private void ResetBoard() //generates a new map, pathfinder and grid { start = new Point(0, 0); finish = new Point(xcells - 1, ycells - 1); path.Clear(); while (path.Count == 0) //to prevent a blocked grid from generating { Map = GenerateRandomMap(xcells, ycells); pathfinder = new Pathfinder2(Map, start, finish, false); path = pathfinder.FindPath(); } myGrid = new Grid(GetDrawRectangle(), Map.GetLength(0), Map.GetLength(1)); reqRedraw = true; MyPlayer = new Player(start, this); enemies.Clear(); for (int i = 0; i <= (xcells / 2 - 3); i++) //creates new enemies { Point ePoint = CreateRandomEnemy(); Map[ePoint.X, ePoint.Y] = true; } this.Invalidate(); //to trigger redrawing of the form }
public void Detected(Point at) //runs when detects the player in Main { if (!at.Equals(goal)) //when the goal is changed { Active = true; goal = at; //sets goal to new point pfinder = new Pathfinder2(form.Map, Location, at, false); //finds new path Path = new Queue <Point>(pfinder.FindPath()); if (Path.Count > 0) { Path.Dequeue(); //remove the top of the list since the first node is the enemy's location } } }
private void ResetBoard(bool[,] _map, Point _player, List <Point> _enemies) //resets board to loaded file { path.Clear(); Map = _map; pathfinder = new Pathfinder2(Map, _player, finish, false); path = pathfinder.FindPath(); myGrid = new Grid(GetDrawRectangle(), Map.GetLength(0), Map.GetLength(1)); reqRedraw = true; MyPlayer = new Player(_player, this); enemies.Clear(); foreach (Point p in _enemies) //creates new enemies { CreateEnemy(p); Map[p.X, p.Y] = true; } this.Invalidate(); //to trigger redrawing of the form }