예제 #1
0
        //private void shipSelector()
        //{
        //    try
        //    {
        //        int option = int.Parse(Console.ReadLine());
        //        if (option == 1 && credits >= 10)
        //        {
        //            if (cargoWeight > 200)
        //            {
        //                Console.WriteLine();
        //                Console.WriteLine("You have more cargo than this ship can hold. Go sell some stuff and try again.");
        //                Console.WriteLine();
        //            }
        //            else
        //            {
        //                ship = 1;
        //                fuel = 100;
        //                fuelCapacity = 100;
        //                cargoCapacity = 200;
        //                credits -= 10;
        //                Console.WriteLine();
        //                Console.WriteLine("You are now the proud owner of a helium balloon.");
        //            }
        //        }
        //        else if (option == 2 && credits >= 4200)
        //        {
        //            if (cargoWeight > 3000)
        //            {
        //                Console.WriteLine();
        //                Console.WriteLine("You have more cargo than this ship can hold. Go sell some stuff and try again.");
        //                Console.WriteLine();
        //            }
        //            else
        //            {
        //                ship = 2;
        //                fuel = 1500;
        //                fuelCapacity = 1500;
        //                cargoCapacity = 3000;
        //                credits -= 4200;
        //                Console.WriteLine();
        //                Console.WriteLine("Welcome aboard the Reasonable Rocketship. You got a great deal.");
        //            }
        //        }
        //        else if (option == 3 && credits >= 15000)
        //        {
        //            if (cargoWeight > 20000)
        //            {
        //                Console.WriteLine();
        //                Console.WriteLine("You have more cargo than this ship can hold. Go sell some stuff and try again.");
        //                Console.WriteLine();
        //            }
        //            else
        //            {
        //                ship = 3;
        //                fuel = 999999999;
        //                fuelCapacity = 999999999;
        //                cargoCapacity = 20000;
        //                credits -= 15000;
        //                Console.WriteLine();
        //                Console.WriteLine("You are now Captain of Malaysia Airlines Flight 370. Don't travel to year 2014. They're looking for you there.");
        //            }
        //        }
        //        else
        //        {
        //            mainError();
        //        }
        //    }
        //    catch (Exception)
        //    {
        //        mainError();
        //    }
        //} // not yet implemented

        private void SellMenu()
        {
            Console.WriteLine();
            Console.WriteLine("What would you like to sell?");

            // the +1/-1 expressions enforce unique economies among three planets.
            Console.WriteLine($"1 = earthItem for {Earth.GetPrice(MyShip.GetPlanetID())} credits");
            Console.WriteLine($"2 = acItem for {Earth.GetPrice(MyShip.GetPlanetID() - 1)} credits");
            Console.WriteLine($"3 = mpItem for {Earth.GetPrice(MyShip.GetPlanetID() + 1)} credits");
            Console.WriteLine();
            try
            {
                SellItem(int.Parse(Console.ReadLine()));
            }
            catch (Exception)
            {
                TradeError();
            }
        }
예제 #2
0
        // parameter is input by user to determine which item is being sold.
        private void SellItem(int action)
        {
            Console.WriteLine();
            Console.WriteLine("How many would you like to sell?");
            Console.WriteLine();
            int quantity = SetQuantity();

            switch (action)
            {
            // case for earth item
            case 1:
                // enforces current existence within cargo inventory
                if (Cargo.GetItemQuant(0) >= quantity)
                {
                    // enforces unique economy
                    Cargo.ChangeCredits(Earth.GetPrice(MyShip.GetPlanetID()) * quantity);
                    // adds to lifetime earnings to be displayed at end of game
                    Cargo.ChangeTotalEarned(Earth.GetPrice(0) * quantity);
                    // removes sold item(s) from cargo inventory
                    Cargo.ChangeItem(0, -quantity);
                    // removes weight from cargo
                    Cargo.ChangeWeight(150 * -quantity);

                    Console.Clear();
                    Console.WriteLine($"Item sold. Credits = {Cargo.GetCredits()}");
                }
                else
                {
                    SellError();
                }
                break;

            // case to sell ac item. See above for general case statement notes.
            case 2:
                if (Cargo.GetItemQuant(1) >= quantity)
                {
                    // enforces unique economy. Notice the -1 modifier as opposed to the other cases.
                    Cargo.ChangeCredits(Earth.GetPrice(MyShip.GetPlanetID() - 1) * quantity);
                    Cargo.ChangeTotalEarned(Earth.GetPrice(MyShip.GetPlanetID() - 1) * quantity);
                    Cargo.ChangeItem(1, -quantity);
                    Cargo.ChangeWeight(150 * -quantity);
                    Console.Clear();
                    Console.WriteLine($"Item sold. Credits = {Cargo.GetCredits()}");
                }
                else
                {
                    SellError();
                }
                break;

            // case to sell mp item. See above for general case statement notes.
            case 3:
                if (Cargo.GetItemQuant(2) >= quantity)
                {
                    Cargo.ChangeCredits(Earth.GetPrice(MyShip.GetPlanetID() + 1) * quantity);
                    Cargo.ChangeTotalEarned(Earth.GetPrice(MyShip.GetPlanetID() + 1) * quantity);
                    Cargo.ChangeItem(2, -quantity);
                    Cargo.ChangeWeight(150 * -quantity);
                    Console.Clear();
                    Console.WriteLine($"Item sold. Credits = {Cargo.GetCredits()}");
                }
                else
                {
                    SellError();
                }
                break;

            default:
                TradeError();
                break;
            }
        }