Beispiel #1
0
        public GameController()
        {
            time  = new Stopwatch();
            pause = false;


            /// Board ///
            boardWidth              = Console.WindowWidth;
            boardHeigth             = Console.WindowHeight;
            Console.Title           = "Westerdals Oslo ACT - SNAKE";
            Console.ForegroundColor = ConsoleColor.Green;
            Console.CursorVisible   = false;
            Console.SetCursorPosition(10, 10);
            Console.Write("@");

            ///Generate Apple///
            apple = PointFactory.Create(1, boardWidth, boardHeigth);
            Console.ForegroundColor = ConsoleColor.Green;
            Console.SetCursorPosition(apple.X, apple.Y);
            Console.Write("$");

            ///Generate Snake///
            SnakeGen();

            /////Direction variables/////
            newDir  = 2;
            lastDir = newDir;
        }
Beispiel #2
0
        ///////////////////////
        /// Snake Generator ///
        ///////////////////////

        private void SnakeGen()
        {
            snake = new List <Point> {
            };
            for (int i = 0; i < 4; i++)
            {
                snake.Add(PointFactory.Create(0, 10, 10));
            }
        }
Beispiel #3
0
        /////////////////
        /// THE GAME! ///
        /////////////////

        public void PlayGame()
        {
            time.Start();
            while (true)
            {
                Input();

                if (!pause)
                {
                    if (time.ElapsedMilliseconds < 100)
                    {
                        continue;
                    }
                    time.Restart();

                    newHead = PointFactory.Create(0, snake.Last().X, snake.Last().Y);
                    switch (newDir)
                    {
                    case 0:
                        newHead.Y -= 1;
                        break;

                    case 1:
                        newHead.X += 1;
                        break;

                    case 2:
                        newHead.Y += 1;
                        break;

                    default:
                        newHead.X -= 1;
                        break;
                    }
                    Checks();
                    Printer();
                }
            }
        }