Example #1
0
        internal static void TotalCost(UserProfile player, TradeGood tradeGoods, SpaceShip spaceShips)
        {
            int     totalCost    = 0;
            int     newCargo     = 0;
            int     quantity     = 0;
            Boolean insufficient = true;

            do
            {
                Console.Write($"How much of {tradeGoods.goodName} do you want to purchase?  ");

                quantity = Utility.ErrorHandler(1000000);

                totalCost = tradeGoods.cost * quantity;
                newCargo  = tradeGoods.size * quantity;

                if (totalCost > player.cosmicCredits)
                {
                    Console.WriteLine($"Insufficient funds.  You have {player.cosmicCredits}cc and {quantity} of {tradeGoods.goodName} costs {totalCost}");
                    Console.WriteLine("Please try again.");
                    insufficient = true;
                }
                else if (newCargo > spaceShips.cargoCapacity)
                {
                    Console.WriteLine($"Insufficient cargo space.  You need {newCargo} space and you only have {spaceShips.cargoCapacity}.");
                    Console.WriteLine("Please try again.");
                    insufficient = true;
                }
                else
                {
                    insufficient = false;
                }
            } while (insufficient == true);

            player.cosmicCredits -= totalCost;
            TradeGood.AddGoods(tradeGoods, quantity);

            spaceShips.cargoCapacity -= (quantity * tradeGoods.size);

            if (quantity > 0)
            {
                tradeGoods.prevBuy = (tradeGoods.prevBuy + totalCost) / (tradeGoods.quantity + quantity);
            }
        }
Example #2
0
        internal static void MarketPlace(TradeGood[] cargoInventory, UserProfile player, SpaceShip currentShip)
        {
            int option      = 0;
            int goodChoice  = 0;
            int addQuantity = 0;
            int numOptions  = 4;

            do
            {
                UserProfile.PrintUserInfo(player, currentShip);
                Console.WriteLine($"What would you like to do? \n1. Buy \n2. Sell \n3. View Inventory \n 4. Go to Planet Menu");

                option = Utility.ErrorHandler(numOptions);

                switch (option)
                {
                case 1:
                    goodChoice  = BuyGoods(cargoInventory);
                    addQuantity = TotalCost(player, cargoInventory[goodChoice], currentShip);
                    TradeGood.AddGoods(cargoInventory[goodChoice], addQuantity);
                    Console.WriteLine($"There are now {cargoInventory[goodChoice].quantity} pieces of {cargoInventory[goodChoice].goodName} in your inventory.");
                    Console.WriteLine("Press <ENTER> to continue...");
                    Console.ReadLine();
                    break;

                case 2:
                    SellGoods(cargoInventory, player, currentShip);
                    break;

                case 3:
                    ViewInventory(cargoInventory);
                    Console.ReadLine();
                    break;

                default:
                    break;
                }
                Console.Clear();
            } while (option != 4);
        }