示例#1
0
 public GameStateService(INotationService notationService, IPGNService pgnService, IMoveService moveService, IAttackService attackService)
 {
     _notationService = notationService;
     _pgnService      = pgnService;
     _moveService     = moveService;
     _attackService   = attackService;
 }
示例#2
0
 public CoordinateTests()
 {
     _orthogonalService = ServiceProvider.GetService <IOrthogonalService>();
     _attackService     = ServiceProvider.GetService <IAttackService>();
     _gameStateService  = ServiceProvider.GetService <IGameStateService>();
     _moveService       = ServiceProvider.GetService <IMoveService>();
 }
示例#3
0
 public Player(IAttackService attackService, IMoveService moveService, IDeathService deathService,
               UserData userData)
 {
     _attackService = attackService;
     _moveService   = moveService;
     _deathService  = deathService;
     UserData       = userData;
 }
 public PlayService(IUnitOfWork unitOfWork, IUserProvider userProvider, IVisibilityModifierFactory visibilityModifierFactory, 
     IAttackService attackService,
     IMapTemplateProvider mapTemplateProvider, 
     IRandomGen randomGen)
     : base(unitOfWork, userProvider, mapTemplateProvider, visibilityModifierFactory)
 {
     this.attackService = attackService;
     this.randomGen = randomGen;
 }
示例#5
0
 public PlayService(IUnitOfWork unitOfWork, IUserProvider userProvider, IVisibilityModifierFactory visibilityModifierFactory,
                    IAttackService attackService,
                    IMapTemplateProvider mapTemplateProvider,
                    IRandomGen randomGen)
     : base(unitOfWork, userProvider, mapTemplateProvider, visibilityModifierFactory)
 {
     this.attackService = attackService;
     this.randomGen     = randomGen;
 }
示例#6
0
        public void Register(IAttackService attackService)
        {
            LogCons.Inst.Write(LogLevel.Info, $"AttackServiceHandler.Register(): Service {attackService.ServiceName} registered");

            // Register the service in the attack service handler
            this.AttackServices.Add(attackService.ServiceName, attackService);

            // Register the service in the GUI
            this.minaryInstance.RegisterAttackService(attackService.ServiceName);
        }
示例#7
0
        public Player(IAttackService attackService, IMoveService moveService, IDeathService deathService,
                      string name, string passwordHash)
        {
            _attackService = attackService;
            _moveService   = moveService;
            _deathService  = deathService;
            Name           = name;
            Password       = passwordHash;

            Init();
        }
示例#8
0
 public Bot(
     Game game, 
     MapTemplate mapTemplate,
     IAttackService attackService,
     IRandomGen randomGen)
 {
     this.game = game;
     this.mapTemplate = mapTemplate;
     this.attackService = attackService;
     this.randomGen = randomGen;
 }
示例#9
0
 public Bot(
     ILogger log,
     Game game,
     MapTemplate mapTemplate,
     IAttackService attackService,
     IRandomGen randomGen)
 {
     this.log           = log;
     this.game          = game;
     this.mapTemplate   = mapTemplate;
     this.attackService = attackService;
     this.randomGen     = randomGen;
 }
示例#10
0
 public CSBot(
     IOptions <BotConfiguration> config,
     IOptions <CsConfiguration> csconfig,
     IExternalMessagingClient externalMessagingClient,
     IPathingService pathingService,
     ITownManagementService townManagementService,
     IAttackService attackService)
 {
     _config = config.Value;
     _externalMessagingClient = externalMessagingClient;
     _pathingService          = pathingService;
     _csconfig = csconfig.Value;
     _townManagementService = townManagementService;
     _attackService         = attackService;
 }
示例#11
0
        public void Attack(
            IAttackService attackService,
            IRandomGen randomGen,
            MapTemplate mapTemplate,
            string sourceCountryIdentifier,
            string destCountryIdentifier,
            int numberOfUnits)
        {
            this.RequireGameActive();

            if (this.PlayState != PlayState.Attack)
            {
                throw new DomainException(ErrorCode.AttackingNotPossible, "Cannot attack, state incorrect");
            }

            var sourceCountry = this.Map.GetCountry(sourceCountryIdentifier);
            var destCountry   = this.Map.GetCountry(destCountryIdentifier);

            // Check connection
            if (!mapTemplate.AreConnected(sourceCountryIdentifier, destCountryIdentifier))
            {
                throw new DomainException(ErrorCode.CountriesNotConnected, "There is no connection between those countries");
            }

            // Check ownership
            if (sourceCountry.TeamId != this.CurrentPlayer.TeamId)
            {
                throw new DomainException(ErrorCode.OriginCountryNotOwnedByTeam, "Can only initiate actions from countries that belong to the same team");
            }

            if (sourceCountry.PlayerId == destCountry.PlayerId)
            {
                throw new DomainException(ErrorCode.AttackOwnCountries, "Cannot attack own countries");
            }

            if (numberOfUnits <= 0 || sourceCountry.Units - numberOfUnits < this.Options.MinUnitsPerCountry)
            {
                throw new DomainException(ErrorCode.NotEnoughUnits, "Cannot attack with that many units");
            }

            var otherPlayer = this.GetPlayerById(destCountry.PlayerId);

            int attackerUnitsLost = 0;
            int defenderUnitsLost = 0;
            var result            = attackService.Attack(numberOfUnits, destCountry.Units, out attackerUnitsLost, out defenderUnitsLost);

            if (result)
            {
                // Attack was successful
                destCountry.Units = numberOfUnits - attackerUnitsLost;

                this.Map.UpdateOwnership(otherPlayer, this.CurrentPlayer, destCountry);

                this.DistributeCard(randomGen);
            }
            else
            {
                // Attack failed
                destCountry.Units -= defenderUnitsLost;
            }

            // Reduce units in this country in any case
            sourceCountry.Units -= numberOfUnits;

            this.GameHistory.RecordAttack(
                this.CurrentPlayer, otherPlayer,
                sourceCountryIdentifier, destCountryIdentifier,
                numberOfUnits, attackerUnitsLost, defenderUnitsLost,
                result);

            // Reduce number of attacks left
            this.AttacksInCurrentTurn++;

            // Check for victory
            this.CheckForVictory(this.CurrentPlayer, otherPlayer);

            if (this.AttacksInCurrentTurn >= this.Options.AttacksPerTurn)
            {
                this.EndAttack();
            }
        }
