private void HandleCollision() { CollisionType collision = collisionManager.Collision(grid, snake); if (collision == CollisionType.PowerUp) { snake.AddTail(); grid.Clear(snake.X, snake.Y); grid.AddRandomPowerUp(snake.GetPositions()); } if (collision == CollisionType.Fatal) { Exit(); } }
protected override void Update(GameTime gameTime) { KeyboardState state = Keyboard.GetState(); if (state.IsKeyDown(Keys.Escape)) { Exit(); } if (_gameOver) { if (state.IsKeyDown(Keys.Space)) { ResetGame(); } return; } _snake.Update((float)gameTime.ElapsedGameTime.TotalSeconds); if (IsPositionOnBorder(_snake.HeadPosition)) { _gameOver = true; } if (_snake.IsPositionInBody(_foodPosition)) { _score++; _snake.AddTail(); SetRandomFoodPosition(); } base.Update(gameTime); }