コード例 #1
0
ファイル: Menu.cs プロジェクト: orndor/Space-Game
        //List<string> menu = new List<string>() {"Travel", "Buy", "Sell", "Refuel", "Exit" };
        public void KeyCatch(List <Product> inventories, List <Product> products)
        {
            Spaceship userSpaceship = new Spaceship();

            Welcome(inventories, userSpaceship);

            ClearMenuArea();

            OpenAndEndCredits.OpeningCredits();

            ClearMenuArea();

            PrintMenu();
            //Spaceship userSpaceship = new Spaceship(1, Global.name);
            Planet planet = new Planet();

            Console.SetCursorPosition(20, 11);
            PrintAnimation($"{Global.name}, please select an action by pressing a key from the menu below.");
            ConsoleKeyInfo consoleKeyInfo;

            PrintMenu();


            Shoping   shoping   = new Shoping(products);
            Spaceship spaceship = new Spaceship();

            while ((consoleKeyInfo = Console.ReadKey()).Key != ConsoleKey.F12) //if pressed F12 close app
            {
                switch (consoleKeyInfo.Key)
                {
                case ConsoleKey.F1:    //travel
                    spaceship.Travel(inventories);
                    App.PrintSideBottomMenu(inventories, spaceship);
                    //Cutscenes.DoIt();
                    PrintMenu();
                    break;

                case ConsoleKey.F2:    //Buy
                    if (shoping.PrintBuyList(inventories))
                    {
                        ClearMenuArea();
                        Console.SetCursorPosition(20, 10);
                        PrintAnimation($"The item was added to your inventory");
                    }
                    else
                    {
                        //ClearMenuArea();
                        Console.Clear();
                        Console.SetCursorPosition(25, 10);
                        Console.WriteLine("Sorry, the transaction was not processed");
                    }

                    //Console.ResetColor();
                    PrintMenu();

                    App.PrintSideBottomMenu(inventories, userSpaceship);

                    Console.SetCursorPosition(20, 12);
                    PrintAnimation($"{Global.name}, please select an action by pressing a key from the menu below.");
                    break;

                case ConsoleKey.F3:    //Sell
                    if (shoping.PrintSellList(inventories))
                    {
                        ClearMenuArea();
                        Console.SetCursorPosition(10, 10);
                        PrintAnimation($"The deal was successfully accomplished");
                    }
                    else
                    {
                        Console.Clear();
                        Console.SetCursorPosition(10, 10);
                        Console.WriteLine($"SSory {Global.name}, the transaction wasn't processed");
                    }
                    //Console.Clear();
                    //Console.ResetColor();
                    PrintMenu();

                    App.PrintSideBottomMenu(inventories, userSpaceship);
                    Console.SetCursorPosition(10, 12);
                    PrintAnimation($"{Global.name}, please select an action by pressing a key from the menu below.");

                    break;

                case ConsoleKey.F4:    //Refuel
                    userSpaceship.ReFuel();
                    App.PrintSideBottomMenu(inventories, userSpaceship);
                    break;

                case ConsoleKey.F5:    //About
                    About();
                    break;

                default:
                    Console.Write("\b \b");
                    break;
                }
            }
        }
