Пример #1
0
 public void ReplaceApple()
 {
     if (_snake.AteTheApple)
     {
         _apple = new Apple();
     }
 }
Пример #2
0
        public void CheckForCollision(Apple other)
        {
            //Reset bool if apple was eaten last frame.
            if (AteTheApple)
            {
                AteTheApple = false;
            }

            //Game over criteria "IsGameOver"?
            else
            {
                foreach (var x in SnakeElements)
                {
                    // Check for appleCollision with body
                    if (x.X == other.Position.X && x.Y == other.Position.Y)
                    {
                        AteTheApple = true;
                    }
                    // Check for death by accidental self-cannibalism.
                    //Should not execute before NewHeadPosition has moved a space.
                    if (x.X != NewHeadPosition.X || x.Y != NewHeadPosition.Y)
                        continue;

                    Global.IsGameOver = true;
                    break;
                }
            }

            // Check for appleCollision with head
            if (NewHeadPosition.X == other.Position.X && NewHeadPosition.Y == other.Position.Y)
            {
                if (SnakeElements.Count + 1 >= Global.BoardWidth * Global.BoardHeight)
                    // No more room to place apples -- game over.
                    Global.IsGameOver = true;

                else
                {
                    AteTheApple = true;
                    //other.ReplaceApple(NewHeadPosition, SnakeElements);
                }
            }
            SnakeElements.Add(NewHeadPosition);
        }
Пример #3
0
 public GameBoard()
 {
     _snake = new Snake();
     _apple = new Apple();
 }