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); } } } }
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; } } } } } }
public void CreateFieldForBot(ShipGameAssignment ship) { DoRandom(false); SelectedShip = ship; }