コード例 #2
0
        static public void PrintSideBottomMenu(List <Product> inventories, Spaceship userSpaceship)
        {
            int numOfGold        = 0;
            int numOfwater       = 0;
            int numOfLiquidSoap  = 0;
            int numOfStyrofoam   = 0;
            int numOfOatmeal     = 0;
            int numOfLightBulbs  = 0;
            int numOfHeartOfGold = 0;

            for (int i = 0; i < 31; i++)
            {
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.SetCursorPosition(120, i);
                Console.WriteLine(" ");
                Console.BackgroundColor = ConsoleColor.Black;
            }
            //Put current planet, Age, Fuel level, and Money in the right box.

            Planet currentPlanet     = new Planet();
            string currentPlanetName = Planet.GetPlanetName(Global.currentPlanet);


            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.SetCursorPosition(122, 0);
            Console.WriteLine($"----==={Global.name}'s Stats===----".PadRight(28, ' '));
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(122, 1);
            Console.WriteLine($"     Age: {Global.age}".PadRight(18, ' '));
            Console.SetCursorPosition(122, 3);
            Console.WriteLine($"    Fuel: {Global.gas}".PadRight(18, ' '));
            Console.SetCursorPosition(122, 5);
            Console.WriteLine($"  Wallet: {Global.money} Cubits".PadRight(20, ' '));
            Console.SetCursorPosition(122, 7);
            Console.WriteLine($"Location: {currentPlanetName.PadRight(18,' ')}");
            Console.SetCursorPosition(122, 9);
            Console.WriteLine($"Max Warp: {userSpaceship.GetWarp()}".PadRight(18, ' '));
            Console.SetCursorPosition(122, 11);



            //Put current inventory in the bottom box
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "Gold")
                {
                    numOfGold += 1;
                }
            }
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "Water")
                {
                    numOfwater += 1;
                }
            }
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "Liquid Soap")
                {
                    numOfLiquidSoap += 1;
                }
            }
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "Styrofoam")
                {
                    numOfStyrofoam += 1;
                }
            }
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "Oatmeal Pies")
                {
                    numOfOatmeal += 1;
                }
            }
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "Light Bulbs")
                {
                    numOfLightBulbs += 1;
                }
            }
            for (int i = 0; i < inventories.Count; i++)
            {
                if (inventories[i].ProductName == "The Heart of Gold Spaceship")
                {
                    numOfHeartOfGold += 1;
                }
            }

            for (int i = 0; i < 150; i++)
            {
                Console.BackgroundColor = ConsoleColor.DarkRed;
                Console.SetCursorPosition(i, 30);
                Console.WriteLine(" ");
                Console.BackgroundColor = ConsoleColor.Black;
            }
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            Console.SetCursorPosition(0, 31);
            Console.WriteLine("--------=====Inventory=====--------");
            Console.ForegroundColor = ConsoleColor.White;
            Console.SetCursorPosition(0, 32);
            Console.WriteLine($"       Gold: {numOfGold}".PadRight(18, ' '));
            Console.SetCursorPosition(0, 33);
            Console.WriteLine($"      Water: {numOfwater}".PadRight(18, ' '));
            Console.SetCursorPosition(0, 34);
            Console.WriteLine($"Liquid Soap: {numOfLiquidSoap}".PadRight(18, ' '));
            Console.SetCursorPosition(20, 32);
            Console.WriteLine($"   Styrofoam: {numOfStyrofoam}".PadRight(18, ' '));
            Console.SetCursorPosition(20, 33);
            Console.WriteLine($"Oatmeal Pies: {numOfOatmeal}".PadRight(18, ' '));
            Console.SetCursorPosition(20, 34);
            Console.WriteLine($" Light Bulbs: {numOfLightBulbs}".PadRight(18, ' '));
            Console.WriteLine($" ");
            Console.WriteLine($" ");
            Console.WriteLine($" ");

            if (numOfHeartOfGold >= 1)
            {
                Menu.ClearMenuArea();
                OpenAndEndCredits.WinEndingCredits();
                Console.SetCursorPosition(20, 10);
                Console.WriteLine("Press the Space Bar to exit the game.");
                while (Console.ReadKey(true).Key != ConsoleKey.Spacebar)
                {
                    ;
                }
                Console.Clear();
                Environment.Exit(0);
            }
            if (Global.age >= 60 || Global.money == 0 && numOfGold == 0 && numOfLightBulbs == 0 && numOfLiquidSoap == 0 && numOfOatmeal == 0 && numOfwater == 0 && numOfStyrofoam == 0)
            {
                Menu.ClearMenuArea();
                OpenAndEndCredits.LoseEndingCredits();
                Console.SetCursorPosition(20, 10);
                Console.WriteLine("Press the Space Bar to exit the game.");
                while (Console.ReadKey(true).Key != ConsoleKey.Spacebar)
                {
                    ;
                }
                Console.Clear();
                Environment.Exit(0);
            }
        }