Пример #1
0
        public static void Main(string[] args)
        {
            OriginalWindowWidth = Console.WindowWidth;
            OriginalWindowHeight = Console.WindowHeight;

            try
            {
                bool isTrueTypeFont = WinAPI.IsOutputConsoleFontTrueType();
                Console.Title = string.Format("C# Nibbles");
                if (isTrueTypeFont)
                    Console.OutputEncoding = Encoding.UTF8;
                Console.SetWindowSize(80, 25);
                Console.CursorVisible = false;
                Console.CancelKeyPress += (s, e) => RestoreConsole();

                Console.ForegroundColor = ConsoleColor.White;
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Clear();
                Console.SetWindowSize(80, 25);
                Console.SetBufferSize(80, 25);
                Console.CursorVisible = false;

                // INTRO

                Center(4, "C #   N i b b l e s");
                Console.ForegroundColor = ConsoleColor.Gray;
                Center(6, "(Translated from QBasic Nibbles)");
                Center(8, "Nibbles is a game for one or two players.  Navigate your snakes");
                Center(9, "around the game board trying to eat up numbers while avoiding");
                Center(10, "running into walls or other snakes.  The more numbers you eat up,");
                Center(11, "the more points you gain and the longer your snake becomes.");
                Console.ForegroundColor = ConsoleColor.White;
                Center(13, " Game Controls ");
                Console.ForegroundColor = ConsoleColor.Gray;
                Center(15, "  General             Player 1               Player 2    ");
                Console.ForegroundColor = ConsoleColor.DarkGray;
                Center(16, "                        (Up)                   (Up)      ");
                Center(17, "P - Pause                ↑                      W       ");
                Center(18, "                     (Left) ←   → (Right)   (Left) A   D (Right)  ");
                Center(19, "                         ↓                      S       ");
                Center(20, "                       (Down)                 (Down)     ");
                Console.ForegroundColor = ConsoleColor.Cyan;
                Center(24, "Press any key to continue");

                Music.Play("T160O1L8CDEDCDL4ECC", true);
                SparklePause();

                // ASK USER FOR PARAMETERS

                Console.ForegroundColor = ConsoleColor.Gray;
                Console.BackgroundColor = ConsoleColor.Black;
                Console.Clear();
                Console.CursorVisible = true;

                bool success;
                do
                {
                    ConsoleSetCursorPosition(47, 5);
                    Console.Write(new string(' ', 34));
                    ConsoleSetCursorPosition(20, 5);
                    Console.Write("How many players (1 or 2)? ");
                    string num = Console.ReadLine();
                    success = int.TryParse(num, out NumPlayers);
                }
                while (!success || NumPlayers < 1 || NumPlayers > 2);

                ConsoleSetCursorPosition(21, 8);
                Console.Write("Skill level (1 to 100)? ");
                ConsoleSetCursorPosition(22, 9);
                Console.Write("1   = Novice");
                ConsoleSetCursorPosition(22, 10);
                Console.Write("90  = Expert");
                ConsoleSetCursorPosition(22, 11);
                Console.Write("100 = Twiddle Fingers");
                ConsoleSetCursorPosition(15, 12);
                Console.Write("(Computer speed may affect your skill level)");

                do
                {
                    ConsoleSetCursorPosition(45, 8);
                    Console.Write(new string(' ', 35));
                    ConsoleSetCursorPosition(45, 8);
                    string gamespeed = Console.ReadLine();
                    success = int.TryParse(gamespeed, out Speed);
                }
                while (!success || Speed < 1 || Speed > 100);

                Speed = (int) ((100 - Speed) * 2 + 10);

                string increase;
                do
                {
                    ConsoleSetCursorPosition(56, 15);
                    Console.Write(new string(' ', 25));
                    ConsoleSetCursorPosition(15, 15);
                    Console.Write("Increase game speed during play (Y or N)? ");
                    increase = Console.ReadLine().ToUpperInvariant();
                }
                while (increase != "Y" && increase != "N");
                IncreaseSpeedDuringPlay = increase == "Y";

                string monitor;
                do
                {
                    ConsoleSetCursorPosition(46, 17);
                    Console.Write(new string(' ', 34));
                    ConsoleSetCursorPosition(17, 17);
                    Console.Write("Monochrome or color monitor (M or C)? ");
                    monitor = Console.ReadLine().ToUpperInvariant();
                }
                while (monitor != "M" && monitor != "C");

                if (monitor == "M")
                {
                    Sammy = ConsoleColor.White;
                    Jake = ConsoleColor.Gray;
                    Walls = ConsoleColor.Gray;
                    Background = ConsoleColor.Black;
                    DlgFore = ConsoleColor.White;
                    DlgBack = ConsoleColor.Black;
                }
                else
                {
                    Sammy = ConsoleColor.Yellow;
                    Jake = ConsoleColor.Magenta;
                    Walls = ConsoleColor.Red;
                    Background = ConsoleColor.DarkBlue;
                    DlgFore = ConsoleColor.White;
                    DlgBack = ConsoleColor.DarkRed;
                }

                Console.CursorVisible = false;

                // Initialize arena array
                for (int row = 1; row <= 50; row++)
                    for (int col = 1; col <= 80; col++)
                        Arena[row, col] = new Arena { RealRow = (row + 1) / 2, Sister = (row % 2) * 2 - 1 };

                Console.BackgroundColor = Background;
                Console.Clear();

                do
                    PlayNibbles();
                while (StillWantsToPlay());

                RestoreConsole();
            }
            catch (Exception ex)
            {
                RestoreConsole();
                Console.WriteLine(ex);
            }
            finally
            {
                Music.Dispose();
            }
        }