public void Generate(int userLength) { var maze = new Maze(); _maze = maze; if (OnProgressUpdate != null) { OnProgressUpdate.Invoke(20); //Updates the loading bar on the MainWindow } var genMaze = new MazeGenerationService(userLength, userLength, _maze); _genMaze = genMaze; if (OnProgressUpdate != null) { OnProgressUpdate.Invoke(70); //Updates the loading bar on the MainWindow } var play = new MazePlayService(_maze); _play = play; if (OnProgressUpdate != null) { OnProgressUpdate.Invoke(10); //Updates the loading bar on the MainWindow } CreateExitPoint(); var position = new Mazepoints(0, 0, false, true); _position = position; }
public void DrawSolution(IEnumerable <AStar> solution) { foreach (var position in solution) { var tempMazePoint = new Mazepoints(position.X, position.Y, true, false); GenerateRectangle2(tempMazePoint); } }
private void RemovePath() { _previousPoint = _pathSolution[_pathSolution.Count - 1]; _pathSolution.RemoveAt(_pathSolution.Count - 1); //Remove positon from list _currentPoint = _pathSolution[_pathSolution.Count - 1]; //Update current positon to the previous state _currentPoint.IsSolution = false; //Return false }
public Draw(Maze mazeGrid, Grid blank, Mazepoints finalCoords) { _maze = mazeGrid; _grid = blank; _finalCoords = finalCoords; DrawMaze(); ReadyPlayer(); }
private void ReadyPlayer() { var startCoord = new Mazepoints(0, 0, false, true); UIElement startRect = DrawRect(76, 175, 80); AddChildToGrid(startRect, startCoord); UIElement finalRect = DrawRect(244, 67, 54); AddChildToGrid(finalRect, _finalCoords); }
public void DrawPath(Mazepoints s) { if (s.IsSolution) { var myPath = DrawRect(76, 175, 80); AddChildToGrid(myPath, s); } else { RemovePath(s.Parent); } }
private void CreateExitPoint() //Creates a random end point to the maze in the bottom right quadrant of the maze { var flag = true; var findMaze = (_maze.Length) - (_maze.Length / 4); while (flag) { var testX = MathRandom.GetRandomNumber(findMaze, (_maze.Length - 1)); var testY = MathRandom.GetRandomNumber(findMaze, (_maze.Length - 1)); if (_maze.MazeGrid.Exists(x => x.X == testX && x.Y == testY && x.IsPath)) { _finalCoords = new Mazepoints(testX, testY, true, false); flag = false; } } }
private bool MoveSelection(Mazepoints currentPoint, MoveList move) { _currentPoint = currentPoint; switch (move) { case MoveList.Up: _currentPoint.Y -= 1; if (MoveValidation() && _currentPoint.Y >= 0) { return(true); } _currentPoint.Y += 1; break; case MoveList.Left: _currentPoint.X -= 1; if (MoveValidation() && _currentPoint.X >= 0) { return(true); } _currentPoint.X += 1; break; case MoveList.Down: _currentPoint.Y += 1; if (MoveValidation() && _currentPoint.Y <= _maze.Length) { return(true); } _currentPoint.Y -= 1; break; case MoveList.Right: _currentPoint.X += 1; if (MoveValidation() && _currentPoint.X <= _maze.Length) { return(true); } _currentPoint.X -= 1; break; } return(false); }
public bool Gauntlet(Mazepoints position, MoveList move) { if (!MoveSelection(position, move)) { return(false); } foreach (var item in _pathSolution) //Iterate through list if mazepoint is there { if (item.X == _currentPoint.X && item.Y == _currentPoint.Y) { RemovePath(); position.IsSolution = false; position.Parent = _previousPoint; return(true); } } _currentPoint.IsSolution = true; _pathSolution.Add(new Mazepoints(_currentPoint.X, _currentPoint.Y, true, true)); return(true); }
public MazeSolveService(List <Mazepoints> mazeCoords, Mazepoints finalCoords) { _mazeCoords = mazeCoords; _entireMaze = new List <AStar>(); _openSet = new List <AStar>(); _closedSet = new List <AStar>(); _target = new AStar { X = finalCoords.X, Y = finalCoords.Y }; foreach (var child in mazeCoords) //Get all the nodes into a list that can be used by the AStar algorithm { if (child.IsPath) { _entireMaze.Add(new AStar { X = child.X, Y = child.Y }); } } _length = _entireMaze.Max(x => x.Y); //Length calculated by finding the largest Y coordinate in the list var currentPosition = GenerateSolution(); if (currentPosition != null) { Solution = BuildSolution(currentPosition); } else { //No solution is possible } }
public void Clear() //Ensures that everything is cleared before a new maze is generated { _maze = null; _genMaze = null; _position = null; }
private void GenerateRectangle2(Mazepoints s) { var myRect = DrawRect(174, 213, 129); AddChildToGrid(myRect, s); }
private void GenerateRectangle(Mazepoints s) { var myRect = DrawRect(255, 255, 255); AddChildToGrid(myRect, s); }
private void RemovePath(Mazepoints s) { var pathToRemove = DrawRect(255, 255, 255); AddChildToGrid(pathToRemove, s); }
private void AddChildToGrid(UIElement val, Mazepoints s) { _grid.Children.Add(val); Grid.SetRow(val, s.Y); Grid.SetColumn(val, s.X); }