Ejemplo n.º 1
0
        public void PlayTurn(bool display = false)
        {
            ++turn;
            --ttl;
            Snake.Direction dir = bot.PlayTurn(display);
            if ((int)dir == -(int)snake.Dir)
            {
                dir = snake.Dir;
            }
            snake.Dir = dir;
            try
            {
                snake.Move(grid);
            }
            catch (ArgumentException)
            {
                lost = true;
            }

            if (ttl <= 0)
            {
                lost = true;
            }

            UpdateGrid();

            if (appleX == snake.Head.X && appleY == snake.Head.Y)
            {
                ++score;
                snake.Grow();
                if (x * y - 5 - score > 0)
                {
                    NewApple();
                }
                ttl = 200;
            }
            if (display)
            {
                PrintGrid();
            }
        }