Ejemplo n.º 1
0
    void SubmitClue(PlayerInfo player, string content)
    {
        if (m_clues.Any(c => c.player.Id == player.Id))
        {
            return; // already submitted
        }

        string        norm   = content.ToLower();
        List <string> tokens = new List <string>(norm.Split(' '));

        tokens.RemoveAll(s => IGNORE_WORDS.Contains(s));

        List <string> usedTokens     = m_submittedClueWords.Intersect(tokens).ToList();
        bool          alreadyEntered = usedTokens.Count > 0;

        StringBuilder sb = new StringBuilder();

        if (alreadyEntered)
        {
            Debug.Log("Already entered: " + content);

            foreach (var s in usedTokens)
            {
                sb.Append(s);
                sb.Append(", ");
            }
            sb.Length -= 2;
            Main.RaiseEvent(SpewEventCode.InvalidClue, sb.ToString(), player.Id);
            return;
        }

        MatchCollection matches = m_currentTarget.ClueMatches(content);

        if (matches.Count == 0)
        {
            Clue clue = new Clue();
            clue.player = player;
            clue.clue   = content;
            m_clues.Insert(0, clue);

            m_submittedClueWords.AddRange(tokens);

            foreach (string s in m_submittedClueWords)
            {
                sb.Append(s);
                sb.Append(", ");
            }

            Main.RaiseEvent(SpewEventCode.ValidClue, string.Empty, player.Id);
            Main.RaiseEvent(SpewEventCode.UpdateWords, sb.ToString());

            if (m_state == State.Clues && m_clues.Count == m_playerList.Count - 1)
            {
                StopTimer();
                SetState(State.Guess);
            }
        }
        else
        {
            foreach (var match in matches.Cast <Match>())
            {
                sb.Append(match.Value);
                sb.Append(", ");
            }
            sb.Length -= 2;

            Debug.Log("Sorry, matches: " + sb.ToString());
            Main.RaiseEvent(SpewEventCode.InvalidClue, sb.ToString(), player.Id);
        }
    }