コード例 #1
0
ファイル: Shop.cs プロジェクト: ilian02/RPGgameForProject
        public Hero sellItems(Hero hero)
        {
            Console.WriteLine();
            Console.WriteLine("Items you can sell: ");
            Utils.displayListOfItems(equipmentBusiness.GetAllByOwnerId(hero.Id));

            List <Equipment> heroItems = equipmentBusiness.GetAllByOwnerId(hero.Id);

            Console.WriteLine("Enter number of item to sell, (Q)uit or (G)o back");
            string command = Console.ReadLine().ToLower();

            if (command == "q")                  //quit shop menu
            {
                return(hero);
            }
            else if (command == "g")            //back to shop menu buy page
            {
                return(showShopItems(hero));
            }

            if (int.TryParse(command, out int result))          //check if input is int and in heroItems size
            {
                if (Utils.inArrayRange(heroItems.Count, result - 1))
                {
                    string commandForSale = ItemBuyAndSellMenu.DoYouWishToSell(heroItems[result - 1]); //Do you wish to sell menu

                    if (commandForSale == "y")                                                         //sell item and delete from DBcontext
                    {
                        Console.Clear();
                        Console.WriteLine("You sold an item!");
                        hero.Money += (int)heroItems[result - 1].Price;
                        Console.WriteLine("Current gold: " + hero.Money);
                        heroBusiness.Update(hero);
                        equipmentBusiness.Delete(heroItems[result - 1].Id);
                        Console.WriteLine();
                        sellItems(hero);                        //back to selling item menu
                    }
                }
                else
                {
                    Console.Clear();
                    Console.WriteLine("Invalid command!");
                    hero = sellItems(hero);
                }
            }
            else
            {
                Console.Clear();
                Console.WriteLine("Invalid command!");
                hero = showShopItems(hero);
            }


            return(hero);
        }
コード例 #2
0
ファイル: Utils.cs プロジェクト: ilian02/RPGgameForProject
        public static void OpenInventory(Hero hero)
        {
            EquipmentBusiness eb = new EquipmentBusiness();

            Console.WriteLine("Inventory: ");
            List <Equipment> items = (eb.GetAllByOwnerId(hero.Id));

            if (items.Count == 0)
            {
                Console.WriteLine(" Empty");
            }

            for (int i = 0; i < items.Count; i++)
            {
                Console.Write(" " + (i + 1) + ") " + items[i].Name.Trim() + " " + items[i].Points);
                if (items[i].Is_equiped == true)
                {
                    Console.WriteLine(" -> Equiped");
                }
                else
                {
                    Console.WriteLine();
                }
            }
        }
コード例 #3
0
        public int CharacterSelectMenu()
        {
            HeroBusiness      heroBusiness      = new HeroBusiness();
            EquipmentBusiness equipmentBusiness = new EquipmentBusiness();
            List <HeroModel>  heros             = heroBusiness.GetAll();


            int i = 1;

            foreach (HeroModel hero in heros)
            {
                Console.WriteLine($"{i}: {hero.Name} / {hero.Char_level} level");
                i++;
            }

            Console.WriteLine("Please enter hero number to continue or (D)elete to delete hero");

            string command = Console.ReadLine();

            if (command == "d")
            {
                while (command == "d")
                {
                    Console.WriteLine("Which hero do you wish to delete? Input number.");
                    int deleteNumber = int.Parse(Console.ReadLine());
                    if (Utils.inArrayRange(heros.Count, (deleteNumber - 1)))
                    {
                        List <Equipment> itemsToDelete = equipmentBusiness.GetAllByOwnerId(heros[deleteNumber - 1].Id);
                        heroBusiness.Delete(heros[deleteNumber - 1].Id);
                        for (int j = 0; j < itemsToDelete.Count; j++)
                        {
                            equipmentBusiness.Delete(itemsToDelete[j].Id);
                        }
                    }
                    Console.WriteLine("Please enter hero number to continue or (D)elete to delete hero");
                    command = Console.ReadLine().ToLower();
                }
            }


            return(int.Parse(command));
        }
コード例 #4
0
ファイル: Hero.cs プロジェクト: ilian02/RPGgameForProject
        public Hero OpenInventory(Hero hero)
        {
            Utils.OpenInventory(hero);
            List <Equipment> items = (eb.GetAllByOwnerId(hero.Id));

            Console.WriteLine("Input number of item you wish to equip or (g)o back");

            string command = Console.ReadLine();

            if (int.TryParse(command, out int result))
            {
                if (Utils.inArrayRange(items.Count, result - 1))
                {
                    ;
                }
                equipItem(items[result - 1]);
                hero = hero.OpenInventory(hero);
            }

            return(hero);
        }