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; } }
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); } }
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(); } }
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); }
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(); }
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(); }