/// <summary> /// Method <c>ChangeDirection</c> changes the direction of the snake. /// </summary> /// <param name="newDirection">The snake's new direction</param> public void ChangeDirection(Direction newDirection) { switch (Compass) { case Direction.UP: if (!newDirection.Equals(Direction.DOWN)) { Compass = newDirection; } break; case Direction.RIGHT: if (!newDirection.Equals(Direction.LEFT)) { Compass = newDirection; } break; case Direction.LEFT: if (!newDirection.Equals(Direction.RIGHT)) { Compass = newDirection; } break; case Direction.DOWN: if (!newDirection.Equals(Direction.UP)) { Compass = newDirection; } break; } }
private Coordinate nextHead(Direction direction) { int x = snake.get(0).x; int y = snake.get(0).y; if (direction.Equals(Direction.LEFT)) { x = x - 1; x = (x < 0) ? width + x : x % width; } else if (direction.Equals(Direction.UP)) { y = y - 1; y = (y < 0) ? height + y : y % height; } else if (direction.Equals(Direction.RIGHT)) { x = (x + 1) % width; } else if (direction.Equals(Direction.DOWN)) { y = (y + 1) % height; } else { Console.WriteLine("You messed something up mate"); } return(new Coordinate(x, y)); }