public Path Diverge() { Path Next = new Path(Start, null); Next.Points = new List<Point>(Points); if (End != null) { Next.AddEnd(End); } return Next; }
private void GenerateMatrix(Node Prev, Point Aqui, Path Path) { if (CheckedBoard == null) { CheckedBoard = new bool[Board.Width, Board.Height]; } CheckedBoard[Aqui.X, Aqui.Y] = true; if (Path == null) { Path = new Path(this, null); } if (All.ContainsKey(Aqui) && (!Prev.Location.Equals(Aqui) || Path.Points.Count > 1)) { Node node; All.TryGetValue(Aqui, out node); Path.AddEnd(node); Prev.Paths.Add(Path); node.Paths.Add(Path.Reverse()); //foreach (Point Point in Path.Points) //{ // UI.RegisterSprite(new StaticSprite(new Element { X = Point.X, Y = Point.Y }, "fruit/banana", 20)); //} return; } if (SurroundingFreeSpaces(Aqui) > 2 && !Path.Start.Location.Equals(Aqui) && !All.ContainsKey(Aqui)) { //UI.RegisterSprite(new StaticSprite(new Element { X = Aqui.X, Y = Aqui.Y }, "fruit/orange", 20)); Node End = new Node(Aqui); All.Add(Aqui, End); //Path.AddEnd(End); //Prev.Paths.Add(Path); //End.Paths.Add(Path.Reverse()); //foreach (Point Point in Path.Points) //{ // UI.RegisterSprite(new StaticSprite(new Element { X = Point.X, Y = Point.Y }, "fruit/cherry", 20)); //} End.GenerateMatrix(End, End.Location, null); return; } for (double i = 0; i < 2 * MathHelper.Pi; i+= MathHelper.Pi/2) { Point Next = new Point(Aqui.X + (int)Math.Round(Math.Sin(i)), Aqui.Y + (int)Math.Round(Math.Cos(i))); if(IsInBounds(Next) && !Board.IsType(Enum.ElementTypes.Wall, Next) && !CheckedBoard[Next.X, Next.Y]){ GenerateMatrix(Prev, Next, Aqui.Equals(Location)?Path.Diverge():Path.Diverge(Aqui)); } } }
public Path Reverse() { Path Out = new Path(End, Start); Out.Points = new List<Point>(Points); Out.Points.Reverse(); Out.Start = End; Out.End = Start; return Out; }