예제 #1
0
        static void Main(string[] args)
        {
            // Setting stuff up.
            Console.WindowHeight       = 30; Console.WindowWidth = 61;
            Console.CursorVisible      = false;
            GrowthBall.ANewBallsChixel = new Chixel('█', ConsoleColor.Red);
            // Making sure there is an instance of FrameBuffer in existance
            FrameBuffer frame = new FrameBuffer(0, 0, Console.WindowWidth, Console.WindowHeight);

            InitalizeGame();

            // Them controls start here. Made it IsBackground to make sure it dies when the main thread dies
            Thread keylistener = CreateKeyListener();

            keylistener.Start();

            // Main Game loop
            while (!pressedEscape)
            {
                // If the snake is dead, don't do things that snakes do when they're alive like moving
                // I am not happy how handling death and restarts turned out. This is unreadable crap!
                if (!snake.Dead)
                {
                    if (!snake.Move())
                    {
                        snake.OnDie();
                    }
                    ;
                    if (GrowthBall.GrowthBallDict.Count < 1)
                    {
                        GrowthBall.Spawn(3);
                    }
                }
                else if (IsRestarting)
                {
                    FrameBuffer.Instance.Clear();
                    GrowthBall.GrowthBallDict.Clear();

                    // The stuff with the keylistener is so that it doesn't steal the Game's fist ReadKey
                    // Which causes the game to require two key presses to unpause after restart
                    keylistener.Abort();

                    InitalizeGame();

                    keylistener = CreateKeyListener();
                    keylistener.Start();

                    IsRestarting = false;
                }
                FrameBuffer.Instance.DrawFrame();
                Thread.Sleep(frameTimeReal);
            }
        }
예제 #2
0
        static void InitalizeGame()
        {
            snake = new Snake(7,
                              new Chixel('█', ConsoleColor.White),
                              new Chixel('█', ConsoleColor.Gray));

            snake.Died += new Action <Snake>(DealWithScoring);
            snake.Died += new Action <Snake>(DrawGameOverScreen);

            FrameBuffer.Instance.DrawFrame();
            // The game starts paused
            ControlGame(Console.ReadKey(true).Key);

            // Spawn a ball after the player unpauses
            GrowthBall.Spawn(3);
        }