Ejemplo n.º 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.");
            }
        }
Ejemplo n.º 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!");
            }
        }
Ejemplo n.º 3
0
        public void BuyItems()
        {
            User_Interface.MenuMessage = "What would you like to buy? ('lemons', 'cups', 'ice', 'sugar', or 'finish' to finish)";
            User_Interface.DisplayMessage();
            switch (Console.ReadLine())
            {
            case "lemons":
                User_Interface.MenuMessage = "How many would you like to buy? 15 cents each.";
                User_Interface.DisplayMessage();
                inventory.AddLemons(Convert.ToInt32(Console.ReadLine()));
                money -= (Lemon.price * inventory.numberOfLemons.Count);
                DisplayMoney();
                BuyItems();
                break;

            case "cups":
                User_Interface.MenuMessage = "How many would you like to buy? 4 cents each.";
                User_Interface.DisplayMessage();
                inventory.AddCups(Convert.ToInt32(Console.ReadLine()));
                money -= (Cup.price * inventory.numberOfCups.Count);
                DisplayMoney();
                BuyItems();
                break;

            case "ice":
                User_Interface.MenuMessage = "How many would you like to buy? 1 cent each.";
                User_Interface.DisplayMessage();
                inventory.AddIce(Convert.ToInt32(Console.ReadLine()));
                money -= (Ice.price * inventory.numberOfIceCubes.Count);
                DisplayMoney();
                BuyItems();
                break;

            case "sugar":
                User_Interface.MenuMessage = "How many would you like to buy? 10 cents each.";
                User_Interface.DisplayMessage();
                inventory.AddSugar(Convert.ToInt32(Console.ReadLine()));
                money -= (Sugar.price * inventory.numberOfSugar.Count);
                DisplayMoney();
                BuyItems();
                break;

            case "finish":
                break;

            //case "removesugar":
            //    inventory.RemoveSugar(Convert.ToInt32(Console.ReadLine()));
            //    break;
            default:
                Console.WriteLine("Invalid Input");
                BuyItems();
                break;
            }
        }
Ejemplo n.º 4
0
        private void RefillCups()
        {
            Console.WriteLine("Cups: ");
            int cupAmount = int.Parse(Console.ReadLine());

            if (cupAmount != 0)
            {
                if ((cupAmount * new Cup().Price) > player1.Store.Money)
                {
                    Console.WriteLine("You don't have enough money to buy that many cups. Please try again.");
                    UserInterface.DisplayCash(player1);
                    RefillCups();
                }
                else
                {
                    inventory.AddCups(cupAmount);
                    dailyExpenses += (cupAmount * new Cup().Price);
                    money         -= (cupAmount * new Cup().Price);
                }
            }
        }
Ejemplo n.º 5
0
        public void ReadFile(Player player, Inventory inventory, Game game)
        {
            string        line;
            string        path       = "LemonadeSaveFile.txt";
            string        fullPath   = System.IO.Path.GetFullPath(path);
            List <string> textToRead = new List <string>();

            try {
                System.IO.StreamReader file = new System.IO.StreamReader(fullPath);
                if ((line = file.ReadLine()) != null)
                {
                    player.SetName(line);
                }
                if ((line = file.ReadLine()) != null)
                {
                    player.SetCash(Convert.ToDouble(line));
                }
                inventory.Reset();
                if ((line = file.ReadLine()) != null)
                {
                    //lemons
                    inventory.AddLemons(Int32.Parse(line));
                }
                if ((line = file.ReadLine()) != null)
                {
                    //ice
                    inventory.AddIces(Int32.Parse(line));
                }
                if ((line = file.ReadLine()) != null)
                {
                    //sugar
                    inventory.AddSugars(Int32.Parse(line));
                }
                if ((line = file.ReadLine()) != null)
                {
                    //cups
                    inventory.AddCups(Int32.Parse(line));
                }
                if ((line = file.ReadLine()) != null)
                {
                    //total spent
                    player.SetTotalSpent(Convert.ToDouble(line));
                }
                if ((line = file.ReadLine()) != null)
                {
                    //total profit
                    player.SetTotalProfit(Int32.Parse(line));
                }
                if ((line = file.ReadLine()) != null)
                {
                    //current day
                    game.SetCurrentDay(Int32.Parse(line));
                }
                Console.WriteLine("Game loaded.");
                file.Close();
            }
            catch
            {
                Console.WriteLine("Error trying to load file.");
            }
        }