public void DisplayInfo() { Console.WriteLine("Additional dock info: "); Console.WriteLine(); int row = Boats .OfType <RowingBoat>() .Count(); int pow = Boats .OfType <PowerBoat>() .Count(); int sail = Boats .OfType <SailBoat>() .Count(); int cata = Boats .OfType <Catamaran>() .Count(); int carg = Boats .OfType <CargoShip>() .Count(); var weight = Boats .GroupBy(b => b.Weight) .Sum(b => b.Key); var speed = Boats .GroupBy(b => b.MaxSpeed) .Sum(b => b.Key); var emptySlot = Docks .Count(b => b == null); int speedInKMH = speed / Boats.Count(); Console.WriteLine("Number of docked boats: "); Console.WriteLine($"Rowingboat: {row}"); Console.WriteLine($"Powerboat: {pow}"); Console.WriteLine($"Sailboat: {sail}"); Console.WriteLine($"Catamaran: {cata}"); Console.WriteLine($"Cargoship: {carg}"); Console.WriteLine($"Total weight in dock: {weight} kg"); Console.WriteLine($"Average maximum speed in dock: {(speedInKMH * 1.85200)} km/h"); Console.WriteLine($"Empty slots in dock: {emptySlot/2}"); Console.WriteLine($"Number of total boats added: {AddedBoats}"); Console.WriteLine($"Number of total boats rejected: {RejectedBoats}"); }
/// <summary> /// Checks if parsed boats are correct and connects them to the BattleField in the case of success /// </summary> /// <param name="p_message">Error string</param> /// <returns>returns true if arrangement was correct</returns> public bool CheckArrangement(out string p_message) { // 3. Check if Boats are correct bool _result = true; //first check quantity if (Boats != null) { if (Boats.All(b => (b.Cells.Select(c => c.x).Distinct().Count() == 1) || (b.Cells.Select(c => c.y).Distinct().Count() == 1) ) ) { if (Boats.Count == 10) { if (Boats.All(a => a.Cells.Count <= 4)) { if ( Boats.Count(a => a.Cells.Count == 4) == 1 && Boats.Count(a => a.Cells.Count == 3) == 2 && Boats.Count(a => a.Cells.Count == 2) == 3 && Boats.Count(a => a.Cells.Count == 1) == 4 ) { _result = true; p_message = "The Boats arranged correctly"; } else { _result = false; p_message = "Wrong set of Boats"; } } else { _result = false; p_message = "Some Boats are too long"; } } else { _result = false; p_message = "Incorrect quantity of Boats"; } } else { _result = false; p_message = "A Boat can't bend or touch an other Boat diagonally"; } } else { throw new Exception("Before Check the Boats should be parsed"); } if (_result) { foreach (var boat in Boats) { this.ConnectBoatToBF(boat); } } return(_result); }