Exemple #1
0
        //Controls the pace of the game. Every time this is called the snake advances one space and
        //collision checks are made
        private void Step()
        {
            StateOfLocation[,] oldGameBoard = gameBoard;
            gameBoard = new StateOfLocation[width, height];

            snake.MoveSnake();
            List <Point> newSnakePosition = snake.GetSnakePosition();
            Point        newFoodPosition  = food.FoodPosition;

            gameBoard[newFoodPosition.X, newFoodPosition.Y] = StateOfLocation.Food;

            if (!CheckCollision(oldGameBoard, newSnakePosition))
            {
                foreach (Point segment in newSnakePosition)
                {
                    gameBoard[segment.X, segment.Y] = StateOfLocation.Snake;
                }
            }
            else
            {
                timer.Stop();
                gameRunning = false;
                return;
            }

            screen.DrawScreen(gameBoard);
        }
Exemple #2
0
        private bool MoveAndEat()
        {
            SnakePoint p = snake.GetSnakeNextPoint();

            if (food != null && p.X == food.X && p.Y == food.Y)
            {
                snake.AddSnakeBody(p.X, p.Y);
                food = null;
                return(true);
            }
            else
            {
                return(snake.MoveSnake());
            }
        }