public RailSystem() : base() { InitializeComponent(); StreamReader f2 = new StreamReader("..\\..\\assets\\points.txt", System.Text.Encoding.GetEncoding("gb2312")); String temp; while (!f2.EndOfStream) { Point tempPoint = new Point(0, 0); temp = f2.ReadLine(); int start = 0; int end = 0; while (temp[++end] != ',') ; tempPoint.X = int.Parse(temp.Substring(start, end - start)); start = end + 1; end = start; while (temp[++end] != ' ') ; tempPoint.Y = int.Parse(temp.Substring(start, end - start)); start = end + 1; String location = temp.Substring(start); pointTable.Add(tempPoint, location); } f2.Close(); routeTable = BezierCurve.getCurvesFromFile("..\\..\\assets\\bezier_points.txt"); testRoute = Route.routeFromFile("..\\..\\assets\\test_route.txt"); Line tempLine; while ((tempLine = testRoute.moveToNextLine()) != null) bezierRoute.addBezierCurve(getBezierCurveFromHash(tempLine)); }
public static Route routeFromFile(String filePath) { Route route = new Route(); StreamReader sr = new StreamReader(filePath); int count = 0; Point firstPoint = new Point(); Point secondPoint = new Point(); while (!(sr.EndOfStream)) { String line = sr.ReadLine(); if (count == 0) { firstPoint = Utility.getPointFromString(line); count = 1; } else if (count == 1) { secondPoint = Utility.getPointFromString(line); route.addLine(new Line(firstPoint, secondPoint)); firstPoint = secondPoint; count = 1; } } sr.Close(); return route; }