コード例 #1
0
        //Shows the main UI
        void ShowMainUI()
        {
            if (PlayerFightSystem.IsAlive)
            {
                //Always runs because we should always get back here
                while (true)
                {
                    Console.Clear();
                    bool inMenu = true;

                    //The main UI thread
                    Thread UI = new Thread(() =>
                    {
                        //Do while in menu
                        while (inMenu)
                        {
                            //Clear the console
                            Console.Clear();

                            //Create some space between the wall and the text
                            Console.Write("     ");

                            SetHealthBar();

                            Console.Write("             " + "Days alive: ");
                            Print.PrintColorText(DaysAlive.ToString(), ConsoleColor.DarkYellow);

                            Console.Write("             " + "Hunger: ");
                            Print.PrintColorText(HungerStatus, ConsoleColor.Green);

                            Console.Write("             " + "Level: ");
                            Print.PrintColorText(PlayerFightSystem.PlayerLevel.ToString(), ConsoleColor.DarkCyan);

                            Console.WriteLine("");
                            Console.WriteLine("----------------------------------------------------------------------------------------------------------");

                            var menu = new[] {
                                @"",
                                @"  What would you like to do?",
                                @"  1 - Go out and venture",
                                @"  2 - Sleep",
                                @"  3 - Access inventory",
                                @"  4 - Eat",
                                @"  5 - HELP"
                            };

                            //Show the menu with a short delay between the lines to give an effect
                            foreach (string line in menu)
                            {
                                Console.WriteLine(line);
                            }

                            if (inMenu)
                            {
                                Thread.Sleep(2000);
                            }
                        }
                    });
                    UI.Start();

                    //Get the players choice
                    string playerChoice = Console.ReadLine();

                    //If the player choses one
                    if (playerChoice == "1")
                    {
                        //Let's the player go out and search for
                        inMenu = false;
                        UI.Join();
                        GoOut();
                    }
                    //If the player choses two
                    else if (playerChoice == "2")
                    {
                        //Let's the player sleep
                        inMenu = false;
                        UI.Join();
                        StartSleep();
                    }
                    //If the player choses three
                    else if (playerChoice == "3")
                    {
                        //Shows the inventory
                        inMenu = false;
                        UI.Join();
                        PlayerInventory.ShowInventory(PlayerInventory, PlayerFightSystem);
                    }
                    //If the player choses four
                    else if (playerChoice == "4")
                    {
                        //Show the food menu
                        inMenu = false;
                        UI.Join();
                        PlayerInventory.AccessFoodMenu(PlayerFightSystem);
                    }
                    //If the player choses five
                    else if (playerChoice == "5")
                    {
                        //Show the help menu
                        inMenu = false;
                        UI.Join();
                        ShowHelp();
                    }
                    else
                    {
                        Console.WriteLine("Incorrect input!");
                        Console.WriteLine("Press ENTER to continue");
                        inMenu = false;
                        UI.Join();

                        Console.ReadKey();
                    }

                    //Check if players food level is less than zero
                    if (PlayerFightSystem.FoodValue <= 0)
                    {
                        //Show the game over screen
                        PlayerFightSystem.ShowGameOver(DaysAlive);
                    }
                }
            }
            else
            {
                PlayerFightSystem.ShowGameOver(DaysAlive);
                PlayerFightSystem.CauseOfDeath = "Starving";
            }
        }