Exemple #1
0
 public void Setup(Commands.SetupCommand setupData)
 {
     _squares = new Square[Dimension, Dimension];
     _ships   = setupData.CreateShips();
     Parallel.ForEach(_ships, ship =>
     {
         Array.ForEach(ship.Squares, shipSquare =>
         {
             if (!CheckPoint(shipSquare.Point))
             {
                 throw new InvalidDataException($"ship '{ship.Name}' can't fit within board");
             }
             var existing = _squares[shipSquare.Point.X, shipSquare.Point.Y];
             if (existing?.ShipIndex != null)
             {
                 throw new InvalidDataException(
                     $"ship '{ship.Name}' overlapping with ship '{_ships[existing.ShipIndex.Value].Name}'");
             }
             _squares[shipSquare.Point.X, shipSquare.Point.Y]
                 = new Square {
                     Result = shipSquare.Result, ShipIndex = Array.IndexOf(_ships, ship)
                 };
         });
     });
 }
Exemple #2
0
 public void Setup(Commands.SetupCommand setup)
 {
     _boards = new Board();
     _boards.Setup(setup);
 }