コード例 #1
0
        public static void Main(string[] args)
        {
            Console.SetBufferSize(80, 25);

            int   score = 0;
            Walls walls = new Walls(80, 25);

            walls.Draw();

            // Отрисовка точек
            Point p     = new Point(4, 5, '*');
            Snake snake = new Snake(p, 4, Direction.RIGHT);

            snake.Draw();
            int speed = 500;



            FoodCreator foodCreator = new FoodCreator(80, 25, '$');
            Point       food        = foodCreator.CreateFood();

            while (walls.isHitFood(food))
            {
                food = foodCreator.CreateFood();

                break;
            }

            food.Draw();


            /*FoodCreator foodCreator = new FoodCreator(80, 25, '$');
             * Point food = foodCreator.CreateFood();
             * food.Draw();*/

            while (true)
            {
                if (walls.IsHit(snake) || snake.IsHitTail())
                {
                    break;
                }
                if (snake.Eat(food))
                {
                    food = foodCreator.CreateFood();
                    while (walls.isHitFood(food))
                    {
                        food = foodCreator.CreateFood();

                        break;
                    }

                    food.Draw();
                    //food = foodCreator.CreateFood();
                    //food.Draw();
                    score++;
                    speed = speed - 30;
                }
                else
                {
                    snake.Move();
                }

                System.Threading.Thread.Sleep(speed);
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.HandleKey(key.Key);
                }
            }
            string str_score = Convert.ToString(score);

            WriteGameOver(str_score);
            Console.ReadLine();
        }