示例#1
0
        public GameController()
        {
            WINDOW_HEIGTH           = Console.LargestWindowHeight;
            WINDOW_WIDTH            = Console.LargestWindowWidth < (WINDOW_HEIGTH * 2 + STATISTIC_AREA) ? Console.LargestWindowWidth : WINDOW_HEIGTH * 2 + STATISTIC_AREA;
            delay                   = 120;
            Console.BackgroundColor = DEF_BACKGROUND_COLOR;
            Console.ForegroundColor = DEF_COLOR;
            Console.CursorVisible   = false;
            Console.SetWindowSize(WINDOW_WIDTH, WINDOW_HEIGTH);
            Console.SetBufferSize(WINDOW_WIDTH, WINDOW_HEIGTH);
            //Создание стен
            this.walls = new walls(0, 0, WINDOW_WIDTH - STATISTIC_AREA - 1, WINDOW_HEIGTH - 1, WALLS);
            //Создание змейки
            Point tail = new Point((WINDOW_WIDTH - STATISTIC_AREA - 1) / 2, (WINDOW_HEIGTH - 1) / 2, SNAKE, DEF_COLOR, DEF_BACKGROUND_COLOR);

            this.snake       = new Snake(tail, START_SNAKE_LENGTH, START_SNAKE_DIRECTION);
            this.foodCreator = new FoodCreator(2, WINDOW_WIDTH - STATISTIC_AREA - 2, 2, WINDOW_HEIGTH - 2, DEF_BACKGROUND_COLOR);
            this.statistics  = new Statistics(delay, this.snake.length);
        }
示例#2
0
        static void Main(string[] args)
        {
            GameController gameController = new GameController();

            gameController.StartScreen();

            int hs    = Console.LargestWindowHeight;
            int ws    = 2 * hs;
            int delay = 120;

            int startSnakeLength = 2;

            walls walls = gameController.walls;

            walls.Draw();


            Snake snake = gameController.snake;

            snake.Draw();
            Statistics  statistics  = gameController.statistics;
            FoodCreator foodCreator = gameController.foodCreator;

            Food food = foodCreator.CreateNewFood();

            food.Draw();

            while (true)
            {
                if (walls.isHit(snake) || snake.isHitTail())
                {
                    break;
                }
                if (Console.KeyAvailable)
                {
                    ConsoleKeyInfo key = Console.ReadKey();
                    snake.direction = gameController.keyHandler(snake.direction, key);
                }
                if (snake.HaveEat(food))
                {
                    if (food.kind == '-')
                    {
                        snake.throwTail();
                        snake.throwTail();
                    }
                    if (food.kind == 'F')
                    {
                        delay = (int)(delay * 0.95);
                    }
                    else if (food.kind == 'S')
                    {
                        delay = (int)(delay / 0.95);
                    }

                    statistics.setStatistics(delay, snake.length);
                    do
                    {
                        food = foodCreator.CreateNewFood();
                    } while (!walls.isHit(food) && snake.isHit(food));
                    food.Draw();
                }
                else
                {
                    snake.Move();
                }
                Thread.Sleep(delay);
                statistics.printStatistics(ws + 1);
            }



            //Console.WriteLine("Hello World!");
            Console.WriteLine("GAME OVER");
            Console.ReadLine();
        }