public BattleShipShooterTracker(Type shooterType, string name = null)
        {
            try
            {
                _originalShooter = (IBattleShipShooter)Activator.CreateInstance(shooterType);
            }
            catch (Exception e)
            {
                Console.WriteLine(JsonConvert.SerializeObject(e));
                throw new Exception($"Cannot initiate shooter {name ?? shooterType.FullName}! Error: {e.InnerException?.Message ?? e.Message}");
            }

            CaptainName = string.IsNullOrEmpty(name) ? _originalShooter.CaptainName : name;
            if (string.IsNullOrEmpty(CaptainName))
            {
                throw new Exception($"Shooter {shooterType.FullName} doesn't have a name!");
            }
        }
示例#2
0
 public BattleShipPlayer(IBattleShipShooter shooter)
 {
     Shooter = shooter;
 }
 public BattleShipGame(IBattleShipShooter shooter1, IBattleShipShooter shooter2)
 {
     Player1 = new BattleShipPlayer(shooter1);
     Player2 = new BattleShipPlayer(shooter2);
 }