public void NewGame(IRenderer renderer) { playTimer.Reset(); renderer.ClearScreen(); DirectionControl.ResetDirection(); score.ResetScore(); new FieldBorder(renderer, (int)playgroundDimension.X, (int)playgroundDimension.Y); var snakeStartPoint = new Vector(playgroundDimension.X / 2 * Measure, playgroundDimension.Y / 2 * Measure); snake = new Snake(snakeStartPoint, renderer); apple = new Apple(ColorThemes.Apple); renderer.RenderObject(apple.GetShape()); pinkApple = new PinkApple(ColorThemes.PinkApple); renderer.RenderObject(pinkApple.GetShape()); collision = new Collision(snake, apple, pinkApple, playgroundDimension); apple.SetCollision(collision); apple.ReplaceApple(); pinkApple.SetCollision(collision); pinkApple.HideApple(); ResumeGame(); guiClient.SetVisibilityOfResume(true); }
private void WindowKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Escape) { ShowPanel(mainMenuPanel); gameControl.PauseGame(); HideGameObjects(); } if (gameControl.GameIsRunning()) { switch (e.Key) { case Key.A: case Key.Left: DirectionControl.SetTurn(Turn.Conterclockwise); break; case Key.D: case Key.Right: DirectionControl.SetTurn(Turn.Clockwise); break; } } }
public void Move() { var newPosition = snakeHead.GetCurrentPosition() + DirectionControl.GetDirection().Offset(); DirectionControl.ResetTurn(); snakeHead.SetPositionOnCanvas(newPosition); for (int index = 1; index < this.Count; index++) { this[index].SetPositionOnCanvas(this[index - 1].GetFormerPosition()); } }