コード例 #1
0
        private void HandleAccurateShot(Shot shot, IShip shotShip)
        {
            SetField(boardStateFields, shot.Position, new ShootShipField(shot.Position, shotShip));
            SetField(playerFields, shot.Position, new ShootShipField(shot.Position, shotShip));

            var boardContext = new ReadOnlyBoardContext(this);

            if (shotShip.IsSunk)
            {
                ShipSunk?.Invoke(this, new ShipSunkEventArgs(shotShip, boardContext));

                if (Ships.All(s => s.IsSunk))
                {
                    AllShipsSunk?.Invoke(this, new AllShipsSunkEventArgs(shotHistory.Count, boardContext));
                }
            }
            else
            {
                AccurateShot?.Invoke(this, new AccurateShotEventArgs(shotShip.Name, boardContext));
            }
        }
コード例 #2
0
ファイル: GameEventArgs.cs プロジェクト: wtor/Battleships
 public GameFinishedEventArgs(Action restartGame, ReadOnlyBoardContext board)
 {
     Board            = board;
     this.restartGame = restartGame;
 }
コード例 #3
0
 public AllShipsSunkEventArgs(int shotsCount, ReadOnlyBoardContext board)
 {
     ShotsCount = shotsCount;
     Board      = board;
 }
コード例 #4
0
 public RepeatedShotEventArgs(Shot shot, ReadOnlyBoardContext board)
 {
     Shot  = shot;
     Board = board;
 }
コード例 #5
0
 public MissedShotEventArgs(ReadOnlyBoardContext board)
 {
     Board = board;
 }
コード例 #6
0
 public AccurateShotEventArgs(string shipName, ReadOnlyBoardContext board)
 {
     ShipName = shipName;
     Board    = board;
 }
コード例 #7
0
 public ShipSunkEventArgs(IShip ship, ReadOnlyBoardContext board)
 {
     Board    = board;
     ShipName = ship.Name;
 }