public void PrintRoad(Road road, Object o) { CharMatrix cm = (CharMatrix)o; int x, y; int CCx = Conversions.WCpointToCCpoint(road.GetXLocation()); int CCy = Conversions.WCpointToCCpoint(-road.GetYLocation()); int distance = 0; int CCRoadLength = Conversions.WClengthToCClength(road.GetLength()); switch (road.GetHeading()) { case Heading.North: x = (int)CCx; if (x >= 0 && x < Constants.CharMapSize) { while (distance < CCRoadLength) { y = (int)(CCy - distance); if (y >= 0 && y < Constants.CharMapSize) { cm.map[y][x] = '|'; cm.map[y][x + 2] = '|'; cm.map[y][x + 4] = '|'; } distance += 1; } } break; case Heading.South: break; case Heading.East: y = (int)CCy; if (y >= 0 && y < Constants.CharMapSize) { while (distance < CCRoadLength) { x = (int)(CCx + distance); if (x >= 0 && x < Constants.CharMapSize) { cm.map[y][x] = '-'; cm.map[y + 2][x] = '-'; cm.map[y + 4][x] = '-'; } distance += 1; } } break; case Heading.West: break; default: break; } }
static void Main(string[] args) { GUI simInput; Map map = new Map(); IPrintDriver cp = new ConsolePrint(); //Console.Write("Enter 'M' for metric or 'I' for Imperial: "); //string units = Console.ReadLine(); //Console.Write("Enter speed limit: "); //double speedLimit = Convert.ToDouble(Console.ReadLine()); //if (units == "I") gui = new ImperialGUI(); //else gui = new MetricGUI(); //Car car = new Car(); gui.SetSpeedLimit(car, speedLimit); //Truck truck1 = new Truck(4); gui.SetSpeedLimit(truck1, speedLimit); //Truck truck2 = new Truck(8); gui.SetSpeedLimit(truck2, speedLimit); //List<Vehicle> vehicles = new List<Vehicle>(); //vehicles.Add(car); vehicles.Add(truck1); vehicles.Add(truck2); //for (int i = 0; i < 11; i++) //{ // foreach (Vehicle v in vehicles) // { // v.UpdateSpeed(1); // string s = v.GetType().ToString(); // Console.WriteLine("{0} speed: {1:F}", s, gui.GetSpeed(v)); // } //} simInput = new MetricGUI(); Road Uptown = simInput.CreateRoad("Uptown", 0.0, -0.09, .180, Heading.North); map.AddRoad(Uptown); Road Crosstown = simInput.CreateRoad("Crosstown", -0.09, 0.0, .180, Heading.East); map.AddRoad(Crosstown); CharMatrix cm = new CharMatrix(); map.Print(cp, cm); for (int i = 0; i < Constants.CharMapSize; i++) { string s = new string(cm.map[i]); Console.WriteLine(s); } }