static void Main(string[] args) { SnakeGame s = new SnakeGame(); s.Construct(50, 50, 10, 10, 30); s.Start(); }
static void Main(string[] args) { // Create an instance SnakeGame s = new SnakeGame(); // Construct the game s.Construct(50, 50, 10, 10, 30); // Start the game s.Start(); }
public SnakeDirection GetNextDirection(SnakeDirection currentDirection) { if (currentDirection == SnakeDirection.Up && _myHeadPosition.Y < _wallDistanceThreshold) { return(SnakeDirection.Left); } if (currentDirection == SnakeDirection.Right && _myHeadPosition.X > _width - _wallDistanceThreshold) { return(SnakeDirection.Up); } if (currentDirection == SnakeDirection.Down && _myHeadPosition.Y > _width - _wallDistanceThreshold) { return(SnakeDirection.Right); } if (currentDirection == SnakeDirection.Left && _myHeadPosition.X < _wallDistanceThreshold) { return(SnakeDirection.Down); } Tuple <int, int> foodCoord = SnakeGame.getFoodCoord(); int foodX = foodCoord.Item1; int foodY = foodCoord.Item2; if (currentDirection == SnakeDirection.Up && _myHeadPosition.Y == foodY && _myHeadPosition.X < foodX) { return(SnakeDirection.Right); } else if (currentDirection == SnakeDirection.Up && _myHeadPosition.Y == foodY && _myHeadPosition.X > foodX) { return(SnakeDirection.Left); } else if (currentDirection == SnakeDirection.Right && _myHeadPosition.X == foodX && _myHeadPosition.Y > foodY) { return(SnakeDirection.Up); } else if (currentDirection == SnakeDirection.Right && _myHeadPosition.X == foodX && _myHeadPosition.Y < foodY) { return(SnakeDirection.Down); } else if (currentDirection == SnakeDirection.Left && _myHeadPosition.X == foodX && _myHeadPosition.Y < foodY) { return(SnakeDirection.Down); } else if (currentDirection == SnakeDirection.Left && _myHeadPosition.X == foodX && _myHeadPosition.Y > foodY) { return(SnakeDirection.Up); } else if (currentDirection == SnakeDirection.Down && _myHeadPosition.Y == foodY && _myHeadPosition.X < foodX) { return(SnakeDirection.Right); } else if (currentDirection == SnakeDirection.Down && _myHeadPosition.Y == foodY && _myHeadPosition.X > foodX) { return(SnakeDirection.Left); } return(currentDirection); }