示例#1
0
文件: Program.cs 项目: Photon74/Snake
        static void Main(string[] args)
        {
            GameField gameField = new GameField();

            gameField.DrawWalls();

            Food food = new Food(gameField.GameFieldWidth, gameField.GameFieldHeigth);

            food.DrawNewFood();

            Snake snake = new Snake();

            snake.Draw();

            while (true)
            {
                if (snake.IsHittingItself() || gameField.IsHitedBy(snake))
                {
                    break;
                }

                if (snake.IsEating(food))
                {
                    food.DrawNewFood();
                }
                else
                {
                    snake.Move();
                }

                if (Console.KeyAvailable)
                {
                    var key = Console.ReadKey();
                    snake.GetMovingDirection(key.Key);
                }

                Thread.Sleep(200);
            }
            WriteGameOver();
            Console.ReadLine();
        }