private void OnPlayerShooting(object sender, ShootingEventArgs e)
        {
            var    shooter = (Player)sender;
            Board  oponentBoard;
            Player oponent;

            if (shooter == _player1)
            {
                oponent      = _player2;
                oponentBoard = _board2;
            }
            else
            {
                oponent      = _player1;
                oponentBoard = _board1;
            }

            var shotResult = oponentBoard.OponentShotAt(e.X, e.Y);

            e.Result = shotResult;

            if (_scoreBoard.GameHasEnded())
            {
                return;
            }
        }
예제 #2
0
        public void ShotTargetChosen(int x, int y)
        {
            if (!_canShoot)
            {
                return;
            }

            _canShoot = 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);
            }
        }
        private void OnPlayerShotShot(object sender, ShootingEventArgs e)
        {
            if (_scoreBoard.GameHasEnded())
            {
                return;
            }

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

            if (e.Result != ShotResult.Missed)
            {
                shooter.Shoot();
            }
            else
            {
                oponent.Shoot();
            }
        }
 private void OnPlayerMadeShot(object sender, ShootingEventArgs e)
 {
     if (sender == _player1)
     {
         _shotsMade.X++;
         if (e.Result == ShotResult.ShipDrowned)
         {
             _shipsLeft.Y--;
         }
     }
     else
     {
         _shotsMade.Y++;
         if (e.Result == ShotResult.ShipDrowned)
         {
             _shipsLeft.X--;
         }
     }
     TrackResult();
     RefreshPlayerStats();
 }