Beispiel #1
0
        private async Task BestOfOutOfRound(bool didFindGuess)
        {
            List <string> bestName  = new List <string>();
            int           bestScore = 0;

            foreach (var name in _lobby.GetFullNames())
            {
                int currScore = _bestOfScore.ContainsKey(name) ? _bestOfScore[name] : 0;
                if (currScore == bestScore)
                {
                    bestName.Add(name);
                }
                else if (currScore > bestScore)
                {
                    bestName = new List <string>();
                    bestName.Add(name);
                    bestScore = currScore;
                }
            }
            string finalStr = "";

            if (didFindGuess)
            {
                finalStr += Sentences.GuessGood(_guild) + Environment.NewLine;
            }
            finalStr += Sentences.CurrentScore(_guild) + Environment.NewLine + GetBestOfScore() + Environment.NewLine + Environment.NewLine + Sentences.ReversiGameEnded(_guild) + Environment.NewLine;
            if (bestName.Count == _lobby.GetFullNames().Count)
            {
                await PostText(finalStr + Sentences.Draw(_guild));
            }
            else
            {
                await PostText(finalStr + Sentences.WonMulti(_guild, string.Join(", ", bestName)));
            }
            _gameState = GameState.Lost;
        }
Beispiel #2
0
        public async Task CheckCorrectAsync(IUser user, string userAnswer, SocketUserMessage msg)
        {
            if (_gameState != GameState.Running || userAnswer.StartsWith("//") || userAnswer.StartsWith("#"))
            {
                return;
            }
            _checkingAnswer = true;
            if (HaveMultiplayerLobby())          // If is in multiplayer
            {
                if (!_lobby.IsPlayerIn(user.Id)) // Player isn't in the multiplayer lobby
                {
                    return;
                }
                // Check if it's the player's turn (elimination mode only)
                else if (_multiType == APreload.MultiplayerType.Elimination && !_lobby.IsMyTurn(user.Id))
                {
                    await msg.AddReactionAsync(new Emoji("🚫"));

                    _checkingAnswer = false;
                    return;
                }
                // Check if the player is out of tries
                else if (_multiType == APreload.MultiplayerType.BestOf && _bestOfTries.ContainsKey(user.ToString()) && _bestOfTries[user.ToString()] == nbMaxTry - 1)
                {
                    await msg.AddReactionAsync(new Emoji("🚫"));

                    _checkingAnswer = false;
                    return;
                }
            }
            if (_postImage) // Image is being posted
            {
                await msg.AddReactionAsync(new Emoji("❌"));

                _checkingAnswer = false;
                return;
            }
            string error;

            try
            {
                error = await GetCheckCorrectAsync(userAnswer);
            }
            catch (Exception e)
            {
                await _chan.SendMessageAsync("", false, new EmbedBuilder()
                {
                    Color       = Color.Red,
                    Title       = e.GetType().ToString(),
                    Description = Sentences.ExceptionGameCheck(_guild),
                    Footer      = new EmbedFooterBuilder()
                    {
                        Text = e.Message
                    }
                }.Build());

                await Program.p.LogError(new LogMessage(LogSeverity.Error, e.Source, e.Message, e));
                await LooseAsync(null);

                return;
            }
            if (error != null)
            {
                if (error.Length < 5)
                {
                    await msg.AddReactionAsync(new Emoji(error));

                    error = "";
                }
                if (HaveMultiplayerLobby() && _multiType == APreload.MultiplayerType.BestOf)
                {
                    if (_bestOfTries.ContainsKey(user.ToString()))
                    {
                        _bestOfTries[user.ToString()]++;
                    }
                    else
                    {
                        _bestOfTries.Add(user.ToString(), 1);
                    }
                    error += Environment.NewLine + Sentences.TurnsRemaining(_guild, nbMaxTry - _bestOfTries[user.ToString()], user.ToString());
                }
                if (error != "")
                {
                    await PostText(error);
                }
                _checkingAnswer = false;
                return;
            }
            if (!_contributors.Contains(user.Id))
            {
                _contributors.Add(user.Id);
            }
            string finalStr = AnnounceNextTurnInternal();

            if (CongratulateOnGuess())
            {
                finalStr += Sentences.GuessGood(_guild);
            }
            if (HaveMultiplayerLobby())
            {
                if (_multiType == APreload.MultiplayerType.Elimination)
                {
                    await NextTurn();

                    if (finalStr != "")
                    {
                        finalStr += Environment.NewLine;
                    }
                    finalStr += Sentences.AnnounceTurn(_guild, _lobby.GetTurnName());
                }
                else if (_multiType == APreload.MultiplayerType.BestOf)
                {
                    if (_bestOfScore.ContainsKey(user.ToString()))
                    {
                        _bestOfScore[user.ToString()]++;
                    }
                    else
                    {
                        _bestOfScore.Add(user.ToString(), 1);
                    }
                    _bestOfRemainingRounds--;
                    if (_bestOfRemainingRounds == 0)
                    {
                        await BestOfOutOfRound(true);

                        return;
                    }
                    _bestOfTries = new Dictionary <string, int>();
                    finalStr    += Environment.NewLine + Sentences.CurrentScore(_guild) + Environment.NewLine;
                    finalStr    += GetBestOfScore();
                }
            }
            if (_gameState != GameState.Running || _isFound)
            {
                return;
            }
            _isFound = true;
            if (!string.IsNullOrWhiteSpace(finalStr))
            {
                await PostText(finalStr);
            }
            _score++;
            await PostAsync();

            _checkingAnswer = false;
        }