public static Game[] CreateGame(WaitingRoom r) { Guid guid = Utilities.GenerateGuid(); int gameCountWithMin; int size = GetSize(r.Clients.Count, out gameCountWithMin); Game[] game = new Game[size]; r.Clients.Shuffle(); Queue <GameClient> queue = r.Clients.ToQueue(); int count = 0; while (count < game.Length) { game[count] = new Game(r); game[count].Guid = guid; int maxPlayerCount = (gameCountWithMin > 0) ? 3 : 4; int currentPlayerCount = 0; while (queue.Count() > 0 && currentPlayerCount != maxPlayerCount) { var client = queue.Dequeue(); game[count].PlayerManager.Add(client); client.Character.Status.Update(game[count]); currentPlayerCount += 1; } gameCountWithMin -= 1; game[count].PlayerManager.Setup(); game[count].SetupBoard(); count++; } return(game); }
public Game(WaitingRoom r) { this.Parent = r; this.TotalQuestion = (byte)r.Quiz.Questions.Count(); this.Questions = new Queue <Question>(); this.RewardManager = new RewardManager(); this.PlayerManager = new PlayerManager(); this.TurnTimer = new Timer(EndCurrentPlayerTurn, this, Timeout.Infinite, Timeout.Infinite); foreach (var question in r.Quiz.Questions) { this.Questions.Enqueue(question); } this.QuizId = r.Quiz.Id; this.EventDespatcher = new DespawnDespatcher(this); }