public async Task CreatePendingGame() { if (!(await CanPayCostOfEntry(Context.User.Id))) { await ReplyAsync(ErrorView.NotEnoughFunds()); } else if (PendingGameService.PendingGames.Any()) { await ReplyAsync(ErrorView.MultipleGames()); } else { PendingGame game = new PendingGame(Context.User); PendingGameService.PendingGames.Add(game); await ReplyAsync(InfoView.LobbyCreated(game.Id)); } }
public async Task JoinPendingGame() { if (!(await CanPayCostOfEntry(Context.User.Id))) { await ReplyAsync(ErrorView.NotEnoughFunds()); } else if (PendingGameService.PendingGames.Count == 0) { await ReplyAsync(ErrorView.NotFound()); } else if (PendingGameService.PendingGames.Any(g => g.Users.Any(u => u.Id == Context.User.Id))) { await ReplyAsync(ErrorView.AlreadyInLobby()); } else { PendingGame game = PendingGameService.PendingGames.FirstOrDefault(); if (game.Active) { await ReplyAsync(ErrorView.InProgress()); } else { game.Users.Add(Context.User); if (game.Users.Count == GameConfiguration.NumberOfPlayers) { game.Active = true; await ReplyAsync(InfoView.GameStarting()); await _game.InitialiseGame(Context, game); } else { await ReplyAsync(InfoView.LobbyStatus(game.Users.Count)); } } } }