public Tournament(
            string name, 
            int numberOfTeams, 
            int numberOfGroupGames, 
            int numberOfKnockoutGames,
            int numberOfFinalGames,
            DateTime startOfRegistration,
            DateTime startOfTournament,
            GameOptions options)
            : this()
        {
            Require.NotNullOrEmpty(name, nameof(name));
            Require.NotNull(options, nameof(options));

            this.Name = name;

            if (numberOfTeams <= 0 || Math.Pow(2, Math.Log(numberOfTeams, 2)) != numberOfTeams)
            {
                throw new DomainException(
                    ErrorCode.TournamentInvalidOption, "Number of teams has to be a power of two and greater than zero");
            }

            this.NumberOfTeams = numberOfTeams;

            if (numberOfGroupGames < 0 || (numberOfGroupGames > 0 && numberOfGroupGames % 2 == 0))
            {
                throw new DomainException(ErrorCode.TournamentInvalidOption, "Number of group games has to be odd and 0 or more");
            }
            this.NumberOfGroupGames = numberOfGroupGames;

            if (this.NumberOfGroupGames > 0)
            {
                if (numberOfTeams < 8)
                {
                    throw new DomainException(ErrorCode.TournamentInvalidOption, "At least 8 teams required for group mode");
                }
            }

            if (numberOfKnockoutGames <= 0 || numberOfKnockoutGames % 2 == 0)
            {
                throw new DomainException(ErrorCode.TournamentInvalidOption, "Number of knockout games has to be odd and greater than zero");
            }
            this.NumberOfKnockoutGames = numberOfKnockoutGames;

            if (numberOfFinalGames <= 0 || numberOfFinalGames % 2 == 0)
            {
                throw new DomainException(ErrorCode.TournamentInvalidOption, "Number of final games has to be odd and greater than zero");
            }
            this.NumberOfFinalGames = numberOfFinalGames;

            this.OptionsId = options.Id;
            this.Options = options;

            this.StartOfRegistration = startOfRegistration;
            this.StartOfTournament = startOfTournament;
        }
示例#2
0
        public Game(
            User user,
            GameType type,
            string name,
            string mapTemplateName,
            GameOptions options)
            : this()
        {
            this.Type = type;
            this.Name = name;

            this.CreatedBy = user;
            this.CreatedAt = DateTime.UtcNow;

            this.MapTemplateName = mapTemplateName;

            this.Options = options;

            this.State = GameState.Open;
            this.PlayState = PlayState.None;
        }
        public Game Create(
            GameType type,
            User user,
            string name,
            string mapTemplate,
            GameOptions options)
        {
            // Check if user is allowed to create games
            if (!user.CanCreateGame)
            {
                throw new DomainException(ErrorCode.NotEnoughSlots, "User does not have enough available slots to create game");
            }

            // Check if name is not already taken
            if (this.gameRepository.FindByName(name) != null)
            {
                throw new DomainException(ErrorCode.NameAlreadyTaken, "Name for this game is already taken");
            }

            // Create game
            return new Game(user, type, name, mapTemplate, options);
        }
 public void Initialize()
 {
     this.options = new GameOptions()
     {
         Id = 42
     };
 }