示例#1
0
 public void MakeAMove(int?x, int?y, bool isplayer = false)
 {
     if (x != null && y != null && Game != null)
     {
         Game.Cells.Single(c => c.X == x && c.Y == y && c.IsPlayer == isplayer && c.GameId == Game.Id).IsHit = true;
         Cell shipCell = _context.Cells.Single(c => c.X == x && c.Y == y && c.IsPlayer == isplayer && c.GameId == Game.Id);
         if (shipCell.ShipName != null && Game.CanGoToAnother)
         {
             ShipGameAssignment shipToKill = _context.ShipGameAssignments.Single(s => s.ShipName == shipCell.ShipName);
             shipToKill.Cells = Game.Cells.Where(c => c.ShipName == shipToKill.ShipName).ToList();
             if (ShipIsKilled(Game.Cells.Single(c => c.X == x && c.Y == y && c.IsPlayer == isplayer && c.GameId == Game.Id).ShipName))
             {
                 SetKillShip(shipToKill);
             }
         }
     }
 }
示例#2
0
 public void SetKillShip(ShipGameAssignment ship)
 {
     if (Game != null && ship.Cells != null)
     {
         int x;
         int y;
         foreach (Cell cell in ship.Cells)
         {
             x = cell.X;
             y = cell.Y;
             for (int i = -1; i < 2; i++)
             {
                 for (int j = -1; j < 2; j++)
                 {
                     if (x + j > 0 && x + j < Game.Width + 1 && y + i > 0 && y + i < Game.Heigth + 1)
                     {
                         Cell cell_to_hit = Game.Cells.Single(c => c.X == x + j && c.Y == y + i && c.IsPlayer == ship.IsPlayer);
                         cell_to_hit.IsHit = true;
                     }
                 }
             }
         }
     }
 }
示例#3
0
 public void CreateFieldForBot(ShipGameAssignment ship)
 {
     DoRandom(false);
     SelectedShip = ship;
 }