Esempio n. 1
0
        public void PlayTurn()
        {
            this.ownTeam = game.CurrentPlayer.Team;
            this.ownPlayer = game.CurrentPlayer;;

            if (this.Place())
            {
                // Not first turn
                this.Attack();
                this.Move();
                this.EndTurn();
            }
        }
Esempio n. 2
0
        public Player(User user, Team team)
            : this()
        {
            this.User = user;
            this.UserId = user.Id;

            this.Team = team;
            this.TeamId = team.Id;

            this.Bonus = 0;
            this.State = PlayerState.Active;
            this.Outcome = PlayerOutcome.None;

            this.PlayOrder = team.Game.Teams.SelectMany(x => x.Players).Count();

            this.IsHidden = false;
        }
        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. 4
0
        /// <summary>
        /// Adds a new team
        /// </summary>
        /// <returns>New team</returns>
        public Team AddTeam()
        {
            if (this.Teams.Count() >= this.Options.NumberOfTeams)
            {
                throw new DomainException(ErrorCode.TooManyTeams, "Cannot create team, there are too many teams already");
            }

            var team = new Team(this);

            this.Teams.Add(team);

            return team;
        }