public WumpusChaseAnimation(int width, int height, int gridSize, int pathLength, double secondsPerMove) { Width = width; Height = height; GridSize = gridSize; SecondsPerMove = secondsPerMove; Path = new SnakePath(pathLength, GetPointOfInterest()); }
private void PickNextPosition() { // Start with the current point as a default Vector2 CurrentPoint = Path.LatestValue; // Create a list to store the valid moves List <Vector2> ValidMoves = new List <Vector2>(); // Try each direction for (int Direction = 0; Direction < 4; Direction++) { // Calculate the target point after the move Vector2 NewPoint = GetPointAtDirection(CurrentPoint, Direction); // Add it to the list if it is valid if (ValidateNewPoint(NewPoint)) { ValidMoves.Add(NewPoint); } } // If there aren't any valid moves (we have trapped ourselves) // restart at a random position if (ValidMoves.Count <= 0) { Path = new SnakePath(Path.Length, GetPointOfInterest()); } else { // Get the mouse position Vector2 MousePos = Mouse.GetState().Position.ToVector2(); // If it isn't in our game window, just move randomly if (IsOutOfBounds(MousePos)) { Path.Enqueue(ValidMoves.GetRandom()); } // If the mouse is in the window, find the closest valid move and // add it to the snake path else { Path.Enqueue(ValidMoves.OrderBy(p => p.Distance(MousePos)).First()); } } }