예제 #1
0
        public void TryToBuy(Player player, Dictionary <string, int> storeInventory, string toBuy, Inventory inventory)
        {
            int converted;

            DisplayHowManyToBuy(toBuy);
            string number = Console.ReadLine();
            bool   result = Int32.TryParse(number, out converted);

            if (result)
            {
                if (converted > 0)
                {
                    double cost = (costs[toBuy] * converted);
                    if (cost <= player.cash)
                    {
                        DisplayYouBought(toBuy, converted);
                        player.AdjustCash(cost * -1);
                        player.AdjustMoneySpentToday(cost);
                        player.AdjustTotalMoneySpent(cost);
                        switch (toBuy)
                        {
                        case "lemons":
                            inventory.AddLemons(converted);
                            break;

                        case "ice":
                            inventory.AddIces(converted);
                            break;

                        case "sugar":
                            inventory.AddSugars(converted);
                            break;

                        case "cups":
                            inventory.AddCups(converted);
                            break;

                        case "trees":
                            inventory.AddTrees(converted);
                            break;
                        }
                        chosen = true;
                    }
                    else
                    {
                        DisplayYouCantBuy(toBuy, converted);
                        chosen = true;
                    }
                }
                else
                {
                    Console.WriteLine("Please enter a number greater than zero.");
                }
            }
            else
            {
                Console.WriteLine("Please enter a number greater than zero.");
            }
        }
예제 #2
0
        public void BuySupplies(Player player, Dictionary <string, int> storeInventory, string item, Inventory inventory)
        {
            int converted;

            AmountToBuy(item);
            string number = Console.ReadLine();
            bool   result = Int32.TryParse(number, out converted);

            if (result)
            {
                if (converted > 0)
                {
                    double cost = (price[item] * converted);
                    if (cost <= player.cash)
                    {
                        DisplaySupplyBought(item, converted);
                        player.AdjustCash(cost * -1);
                        player.AdjustMoneySpentToday(cost);
                        player.AdjustTotalMoneySpent(cost);
                        switch (item)
                        {
                        case "lemons":
                            inventory.AddLemons(converted);
                            break;

                        case "ice":
                            inventory.AddIces(converted);
                            break;

                        case "sugar":
                            inventory.AddSugars(converted);
                            break;

                        case "cups":
                            inventory.AddCups(converted);
                            break;
                        }
                        buy = true;
                    }
                    else
                    {
                        DisplayYouCantBuy(item, converted);
                        buy = true;
                    }
                }
                else
                {
                    Console.WriteLine("Invalid input! Please try again!");
                }
            }
            else
            {
                Console.WriteLine("Invalid input! please try again!");
            }
        }