protected internal override void PerformOperation() { if (!Player.Active) { throw new InvalidEventException(this, "The player is inactive."); } if (Shot.Coordinates < new Coordinates(0, 0) || Shot.Coordinates > Player.Match.FieldSize) { throw new InvalidEventException(this, "Invalid shot made."); } var shipHit = ShipList.GetShipAt(Shot); Player.ShotsMade.Add(Shot); if (shipHit != null) { shipHit.Hit(Shot.Coordinates); } }
private void HandlePlayerShot(Event ev) { PlayerShotEvent evCasted = (PlayerShotEvent)ev; Player plr = evCasted.Player; Shot shot = evCasted.Shot; if (plr == myPlayer) { Ship shipHit = ShipList.GetShipAt(shot); if (shipHit == null) { oldController.ShotMiss(shot); } else { oldController.ShotHit(shot, shipHit.IsSunk()); } } else { oldController.OpponentShot(shot); } }