private void button1_Click(object sender, EventArgs e) { foreach (Crossing crozz in this.cl.ActiveGrid.ListOfCrossings) { this.cl.ActiveGrid.MakeNeighbours(crozz); } this.cl.ActiveGrid.SetAllStartPoints(); MessageBox.Show(this.cl.ActiveGrid.ListOfAllStartPoints.Count.ToString()); Lane l = this.cl.ActiveGrid.ListOfCrossings.ElementAt(0).LisftOfLanes.ElementAt(0); Crossing c = this.cl.ActiveGrid.ListOfCrossings[0]; c.UserChosenStartPoint = c.LisftOfLanes[0].Road[0]; this.cl.ActiveGrid.CreateRoads(c, new List <Point>(), new List <Crossing>()); CarStream cs = new CarStream(0, 10, this.cl.ActiveGrid.AllRoads.First()); this.cl.ActiveGrid.AddCarStream(cs); this.cl.ActiveGrid.SetCurrentCrossingsToCars(); MessageBox.Show(this.cl.ActiveGrid.AllRoads.Count.ToString()); this.Invalidate(); }
public void LoadLanesFromFile(String filename) { StreamReader str = null; try { str = new StreamReader(new FileStream(filename, FileMode.Open, FileAccess.Read)); String s = ""; s = str.ReadLine(); s = str.ReadLine(); while (s.ToLower() != "right") { string[] tokens = s.Split(); string id = tokens[0]; Point entryPoint = new Point(Convert.ToInt16(tokens[1]) + this.Position.X, Convert.ToInt16(tokens[2]) + this.Position.Y); Point stopPoint = new Point(Convert.ToInt16(tokens[3]) + this.Position.X, Convert.ToInt16(tokens[4]) + this.Position.Y); Point curveEnd = new Point(Convert.ToInt16(tokens[5]) + this.Position.X, Convert.ToInt16(tokens[6]) + this.Position.Y); Point exitPoint = new Point(Convert.ToInt16(tokens[7]) + this.Position.X, Convert.ToInt16(tokens[8]) + this.Position.Y); Lane newLane = new Lane(id, entryPoint, stopPoint, curveEnd, exitPoint); List <Point> leftTurnPoints = new List <Point>(); for (int i = 9; i < tokens.Length; i += 2) { leftTurnPoints.Add(new Point((Convert.ToInt16(tokens[i]) + this.Position.X), (Convert.ToInt16(tokens[i + 1])) + this.Position.Y)); } newLane.Road.InsertRange(2, leftTurnPoints); this.LisftOfLanes.Add(newLane); s = str.ReadLine(); } s = str.ReadLine(); while (s.ToLower() != "straight") { string[] tokens = s.Split(); string id = tokens[0]; Point entryPoint = new Point(Convert.ToInt16(tokens[1]) + this.Position.X, Convert.ToInt16(tokens[2]) + this.Position.Y); Point stopPoint = new Point(Convert.ToInt16(tokens[3]) + this.Position.X, Convert.ToInt16(tokens[4]) + this.Position.Y); Point curveStart = new Point(Convert.ToInt16(tokens[5]) + this.Position.X, Convert.ToInt16(tokens[6]) + this.Position.Y); Point curveEnd = new Point(Convert.ToInt16(tokens[7]) + this.Position.X, Convert.ToInt16(tokens[8]) + this.Position.Y); Point exitPoint = new Point(Convert.ToInt16(tokens[9]) + this.Position.X, Convert.ToInt16(tokens[10]) + this.Position.Y); Lane newLane = new Lane(id, entryPoint, stopPoint, curveStart, curveEnd, exitPoint); this.LisftOfLanes.Add(newLane); s = str.ReadLine(); } s = str.ReadLine(); while (s.ToLower() != "end") { string[] tokens = s.Split(); string id = tokens[0]; Point entryPoint = new Point(Convert.ToInt16(tokens[1]) + this.Position.X, Convert.ToInt16(tokens[2]) + this.Position.Y); Point stopPoint = new Point(Convert.ToInt16(tokens[3]) + this.Position.X, Convert.ToInt16(tokens[4]) + this.Position.Y); Point exitPoint = new Point(Convert.ToInt16(tokens[5]) + this.Position.X, Convert.ToInt16(tokens[6]) + this.Position.Y); Lane newLane = new Lane(id, entryPoint, stopPoint, exitPoint); this.LisftOfLanes.Add(newLane); s = str.ReadLine(); } } catch (IOException) { } finally { if (str != null) { str.Close(); } } }