private void SetBoatCells(Boat boat, Cell type) { var cells = boat.GetCellIndexes(); for (int i = 0; i < boat.Length; i++) { m_myGrid[cells[i, 0], cells[i, 1]] = type; } }
private bool TrySink(Boat boat, int x, int y) { var cells = boat.GetCellIndexes(); bool sunked = true; for (int i = 0; i < boat.Length; i++) { if (m_myGrid[cells[i, 0], cells[i, 1]] == Cell.Hit || m_myGrid[cells[i, 0], cells[i, 1]] == Cell.Sunked) continue; sunked = false; break; } if (sunked) { SetBoatCells(boat, Cell.Sunked); boat.IsSunk = true; CheckGameOver(); } return sunked; }
private bool PositionLegal(Boat boat) { try { var cells = boat.GetCellIndexes(); for(int i = 0; i < boat.Length; i++) { if (m_myGrid[cells[i, 0], cells[i, 1]] != Cell.Empty) return false; } } catch (Exception e) { return false; } return true; }