Esempio n. 1
0
        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);
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
        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;
                }
            }
        }
Esempio n. 4
0
 private void Cell_OnCellStateChanged(SeaCell cell)
 {
     this.OnCellStateChanged?.Invoke(cell);
 }
Esempio n. 5
0
 public void AddCell(SeaCell cell)
 {
     AddCells(new SeaCell[] { cell });
 }
Esempio n. 6
0
 private void Board_OnCellStateChanged(SeaCell cell)
 {
     this.OnBoardCellStateChanged?.Invoke(this, cell);
 }