コード例 #1
0
        static void Main(string[] args)
        {
            (int width, int height, int maxFps) = MainMenu();
            Stopwatch sw        = new Stopwatch();
            long      frameWait = Stopwatch.Frequency / maxFps;

            var game = new Game(width, height);

            game.RandomSeed();
            var running = true;
            var wrap    = true;

            while (running)
            {
                sw.Restart();
                if (wrap)
                {
                    game.TickWrap();
                }
                else
                {
                    game.Tick();
                }

                game.Render();
                do
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKey key = Console.ReadKey(true).Key;
                        switch (key)
                        {
                        case ConsoleKey.Escape:
                            running = false;
                            break;

                        case ConsoleKey.Enter:
                            game.RandomSeed();
                            break;

                        case ConsoleKey.Spacebar:
                            wrap = !wrap;
                            break;

                        case ConsoleKey.Tab:
                            NextColor();
                            break;
                        }
                    }
                } while (sw.ElapsedTicks < frameWait);
            }
        }