Beispiel #1
0
        public static DoubleCoord CreateBothCoords(int shipSize, Board board)
        {
            DoubleCoord result;

            do
            {
                result = new DoubleCoord(board, shipSize);
            }while (!(result.CellsNotIdentical() && result.CorrectDistanceBetweenCoords(shipSize)));

            return(result);
        }
Beispiel #2
0
 public void AskPlayerToPlaceShip(int shipSize)
 {
     if (shipSize > 1)
     {
         var doubleCoord = DoubleCoord.CreateBothCoords(shipSize, this);
         AllShips.Add(new Ship(doubleCoord, this));
     }
     else
     {
         var coord = Coord.CreateNewCoord(this, shipSize, "");
         AllShips.Add(new Ship(coord, this));
     }
 }
Beispiel #3
0
        public Ship(DoubleCoord doubleCoord, Board board)
        {
            Body = new List <Part>();

            for (int row = Math.Min(doubleCoord.First.Letter, doubleCoord.Second.Letter);
                 row <= Math.Max(doubleCoord.First.Letter, doubleCoord.Second.Letter); row++)
            {
                for (int column = Math.Min(doubleCoord.First.Number, doubleCoord.Second.Number);
                     column <= Math.Max(doubleCoord.First.Number, doubleCoord.Second.Number); column++)
                {
                    Body.Add(new Part
                    {
                        ShipPart = CellContent.ship,
                        Coord    = new Coord {
                            Letter = row, Number = column
                        }
                    });
                }
            }

            UpdateShipOnBoard(board);
        }