コード例 #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
        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));
        }