public Path(Path copyFrom, Color color) : base(copyFrom.Game) { _game = copyFrom.Game; _color = color; _coordinatesCollection = new List<Coordinate>(copyFrom.CoordinatesCollection); DestinationReached = copyFrom.DestinationReached; }
public Path FindWay(Game game, Coordinate from, Coordinate to) { List<string> visitedCoordinates = new List<string>(); var currentCoordinate = new Coordinate(from); _tempLabirynth = new int[_labyrinth.Width, _labyrinth.Height]; int step = 1; _tempLabirynth[currentCoordinate.X, currentCoordinate.Y] = step++; visitedCoordinates.Add(currentCoordinate.X.ToString() + "." + currentCoordinate.Y.ToString()); Coordinate nextCoordinate; Move(currentCoordinate, to, step); while((nextCoordinate = FindNextCoordinate(ref step, visitedCoordinates)) != null) { Move(nextCoordinate, to, step + 1); visitedCoordinates.Add(nextCoordinate.X.ToString() + "." + nextCoordinate.Y.ToString()); } var path = new Path(game, Color.Red) { Target = to }; var coordinatesFromLastOne = new List<Coordinate>(); if(PathFound(_tempLabirynth, to)) { coordinatesFromLastOne.Add(new Coordinate(to.X, to.Y)); int lastStep = _tempLabirynth[to.X, to.Y]; for(int i = lastStep - 1;i>=1;i--) { coordinatesFromLastOne.Add(GetCoordinate(_tempLabirynth, i, coordinatesFromLastOne.Last())); } } else { int firstX, firstY; int highestValue = FindHighest(_tempLabirynth, out firstX, out firstY); coordinatesFromLastOne.Add(new Coordinate(firstX, firstY)); for (int i = highestValue - 1; i >= 1; i--) { coordinatesFromLastOne.Add(GetCoordinate(_tempLabirynth, i, coordinatesFromLastOne.Last())); } } coordinatesFromLastOne.Reverse(); foreach (var coordinate in coordinatesFromLastOne) { path.AddCoordinate(coordinate); } if (path.CoordinatesCollection.Last().X == to.X && path.CoordinatesCollection.Last().Y == to.Y) path.DestinationReached = true; return path; }
private Vector2 GetFirstPathStepConverted(Path path) { Coordinate newCoordinate = path.CoordinatesCollection.First(); return CalculateLabCoordinatesToVector(newCoordinate.X, newCoordinate.Y); //int newX = (newCoordinate.X * (LabyrinthUnit.Length)) + 25; //int newY = (newCoordinate.Y * (LabyrinthUnit.Length)) + 25; //return new Vector2(newX, newY); }