示例#1
0
        private void MenuAndInitialize()
        {
            Console.Title = "Battleship";

            bool validFontSize = false;

            while (!validFontSize)
            {
                if (Console.LargestWindowHeight >= 40 && Console.LargestWindowWidth >= 75)
                {
                    Console.SetWindowSize(75, 40);
                    Console.SetBufferSize(75, 40);
                    validFontSize = true;
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Please decrease your console font size to play Battleship.");
                    Console.WriteLine("(It's a big board!). Size 16 or below usually works.");
                    Console.WriteLine();
                    Console.WriteLine("Thank you!");
                    Console.ForegroundColor = ConsoleColor.White;
                    Console.WriteLine("(Press enter to retry)");
                    Console.ReadLine();
                    Console.Clear();
                    Thread.Sleep(200);
                }
            }
            Console.ResetColor();

            TextEffects.BattleshipLogoColor = ConsoleColor.Blue;
            TextEffects.HighlightColor      = ConsoleColor.Yellow;
            Console.Clear();

            TextEffects.AnimateBattleshipLogo(false);

            player1.name = GetPlayerName("Player 1 please enter your name: ");
            player2.name = GetPlayerName("Player 2 please enter your name: ");
        }
示例#2
0
        private bool PlayAgainPrompt()
        {
            TextEffects.AnimateBattleshipLogo(true, activePlayer.name);

            //display score
            TextEffects.CenterAlignWriteLine("SCORE");
            TextEffects.CenterAlignWriteLine(activePlayer.name + ": " + activePlayer.score);
            TextEffects.CenterAlignWriteLine(opponent.name + ": " + opponent.score);
            Console.WriteLine();
            Console.WriteLine();
            Console.WriteLine();
            Thread.Sleep(1500);
            //prompt to play again
            //write options for entering yes or no
            for (int i = 1; i <= 35; i++)
            {
                Console.Write(" ");
            }
            Console.Write("(");
            Console.ForegroundColor = TextEffects.HighlightColor;
            Console.Write("Y");
            Console.ResetColor();
            Console.WriteLine(")es");
            for (int i = 1; i <= 35; i++)
            {
                Console.Write(" ");
            }
            Console.Write("(");
            Console.ForegroundColor = TextEffects.HighlightColor;
            Console.Write("N");
            Console.ResetColor();
            Console.WriteLine(")o");
            Console.WriteLine();

            while (true)
            {
                Console.ForegroundColor = TextEffects.HighlightColor;
                TextEffects.CenterAlignWrite("Would you like to play again? ");
                //ask if they want to play again and return the result
                string userInput = Console.ReadLine().Trim().ToUpper();
                switch (userInput)
                {
                case "Y":
                    Console.Clear();
                    return(true);

                case "N":
                    return(false);

                default:
                    int currentCursorTop = Console.CursorTop;
                    Console.SetCursorPosition(0, currentCursorTop - 1);
                    Console.ResetColor();
                    TextEffects.CenterAlignWrite("Enter Y for yes or N for no.");
                    Console.Write("   ");     //to erase their previous entry
                    Thread.Sleep(1300);
                    Console.SetCursorPosition(0, currentCursorTop - 1);
                    break;
                }
            }
        }