private void OnBoardCellStateChanged(Board board, SeaCell cell) { if (cell.CellState == SeaCellState.SHIP_SUNK) { //There is a seperate event for that (OnShipSunk) to compress it down into one packet. return; } var packet = new S2C_GameBoardUpdated(BoardOwner.ME, new[] { cell.GetSimplifiedCell() }); board.Player.RemotePlayer.Connection.Send(packet); packet.BoardOwner = BoardOwner.ENEMY; board.Player.Opponent.RemotePlayer.Connection.Send(packet); }
public FireResult OnHit(SeaCell cell) { if (cell.CellState == SeaCellState.SHIP) { if (this.Health == 1) { this.Sink(); return(FireResult.SHIP_SUNK); } else { cell.SetState(SeaCellState.SHIP_HIT); return(FireResult.SHIP_HIT); } } return(FireResult.ALREADY_FIRED); }
public Board(int boardSize) { this.BoardSize = boardSize; this.Ships = new List <Ship>(); this.Cells = new SeaCell[boardSize, boardSize]; SeaCell tmp; for (int x = 0; x < boardSize; x++) { for (int y = 0; y < boardSize; y++) { tmp = new SeaCell(x, y); tmp.OnCellStateChanged += Board_OnCellStateChanged; this.Cells[x, y] = tmp; } } }
private void Cell_OnCellStateChanged(SeaCell cell) { this.OnCellStateChanged?.Invoke(cell); }
public void AddCell(SeaCell cell) { AddCells(new SeaCell[] { cell }); }
private void Board_OnCellStateChanged(SeaCell cell) { this.OnBoardCellStateChanged?.Invoke(this, cell); }