Example #1
0
 public bool PlaceShipAtlocation(Ship ship, int X, int Y)
 {
     // can be a util
     //  boundry conditions
     if ((X > SIZE) || (Y > SIZE))
     {
         return(false);
     }
     //  check if a postion can hold a ship first then place it
     if (CanShipBePlacedHorizontalRight(
             ship.Size(), X, Y))
     {
         for (int i = Y; i < (Y + ship.Size()); i++)
         {
             gameBoard[X, i].holder = ship;
             gameBoard[X, i].free   = false;
         }
         return(true);
     }
     else if (CanShipBePlacedHorizontalLeft(ship.Size(), X, Y))
     {
         for (int i = Y; i > (Y - ship.Size()); i--)
         {
             gameBoard[X, i].holder = ship;
             gameBoard[X, i].free   = false;
         }
         return(true);
     }
     else if (CanShipBePlacedVerticalUp(ship.Size(), X, Y))
     {
         for (int i = X; i < (X + ship.Size()); i++)
         {
             gameBoard[i, Y].free   = false;
             gameBoard[i, Y].holder = ship;
         }
         return(true);
     }
     else if (CanShipBeVerticalDown(ship.Size(), X, Y))
     {
         for (int i = X; i > (X - ship.Size()); i--)
         {
             gameBoard[i, Y].free   = false;
             gameBoard[i, Y].holder = ship;
         }
         return(true);
     }
     return(false);
 }