protected DTO.Games.Game MapAndApplyModifiers(Game game)
        {
            var mappedGame = Mapper.Map<DTO.Games.Game>(game);

            // Apply visibility modifications
            foreach (var visibilityModifier in game.Options.VisibilityModifier)
            {
                var visibilityModifierInstance = this.visibilityModifierFactory.Construct(visibilityModifier);

                visibilityModifierInstance.Apply(this.CurrentUser, mappedGame);
            }

            if (game.CurrentPlayer != null)
            {
                if (game.CurrentPlayer.UserId == this.userProvider.GetCurrentUserId())
                {
                    // Show extended information
                    mappedGame.CurrentPlayer = Mapper.Map<DTO.Games.Player>(game.CurrentPlayer);
                }
                else
                {
                    mappedGame.CurrentPlayer = Mapper.Map<DTO.Games.PlayerSummary>(game.CurrentPlayer);
                }
            }

            mappedGame.UnitsToPlace = game.GetUnitsToPlace(this.mapTemplateProvider.GetTemplate(game.MapTemplateName), game.CurrentPlayer);

            return mappedGame;
        }
        public static Country GetCountryWithEnemyConnection(Game game, Player player, MapTemplate mapTemplate)
        {
            var enemyCountries = GetEnemyCountries(game, player);

            return player.Countries.First(
                    c => enemyCountries.Any(c2 => mapTemplate.AreConnected(c.CountryIdentifier, c2.CountryIdentifier)));
        }
Esempio n. 3
0
        internal Map(Game game, IList<Country> countryCollection)
        {
            this.game = game;
            this.Countries = countryCollection;

            this.ResetChanges();
        }
Esempio n. 4
0
 public Team(Game game)
     : this()
 {
     this.Players = new HashSet<Player>();
     this.Game = game;
     this.PlayOrder = game.Teams.Count();
 }
Esempio n. 5
0
 public Bot(
     Game game, 
     MapTemplate mapTemplate,
     IAttackService attackService,
     IRandomGen randomGen)
 {
     this.game = game;
     this.mapTemplate = mapTemplate;
     this.attackService = attackService;
     this.randomGen = randomGen;
 }
Esempio n. 6
0
        public static Map CreateFromTemplate(Game game, MapTemplate mapTemplate)
        {
            var map = new Map(game, game.Countries);

            foreach (var countryTemplate in mapTemplate.Countries)
            {
                var country = Country.CreateFromTemplate(map, countryTemplate, game.Options.InitialCountryUnits);

                map.Countries.Add(country);
            }

            return map;
        }
Esempio n. 7
0
        public static Game CreateGame(int teams = 2, int playerPerTeam = 1, Enums.GameType type = GameType.Fun)
        {
            var mapTemplate = new MapTemplate("blah");

            var game = new Game(
                CreateUser("Test"),
                type,
                "NewGame",
                mapTemplate.Name,
                60 * 10,
                teams,
                playerPerTeam,
                new[] { VictoryConditionType.Survival },
                new[] { VisibilityModifierType.None });

            return game;
        }
 public LadderGameStartedEvent(Ladder ladder, Game game)
     : base(game)
 {
     this.Ladder = ladder;
 }
        public void SynchronizeGames()
        {
            // Arrange
            var mockUnitOfWork = TestUtils.GetUnitOfWorkMock();
            mockUnitOfWork.SetupGet(x => x.Tournaments).Returns(new MockTournamentRepository());
            mockUnitOfWork.SetupGet(x => x.Games).Returns(new MockGamesRepository());
            var unitOfWork = mockUnitOfWork.Object;

            var gameServiceMock = new Mock<IGameService>();
            var service = new TournamentService(unitOfWork, gameServiceMock.Object, TestUtils.MockMapTemplateProvider());

            var tournament = new Tournament("T", 2, 0, 1, 1, DateTime.UtcNow, DateTime.UtcNow, new GameOptions { NumberOfPlayersPerTeam = 1 });

            var user1 = TestUtils.CreateUser("1");
            var user2 = TestUtils.CreateUser("2");

            var teamA = new TournamentTeam(tournament);
            teamA.AddUser(user1);

            var teamB = new TournamentTeam(tournament);
            teamB.AddUser(user2);

            var pairing = new TournamentPairing(tournament, 1, 1, teamA, teamB, 1);
            pairing.State = PairingState.Active;
            tournament.Pairings = new[] { pairing };

            tournament.Teams.Add(teamA);
            tournament.Teams.Add(teamB);

            var game = new Game(null, Enums.GameType.Tournament, "T", "WorldDeluxe", new GameOptions());

            game.State = Enums.GameState.Ended;

            var team1 = new Team(game);
            team1.Players.Add(new Player(user1, team1)
            {
                Outcome = Enums.PlayerOutcome.Won
            });
            game.Teams.Add(team1);

            var team2 = new Team(game);
            team2.Players.Add(new Player(user2, team2)
            {
                Outcome = Enums.PlayerOutcome.Defeated
            });
            game.Teams.Add(team2);

            pairing.Games = new[] { game };

            // Act
            service.SynchronizeGamesToPairings(tournament);

            // Assert
            Assert.IsTrue(tournament.Pairings.First().CanWinnerBeDetermined);
            Assert.AreEqual(PairingState.Done, pairing.State);
            Assert.AreEqual(TournamentTeamState.InActive, teamB.State);
            Assert.AreEqual(TournamentTeamState.Active, teamA.State);
        }
Esempio n. 10
0
 public static IEnumerable<Team> GetEnemyTeams(Game game, Player player)
 {
     return game.Teams.Where(x => !x.Players.Contains(player));
 }
Esempio n. 11
0
        public static IEnumerable<Country> GetEnemyCountries(Game game, Player player)
        {
            var enemyTeams = GetEnemyTeams(game, player);

            return enemyTeams.SelectMany(x => x.Players).SelectMany(x => x.Countries);
        }
Esempio n. 12
0
 public static Country GetCountryWithFriendlyConnection(Game game, Player player, MapTemplate mapTemplate)
 {
     return player.Countries.First(
             c => player.Countries.Any(c2 => mapTemplate.AreConnected(c.CountryIdentifier, c2.CountryIdentifier)));
 }
Esempio n. 13
0
 public static Country GetConnectedFriendlyCountry(Game game, Player player, Country origin, MapTemplate mapTemplate)
 {
     return game.Teams.Where(x => x.Players.Contains(player))
             .SelectMany(t => t.Players)
             .SelectMany(p => p.Countries).First(c => mapTemplate.AreConnected(origin.CountryIdentifier, c.CountryIdentifier));
 }
Esempio n. 14
0
 public static Country GetConnectedEnemyCountry(Game game, Player player, Country origin, MapTemplate mapTemplate)
 {
     return GetEnemyTeams(game, player)
             .SelectMany(t => t.Players)
             .SelectMany(p => p.Countries).First(c => mapTemplate.AreConnected(origin.CountryIdentifier, c.CountryIdentifier));
 }