Ejemplo n.º 1
0
        public async Task <ChessMatch> AcceptChallenge(ulong channel, IUser player)
        {
            if (await PlayerIsInGame(channel, player))
            {
                throw new ChessException($"{player.Mention} is currently in a game.");
            }

            var challenge = _challenges.Where(x => x.Channel == channel && x.Challenged == player).OrderBy(x => x.ChallengeDate).FirstOrDefault();

            if (challenge == null)
            {
                throw new ChessException($"No challenge exists for you to accept.");
            }

            if (await PlayerIsInGame(channel, challenge.Challenger))
            {
                throw new ChessException($"{challenge.Challenger.Mention} is currently in a game.");
            }

            var chessGame  = new ChessGame();
            var chessMatch = new ChessMatch {
                Channel = channel, Game = chessGame, Challenger = challenge.Challenger, Challenged = challenge.Challenged
            };

            _challenges.Remove(challenge);
            _chessMatches.Add(chessMatch);

            return(await Task.FromResult <ChessMatch>(chessMatch));
        }
Ejemplo n.º 2
0
        private async void RemoveUndoRequest(ChessMatch match, Action <ChessMatch> onTimeout)
        {
            await Task.Delay(_confirmationsTimeout);

            if (match.UndoRequest != null)
            {
                match.UndoRequest = null;
                onTimeout(match);
            }
        }