Пример #1
0
        protected void ShotTargetChosen(int x, int y)
        {
            if (!_canShot)
            {
                return;
            }

            _canShot = false;

            var shooting = Shooting;

            if (shooting == null)
            {
                return;
            }

            var eventArgs = new ShootingEventArgs(x, y);

            shooting(this, eventArgs);
            AddShotResult(x, y, eventArgs.Result);

            var shot = Shot;

            if (shot != null)
            {
                shot(this, eventArgs);
            }
        }
Пример #2
0
        private void OnPlayerShooting(object sender, ShootingEventArgs e)
        {
            var    shooter = (Player)sender;
            Board  opponentBoard;
            Player opponent;

            if (shooter == _player1)
            {
                opponent      = _player2;
                opponentBoard = _board2;
            }
            else
            {
                opponent      = _player1;
                opponentBoard = _board1;
            }

            var shotResult = opponentBoard.opponentShotAt(e.X, e.Y);

            e.Result = shotResult;

            if (_scoreBoard.GameHasEnded())
            {
                return;
            }
        }
Пример #3
0
        private void OnPlayerShotShot(object sender, ShootingEventArgs e)
        {
            if (_scoreBoard.GameHasEnded())
            {
                return;
            }

            var shooter  = (Player)sender;
            var opponent = shooter == _player1 ? _player2 : _player1;

            if (e.Result != ShotResult.Missed)
            {
                shooter.Shoot();
            }
            else
            {
                opponent.Shoot();
            }
        }
Пример #4
0
 private void OnPlayerMadeShot(object sender, ShootingEventArgs e)
 {
     if (sender == _player1)
     {
         _shotsLeft.X--;
         if (e.Result == ShotResult.ShipDrowned)
         {
             _shipsLeft.Y--;
         }
     }
     else
     {
         _shotsLeft.Y--;
         if (e.Result == ShotResult.ShipDrowned)
         {
             _shipsLeft.X--;
         }
     }
     TrackResult();
     RefreshPlayerStats();
 }