示例#1
0
        // Allows the user to buy fuel
        public void Refuel(bool keepLooping)
        {
            // Adjusts the fuel price based on the planet the user is currently on
            double fuelPrice = 100;

            Console.Clear();
            Menus.WelcomeScreen();

            do
            {
                try
                {
                    double tank      = this.GetShip().GetTankCapacity();
                    double fuelLevel = this.GetFuel();
                    Console.WriteLine($"\nFuel Level:\t\t{fuelLevel} tons" +
                                      $"\nTank Capacity:\t\t{tank} tons" +
                                      $"\nFuel Price:\t\t{fuelPrice} credits per ton");
                    Console.Write("\nHow many tons of fuel do you wish to buy?\n\nC: Cancel\n>>>>");
                    MenuSelection selection = new MenuSelection(Console.ReadLine().Trim());
                    if (selection.GetSelection() == 0)
                    {
                        break;
                    }
                    else if (selection.GetSelection() > 0 && selection.GetSelection() <= tank - fuelLevel)
                    {
                        if (this.GetWallet() >= selection.GetSelection() * fuelPrice)
                        {
                            // Updating fuel level
                            this.SetFuel(selection.GetSelection());
                            // Updating the user's wallet
                            this.SetWallet(-selection.GetSelection() * fuelPrice);
                            keepLooping = false;
                        }
                        else
                        {
                            throw new Exception("\nYou don't have enough credits to buy that much fuel. Enter a smaller amount.");
                        }
                    }
                    else
                    {
                        Console.Clear();
                        throw new Exception("\nInvalid Entry");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (keepLooping);
        }
示例#2
0
        public Ship newShip(bool keepLooping)
        {
            Console.Clear();
            Menus.WelcomeScreen();
            string model = "";

            do
            {
                try
                {
                    Console.WriteLine($"\nWallet: {this.GetWallet()} credits");

                    string[] modelNames = { "Volkswagon Creeper", "Church Van", "Ford F150", "Cadallac Escalade" };
                    Console.Write($"\nSelect the type of ship you want to purchase:\n" +
                                  $"\n1. {modelNames[0]}\t\t1,000 credits" +
                                  $"\n2. {modelNames[1]}\t\t\t2,000 credits" +
                                  $"\n3. {modelNames[2]}\t\t\t10,000 credits" +
                                  $"\n4. {modelNames[3]}\t\t20,000 credits\n\nC: Cancel\n\n>>> ");
                    MenuSelection selection = new MenuSelection(Console.ReadLine().Trim());
                    if (selection.GetSelection() == 0)
                    {
                        break;
                    }
                    else if (Enumerable.Range(1, 4).Contains(selection.GetSelection()))
                    {
                        model = modelNames[selection.GetSelection() - 1];
                        Ship newShip = new Ship(model);
                        if (this.GetWallet() >= newShip.GetPrice())
                        {
                            keepLooping = false;
                        }
                        else
                        {
                            Console.Clear();
                            throw new Exception("\nYou don't have enough credits to purchase the selected model.");
                        }
                    }
                    else
                    {
                        Console.Clear();
                        throw new Exception("\nInvalid Entry");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (keepLooping);
            return(new Ship(model));
        }
示例#3
0
        public static string[] CreateTradeMenus(Items[] tradingGoods)
        {
            // Building the output strings for buy and sell menus
            Console.Clear();
            Menus.WelcomeScreen();
            string itemList = "";
            int    count    = 1;

            foreach (Items items in tradingGoods)
            {
                itemList += count++ + ". " + items.GetName() + " " + items.GetPrice() + "\n";
                if (count > 12)
                {
                    itemList += "\n>>> ";
                }
            }
            string[] tradeMenu = { "\nWhat would you like to buy?\n\n" + itemList, "\nWhat would you like to sell?\n\n" + itemList };
            return(tradeMenu);
        }
示例#4
0
        public Character()
        {
            bool keepLooping = true;

            // enter user's name
            do
            {
                try
                {
                    Console.Write("\nType your name\n\n>>> ");
                    string input = Console.ReadLine().Trim();
                    if (input != "")
                    {
                        this.name   = input;
                        keepLooping = false;
                        Console.Clear();
                    }
                    else
                    {
                        Console.Clear();
                        throw new Exception("\nInvalid Entry");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (keepLooping);
            //CharacterType
            keepLooping = true;
            do
            {
                try
                {
                    Menus.WelcomeScreen();
                    string[] classArray = { "Traveler", "Hauler", "Merchant" };
                    Console.Write($"Select your Class, {this.name}:\n\n1. {classArray[0]}\n2. {classArray[1]}\n3. {classArray[2]}\n\n>>>> ");
                    MenuSelection selection = new MenuSelection(Console.ReadLine().Trim());
                    if (Enumerable.Range(1, 3).Contains(selection.GetSelection()))
                    {
                        this.classType = classArray[selection.GetSelection() - 1];
                        keepLooping    = false;
                        Console.Clear();
                    }
                    else
                    {
                        Console.Clear();
                        throw new Exception("\nInvalid Entry");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            } while (keepLooping);
            // mark starting point as Earth
            double[] startingPoint = { 0.0, 0.0 };
            this.location = new Planet("Earth", startingPoint, 1);
            // give starting credits to the player
            this.wallet = 5000;
            // Set travel time to zero at the beginning of the game
            this.travelTime = 0;
            Menus.WelcomeScreen();
            Console.WriteLine($"\nHello {this.GetName()}. Your character has been created and awarded with 5,000 credits to start the game.");
            Console.WriteLine("Your objective is to travel to as many planets as possible, trading items for as profit.");
            Console.WriteLine("Your success as an intersellar trader will be measured by your money, total fuel, and distance travelled...");
            Console.WriteLine("\nPress Enter to Continue");
            Console.ReadLine();
            Console.Clear();
            // prompt the user to purchase a ship
            this.ship = newShip(true);
            Console.Clear();
            // Updates user's wallet.
            SetWallet(-ship.GetPrice());
            Console.Clear();
            Refuel(true);
            Console.Clear();
        }
示例#5
0
        private static void ShowActionMenu(Character myCharacter, List <SolarSystem> universe, Items[] tradingGoods, string[] TradeMenu)
        {
            bool keepLooping = true;

            do
            {
                bool commandNotExecuted = true;
                do
                {
                    Menus.WelcomeScreen();
                    try
                    {
                        Console.Write("\nSelect from the following options:\n\n1. Status\n2. Trade\n3. Travel to...\n4. Refuel\n5. Change ship\n6. Quit game\n\n>>> ");
                        MenuSelection selection = new MenuSelection(Console.ReadLine().Trim());
                        if (Enumerable.Range(1, 6).Contains(selection.GetSelection()))
                        {
                            switch (selection.GetSelection())
                            {
                            case 1:
                                Console.Clear();
                                Menus.WelcomeScreen();
                                myCharacter.ShowStatus();
                                break;

                            case 2:
                                Console.Clear();
                                Menus.WelcomeScreen();
                                Trade(tradingGoods, myCharacter, TradeMenu);
                                break;

                            case 3:
                                Console.Clear();
                                Menus.WelcomeScreen();
                                myCharacter.Travel(universe);
                                break;

                            case 4:
                                Console.Clear();
                                Menus.WelcomeScreen();
                                myCharacter.Refuel(true);
                                break;

                            case 5:
                                Console.Clear();
                                Menus.WelcomeScreen();
                                myCharacter.newShip(true);
                                break;

                            case 6:
                                Console.Clear();
                                Init i = new Init();
                                i.Run();
                                break;
                            }
                            commandNotExecuted = false;
                        }
                        else
                        {
                            Console.Clear();
                            throw new Exception("\nInvalid Entry");
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                } while (commandNotExecuted);
                Console.WriteLine("\nCommand successfully executed. Press Enter to Continue.");
                Console.ReadLine();
                Console.Clear();
            } while (keepLooping);
        }