public static Tomt InitializeTomt() { Tomt tomt = new Tomt() { Type = "tomt" }; return(tomt); }
static void Main(string[] args) { // Simulate days //for (int i = 0; i < DaysToSimulate; i++) //{ // // Day Start // // Get 5 random boats // for (int x = 0; i < BoatPerDay; x++) // { // // Does the boat fit in the harbor // // If boat fits, park it, else lose it. // } // // Day End //} for (int i = 0; i < harborSize; i++) // Fyller hamnen med "tomt" { hamn.Add(new Tomt { Type = "tomt", Id = "" }); } Console.WriteLine("------------Empty harbor ---"); foreach (var boat in hamn) { Console.WriteLine(boat.Type); } while (true) { day++; int temp = 0; foreach (var item in hamn) { var q = hamn .GroupBy(a => a.Id) .Where(b => b.Count() > 1) .Select(c => c.Key) .ToList(); foreach (var distinctId in q) { if (item.Id == distinctId) { item.DaysLeft -= 1; } } // item.DaysLeft -= 1; } Console.WriteLine($"-----------DAY {day}-----------------"); for (int i = 0; i < hamn.Count; i++) // Boats depart. { if (hamn[i].Type == "tomt" || hamn[i].DaysLeft == 0) { hamn.RemoveRange(i, 1); Tomt newTomt = InitializeTomt(); hamn.Insert(i, newTomt); } } // If sailboat arrives - find parking, else rejectedboats.add(); for (int i = 0; i < hamn.Count; i++) { // abvryta här? int slump = rnd.Next(1, 4 + 1); switch (slump) { case 1: try { foreach (var item in hamn) { //FindParkingSizeHalf //FindParkingSizeOne //FindparkingSizeTwo //FindparkingSizeFour } hamn.RemoveRange(i, 1); hamn.RemoveRange(i + 1, 1); Sailboat newSailBoat = new Sailboat(); RandomizeSailBoat(newSailBoat); hamn.Insert(i, newSailBoat); hamn.Insert(i + 1, newSailBoat); Console.WriteLine("A sailboat has arrived.... !!"); } catch (ArgumentException) { } break; case 2: try { hamn.RemoveRange(i, 1); Motorboat newMotorBoat = new Motorboat(); RandomizeMotorBoat(newMotorBoat); hamn.Insert(i, newMotorBoat); Console.WriteLine("A Motorboat has arrived.... !!"); } catch (ArgumentException) { } break; case 3: try { hamn.RemoveRange(i, 1); // TODO Hur ska vi göra med roddbåtarna Rowingboat newRowingBboat = new Rowingboat(); RandomizeRowingBoat(newRowingBboat); hamn.Insert(i, newRowingBboat); Console.WriteLine("A Rowingboat has arrived.... !!"); } catch (ArgumentException) { } break; case 4: try { hamn.RemoveRange(i, 4); Freightship newFreightship = new Freightship(); RandomizeFreightship(newFreightship); hamn.Insert(i, newFreightship); hamn.Insert(i + 1, newFreightship); hamn.Insert(i + 2, newFreightship); hamn.Insert(i + 3, newFreightship); Console.WriteLine("A Freightship has arrived.... !!"); } catch (ArgumentException) { } break; default: break; } Console.WriteLine("--------------------------- !!"); int parkingSpace = 1; foreach (var boat in hamn) { Console.WriteLine($" Space: {parkingSpace} Reg: {boat.Id} Type: {boat.Type}, Weight: {boat.Weight}kg Misc: Error. "); parkingSpace++; } Console.ReadKey(true); Boat boata = new Boat(); } } }