示例#12
0
		public Gun(IWriter outputWriter, IAttackService attackService)
		{
			_outputWriter = outputWriter;
			_attackService = attackService;
		}
示例#13
0
 public RookAttackTests()
 {
     _attackService    = ServiceProvider.GetService <IAttackService>();
     _gameStateService = ServiceProvider.GetService <IGameStateService>();
     _moveService      = ServiceProvider.GetService <IMoveService>();
 }
示例#14
0
        public void Attack(
            IAttackService attackService,
            IRandomGen randomGen,
            MapTemplate mapTemplate,
            string sourceCountryIdentifier, 
            string destCountryIdentifier, 
            int numberOfUnits)
        {
            this.RequireGameActive();

            if (this.PlayState != PlayState.Attack)
            {
                throw new DomainException(ErrorCode.AttackingNotPossible, "Cannot attack, state incorrect");
            }

            var sourceCountry = this.Map.GetCountry(sourceCountryIdentifier);
            var destCountry = this.Map.GetCountry(destCountryIdentifier);

            // Check connection
            if (!mapTemplate.AreConnected(sourceCountryIdentifier, destCountryIdentifier))
            {
                throw new DomainException(ErrorCode.CountriesNotConnected, "There is no connection between those countries");
            }

            // Check ownership
            if (sourceCountry.TeamId != this.CurrentPlayer.TeamId)
            {
                throw new DomainException(ErrorCode.OriginCountryNotOwnedByTeam, "Can only initiate actions from countries that belong to the same team");
            }

            if (sourceCountry.PlayerId == destCountry.PlayerId)
            {
                throw new DomainException(ErrorCode.AttackOwnCountries, "Cannot attack own countries");
            }

            if (numberOfUnits <= 0 || sourceCountry.Units - numberOfUnits < this.Options.MinUnitsPerCountry)
            {
                throw new DomainException(ErrorCode.NotEnoughUnits, "Cannot attack with that many units");
            }

            var otherPlayer = this.GetPlayerById(destCountry.PlayerId);

            int attackerUnitsLost = 0;
            int defenderUnitsLost = 0;
            var result = attackService.Attack(numberOfUnits, destCountry.Units, out attackerUnitsLost, out defenderUnitsLost);

            if (result)
            {
                // Attack was successful
                destCountry.Units = numberOfUnits - attackerUnitsLost;

                this.Map.UpdateOwnership(otherPlayer, this.CurrentPlayer, destCountry);

                this.DistributeCard(randomGen);
            }
            else
            {
                // Attack failed
                destCountry.Units -= defenderUnitsLost;
            }

            // Reduce units in this country in any case
            sourceCountry.Units -= numberOfUnits;

            this.GameHistory.RecordAttack(
                this.CurrentPlayer, otherPlayer,
                sourceCountryIdentifier, destCountryIdentifier,
                numberOfUnits, attackerUnitsLost, defenderUnitsLost,
                result);

            // Reduce number of attacks left
            this.AttacksInCurrentTurn++;

            // Check for victory
            this.CheckForVictory(this.CurrentPlayer, otherPlayer);

            if (this.AttacksInCurrentTurn >= this.Options.AttacksPerTurn)
            {
                this.EndAttack();
            }
        }
示例#15
0
 public AttackController(IAttackService attackService) => _attackerService = attackService;
示例#16
0
 public PlayerController(IShipService shipService, IBoardService boardService, IAttackService attackService)
 {
     _shipService   = shipService;
     _boardService  = boardService;
     _attackService = attackService;
 }
示例#17
0
 public BoardController(IBoardService boardService, IShipService shipService, IAttackService attackService)
 {
     _boardService  = boardService;
     _shipService   = shipService;
     _attackService = attackService;
 }