예제 #1
0
    void CheckWords()
    {
        // We cache words to prevent unneccessary lookups.
        if (m_WordCache == WordChecker.GetWord(m_PlayerCached.selectedTiles))
        {
            return;
        }

        m_WordCache = WordChecker.GetWord(m_PlayerCached.selectedTiles);

        // Clear any old results.
        m_ViewModel.player.orderedResult.hasValue = false;
        m_ViewModel.player.orderedResult.hasValue = false;

        // If any word check threads are running, abort them here, to prevent any race conditions.
        if (WordChecker.taskCount > 0)
        {
            WordChecker.AbortAllTasks();
        }

        // Two word checks are performed - one is an ordered word check, and one checks word permutations.
        // Different callbacks are used for each one.
        // The SetResuable method lets the task object get used again and reduces garbage allocation.
        WordChecker.CheckWordAsync(m_PlayerCached.selectedTiles, OnCheckWordOrdered).SetReusable();
        WordChecker.CheckWordAsync(m_PlayerCached.selectedTiles, OnCheckWordPermute, false).SetReusable();
    }
예제 #2
0
    void OnCheckWordPermute(WordGameResult result)
    {
        // We only assign this result if it still matches the player's current selection.
        if (result.input == WordChecker.GetWord(m_PlayerCached.selectedTiles))
        {
            var uiResult = m_ViewModel.player.permutationResult;
            uiResult.hasValue = result.hasValue;
            uiResult.isValid  = result.isValid;
            uiResult.input    = result.input;
            uiResult.score    = result.score;
            uiResult.allWords = result.allWords;

            // Verify if we can submit our word
            VerifyWordResults();
        }
    }