Exemplo n.º 1
0
        private void OnPlayerShooting(object sender, ShootingEventArgs e)
        {
            var    shooter = (Player)sender;
            Board  oponentBoard;
            Player openent;

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

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

            e.Result = shotResult;

            if (_scoreBoard.GameHasEnded())
            {
                return;
            }
        }
Exemplo n.º 2
0
        protected void ShotTargetChosen(int x, int y)
        {
            if (!_canSoot)
            {
                return;
            }

            _canSoot = 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);
            }
        }
Exemplo n.º 3
0
        private void OnPlayerShotShot(object sender, ShootingEventArgs e)
        {
            if (_scoreBoard.GameHasEnded())
            {
                return;
            }

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

            if (e.Result != ShotResult.Missed)
            {
                shooter.Shoot();
            }
            else
            {
                openent.Shoot();
            }
        }
Exemplo n.º 4
0
        protected void ShotTargetChosen(int x, int y)
        {
            if (!_canSoot)
                return;

            _canSoot = 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);
        }
Exemplo n.º 5
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();
 }
Exemplo n.º 6
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();
 }