示例#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!");
            }
        }
        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.");
            }
        }