//Flytter biler fra start til slutt public void SendCarToExit() { var view = new View(_crossroad); var side = CheckBiggestQueue(); CrossroadSide otherSide = null; if (side == _crossroad.Top) { otherSide = _crossroad.Right; } if (side == _crossroad.Right) { otherSide = _crossroad.Bottom; } if (side == _crossroad.Bottom) { otherSide = _crossroad.Left; } if (side == _crossroad.Left) { otherSide = _crossroad.Top; } while (side.Exit.TrafficLight.GreenLight) { Car car1 = null; Car car2 = null; if (side.Start.carList.Count > 0) { var car = side.Start.carList[0]; car1 = car; car.Start.carList.RemoveAt(0); car.Exit.CarCollection.Add(car); } if (otherSide.Start.carList.Count > 0) { var car = otherSide.Start.carList[0]; if (car.Exit == side.Exit) { car2 = car; car.Start.carList.RemoveAt(0); car.Exit.CarCollection.Add(car); } } view.Show(car1, car2, side); } }
public void Show(Car car1, Car car2, CrossroadSide side) { Console.Clear(); if (car1 != null) { Console.WriteLine("The car came from " + car1.Start.Name + " and went to " + car1.Exit.Name); } if (car2 != null) { Console.WriteLine("The car came from " + car2.Start.Name + " and went to " + car2.Exit.Name); } Console.WriteLine("\r\nIt's green for: " + side.Start.Name + "\r\n"); Console.Write("Top lane: "); for (var indexTop = 0; indexTop < crossroad.Top.Start.carList.Count; indexTop++) { Console.Write("|"); } Console.WriteLine(); Console.Write("Right lane: "); for (var indexRight = 0; indexRight < crossroad.Right.Start.carList.Count; indexRight++) { Console.Write("|"); } Console.WriteLine(); Console.Write("Bottom lane: "); for (var indexBottom = 0; indexBottom < crossroad.Bottom.Start.carList.Count; indexBottom++) { Console.Write("|"); } Console.WriteLine(); Console.Write("Left lane: "); for (var indexLeft = 0; indexLeft < crossroad.Left.Start.carList.Count; indexLeft++) { Console.Write("|"); } Console.WriteLine(); Thread.Sleep(500); }