// increments movement toward direction public void UpdatePosition(){ // moves head var head = Body[0]; switch (CardinalDirection){ case EDirection.North: Body[0] -= new Vector2D(0, 1); break; case EDirection.South: Body[0] += new Vector2D(0, 1); break; case EDirection.East: Body[0] += new Vector2D(1, 0); break; case EDirection.West: Body[0] -= new Vector2D(1, 0); break; } // moves body after head, caterpillar style for (int i = 1; i < Body.Count; i++){ Vector2D oldPos = Body[i]; Body[i] = head; head = oldPos; } }
public Snake(Vector2D startPosition, int playerCount){ Id = playerCount; _t2 = new Stopwatch(); for (int i = 0; i < 4; i++) { Body.Add(new Vector2D(startPosition)); } CardinalDirection = EDirection.South; }
public Apple(Vector2D startPosition) { Body.Add(new Vector2D(startPosition)); }
public Apple(Vector2D startPosition, int points) { Body.Add(new Vector2D(startPosition)); Points = points; }