Ejemplo n.º 1
0
        public Hero itemPicked(MarketItem itemPicked, Hero hero)
        {
            Console.Clear();

            Utils.showItemInfo(itemPicked);
            string command = ItemBuyAndSellMenu.DoYouWishToBuy(itemPicked);

            if (command == "y")
            {
                if (hero.Money >= itemPicked.Price)
                {
                    hero.Money -= (int)itemPicked.Price;
                    equipmentBusiness.AddNewItem(itemPicked, hero.Id);
                    heroBusiness.Update(hero);
                    Console.WriteLine("Item has been added to your inventory");
                    Console.WriteLine("Current balance: " + hero.Money);
                    Console.WriteLine();
                }
                else
                {
                    Console.WriteLine("You don't have enough money");
                    Console.WriteLine();
                }

                hero = showShopItems(hero);
            }

            if (command == "n")
            {
                hero = showShopItems(hero);
            }

            return(hero);
        }
Ejemplo n.º 2
0
        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);
        }