示例#1
0
    // Update is called once per frame
    void Update()
    {
        if (Input.inputString != "")
        {
            if (LettersAvailable(Input.inputString.Trim()))
            {
                currentWord += Input.inputString.Trim().ToUpper();
                UpdateLettersFreqs(Input.inputString.Trim());

                if (onLetterInputCallback != null)
                {
                    onLetterInputCallback.Invoke(currentWord);
                }
            }
        }



        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (IsCurrentWordCorrect())
            {
                int position = GetPositionOfCorrectWord();
                if (onWordCorrectCallback != null)
                {
                    wordScore = currentWord.Length * wordWeight;// + wordStreak * wordStreakWeight;
                    onWordCorrectCallback.Invoke(wordScore, position);
                }
            }
            else
            {
                if (onWordCorrectCallback != null)
                {
                    wordScore = currentWord.Length * wordWeight;// + wordStreak * wordStreakWeight;
                    onWordCorrectCallback.Invoke(-wordScore, -1);
                }
            }

            currentWord = "";

            if (onLetterInputCallback != null)
            {
                onLetterInputCallback.Invoke(currentWord);
            }
        }
    }
示例#2
0
    void Update()
    {
#if MOBILE_INPUT
        if (isInEvaluationStage)
        {
            if (isWatchingWord && !isGameOver)
            {
                watchingWordCountdown -= Time.deltaTime;

                if (watchingWordCountdown < 0f)
                {
                    isWatchingWord        = false;
                    isDrawingWord         = true;
                    watchingWordCountdown = limitTimeWatchingWord;

                    if (onWatchingCountdownFinishedCallback != null)
                    {
                        onWatchingCountdownFinishedCallback.Invoke();
                    }
                }
            }

            if (isDrawingWord && !isGameOver && drawingWordCountdown >= 0f)
            {
                drawingWordCountdown -= Time.deltaTime;
                //The letter input is coming from touch input manager

                if (_inputString != "")
                {
                    if (AreLettersAvailable(_inputString))
                    {
                        currentWord += _inputString;
                        UpdateLettersFreqs(_inputString);

                        if (onLetterInputCallback != null)
                        {
                            onLetterInputCallback.Invoke(currentWord);
                        }
                    }

                    if (WordCorrect)// IsCurrentWordCorrect())
                    {
                        int position = GetPositionOfCorrectWord();
                        if (onWordChecked != null)
                        {
                            wordScore = currentWord.Length * wordWeight;// + wordStreak * wordStreakWeight;
                            onWordChecked.Invoke(wordScore, position);
                        }

                        if (!IsGameOver())
                        {
                            SetNewTargetWord();
                        }

                        FinishEvaluationStage();
                    }
                    _inputString = "";
                }

                if (drawingWordCountdown < 0f)
                {
                    if (onWordChecked != null)
                    {
                        wordScore = currentWord.Length * wordWeight;// + wordStreak * wordStreakWeight;
                        onWordChecked.Invoke(-wordScore, -1);
                    }

                    FinishEvaluationStage();
                }
            }

            if (_inputString != "" && !isGameOver)
            {
                DiscardImpossibleWords();
            }
        }
#else
        if (isInEvaluationStage)
        {
            _inputString = Input.inputString;
            if (_inputString != "" && !isGameOver)
            {
                if (AreLettersAvailable(_inputString.Trim()))
                {
                    currentWord += _inputString.Trim().ToUpper();
                    UpdateLettersFreqs(_inputString.Trim());

                    if (onLetterInputCallback != null)
                    {
                        onLetterInputCallback.Invoke(currentWord);
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Return) && !isGameOver)
            {
                if (IsCurrentWordCorrect())
                {
                    int position = GetPositionOfCorrectWord();
                    if (onWordChecked != null)
                    {
                        wordScore = currentWord.Length * wordWeight;// + wordStreak * wordStreakWeight;
                        onWordChecked.Invoke(wordScore, position);
                    }

                    if (!IsGameOver())
                    {
                        SetNewTargetWord();
                    }
                }
                else
                {
                    if (onWordChecked != null)
                    {
                        wordScore = currentWord.Length * wordWeight;// + wordStreak * wordStreakWeight;
                        onWordChecked.Invoke(-wordScore, -1);
                    }
                }

                currentWord = "";

                if (onLetterInputCallback != null)
                {
                    onLetterInputCallback.Invoke(currentWord);
                }

                FinishEvaluationStage();
            }

            if (_inputString != "" && !isGameOver)
            {
                DiscardImpossibleWords();
            }
        }
#endif
    }