public SnakeNode(SnakeNode a_Follow, SegmentType a_SegmentType, GraphicType a_GraphicType, Vector2 a_Translation) { m_Follow = a_Follow; SegmentType = a_SegmentType; m_GraphicType = a_GraphicType; Position = Vector2.Zero + a_Translation; }
public Snake(int x, int y) { HeadCoordX = x; HeadCoordY = y; for (int i = 0; i < SnakeLenght; i++) { SnakeNode snakeNode = new SnakeNode(HeadCoordX - i, HeadCoordY); snakeNodes.Add(snakeNode); } }
private void InitializeGame() { this.score = 0; this.scoreLabel.Text = score.ToString(); this.pause = true; gameBoard = new int[20, 20]; snakeHead = new SnakeNode(Node.Direction.East, XOFFSET, YOFFSET, true); food = new FoodNode(XOFFSET, YOFFSET); //snake.direction1(); wt.Start(); Invalidate(); }
private static void CheckSnakeCollision(Model.Snake snake) { SnakeNode head = snake.Head; // check field boundaries bool isOutOfLeftTopBorders = head.Row < 0 || head.Col < 0; bool isOutOfRightBottomBorders = head.Row > RowBoundary || head.Col >= ColBoundary; if (isOutOfLeftTopBorders || isOutOfRightBottomBorders) { GameOver(); } // check food collision if (_food != null && head.Row == _food.Row && head.Col == _food.Col) { _food = null; snake.Grow(); } // check self collision var currentNode = head.Prev; while (currentNode != null) { if (head.Row == currentNode.Row && head.Col == currentNode.Col) { GameOver(); } currentNode = currentNode.Prev; } // check obstacles collision foreach (var obstacle in _obstacles) { if (head.Row == obstacle.Row && head.Col == obstacle.Col) { GameOver(); } } }