Beispiel #1
0
 public bool TryShoot(int x, int y)
 {
     if (x < 0 || y < 0 || x > 9 || y > 9)
     {
         return(false);
     }
     if (enemyField[x, y] == CellStates.Empty || enemyField[x, y] == CellStates.DeadSmallShip)
     {
         return(false);
     }
     if (enemyField[x, y] == CellStates.Water)
     {
         enemyField[x, y] = CellStates.Empty;
         canShoot         = false;
     }
     else
     {
         enemyField[x, y] = Converter.GetDeadState(enemyField[x, y]);
         if (Ship.IsDead(enemyField, new System.Drawing.Point(x, y)))
         {
             enemyShipCount--;
         }
     }
     return(true);
 }
Beispiel #2
0
 void ProcessPoint(int x, int y, Model world)
 {
     if (world.playerField[x, y] == CellStates.Water)
     {
         avalibleTargets.Remove(new Point(x, y));
         world.playerField[x, y] = CellStates.Empty;
         canShootAgain           = false;
     }
     else
     {
         for (var dx = -1; dx <= 1; dx++)
         {
             for (var dy = -1; dy <= 1; dy++)
             {
                 if (x + dx < 0 || y + dy < 0 || x + dx > 9 || y + dy > 9)
                 {
                     continue;
                 }
                 //if (Ship.IsShip(world.playerField[x + dx, y + dy])) continue;
                 if (world.playerField[x, y] == CellStates.ShipBackRight && dx == 0 && dy == 1)
                 {
                     continue;
                 }
                 else if (world.playerField[x, y] == CellStates.ShipMiddleRight && dx == 0 && dy != 0)
                 {
                     continue;
                 }
                 else if (world.playerField[x, y] == CellStates.ShipHeadRight && dx == 0 && dy == -1)
                 {
                     continue;
                 }
                 else if (world.playerField[x, y] == CellStates.ShipBackUp && dx == -1 && dy == 0)
                 {
                     continue;
                 }
                 else if (world.playerField[x, y] == CellStates.ShipMiddleUp && dx != 0 && dy == 0)
                 {
                     continue;
                 }
                 else if (world.playerField[x, y] == CellStates.ShipHeadUp && dx == 1 && dy == 0)
                 {
                     continue;
                 }
                 avalibleTargets.Remove(new Point(x + dx, y + dy));
             }
         }
         world.playerField[x, y] = Converter.GetDeadState(world.playerField[x, y]);
         knownDirection          = Converter.GetDirection(world.playerField[x, y]);
         if (Ship.IsDead(world.playerField, new Point(x, y)))
         {
             world.playerShipCount--;
         }
         canShootAgain = true;
     }
 }