예제 #1
0
    public void MakeGuess(string word)
    {
        if (gameState == Game2State.Demand || gameState == Game2State.Negate)
        {
            SetBubbles(word);

            gameState = Game2State.Phrase;

            phraseTimer = 0f;
            newState    = true;
        }
    }
예제 #2
0
    void AIGuess(int i)
    {
        if ((gameState == Game2State.Demand || gameState == Game2State.Negate) && canGuess)
        {
            recognizedNewWord = false;

            wordRecognized = phrase;
            ActivateGameObject(phraseText.gameObject, true);
            SetBubbles(i + 1);

            gameState       = Game2State.Phrase;
            phraseText.text = wordRecognized;
            phraseTimer     = 0f;
            newState        = true;
            personGuessing  = players[i];
        }
    }
예제 #3
0
    private void Update()
    {
        if (gameRunning)
        {
            float t = Time.time - startTime;
            if (voiceActive == true)
            {
                //Checking if 5 seconds has passed since clicking the red button
                if (t >= 5f)
                {
                    showAnswerTextbox();
                    hideMicIcon();
                    keywordRecognizer.Stop();
                    voiceActive = false;
                }
            }


            if (recognizedNewWord)
            {
                recognizedNewWord = false;

                if ((gameState == Game2State.Demand || gameState == Game2State.Negate))
                {
                    ActivateGameObject(phraseText.gameObject, true);
                    SetBubbles(1);

                    gameState       = Game2State.Phrase;
                    phraseText.text = wordRecognized;
                    phraseTimer     = 0f;
                    newState        = true;
                }
            }


            if (gameRunning)
            {
                //check if voice input has been activated i.e. red button is clicked.
                if (redButtonIsPushed == false)
                {
                    redButton.transform.GetComponent <RectTransform>().rect.Set(value1, value1, value1, value1);
                    if ((gameState == Game2State.Demand || gameState == Game2State.Negate))
                    {
                        if (Time.frameCount % 60 == 0)
                        {
                            for (int i = 1; i < 3; i++)
                            {
                                if (UnityEngine.Random.value <= 0.155)
                                {
                                    SetBubbles(i + 1);

                                    gameState = Game2State.Phrase;

                                    phraseTimer = 0f;
                                    newState    = true;
                                }
                            }
                        }
                    }
                }


                if (timer > 0f)
                {
                    timer         -= Time.deltaTime;
                    timerText.text = Mathf.CeilToInt(timer).ToString();
                }
                else
                {
                    if (!gameOver)
                    {
                        gameOver = true;
                        EndGame();
                    }
                }

                #region DEMAND
                if (gameState == Game2State.Demand)
                {
                    if (newState)
                    {
                        phraseState     = Game2State.Demand;
                        iconImage.color = new Color(1f, 1f, 1f, 0f);
                        iconImageAlpha  = 0f;
                        iconImage.GetComponent <ActionIcon>().Init(listOfActions[UnityEngine.Random.Range(0, listOfActions.Count)]);
                        phrase   = iconImage.GetComponent <ActionIcon>().action.commandSentence;
                        newState = false;

                        speechBubble.gameObject.SetActive(false);
                    }

                    if (iconImage.color.a != 1f)
                    {
                        iconImageAlpha += Time.deltaTime / iconFadeSpeed;
                        iconImage.color = new Color(1f, 1f, 1f, iconImageAlpha);
                    }
                }
                #endregion
                #region PHRASE
                else if (gameState == Game2State.Phrase)
                {
                    if (newState)
                    {
                        phraseTimer = 0f;
                        phraseTime  = 1.5f;
                        newState    = false;
                    }

                    if (phraseTimer <= phraseTime)
                    {
                        phraseTimer += Time.deltaTime;
                    }
                    else
                    {
                        if (wordRecognized == phrase && canGuess)
                        {
                            newState  = true;
                            gameState = Game2State.Correct;
                        }
                        else
                        {
                            //newState = true;
                            gameState = phraseState;
                            SetBubbles(0);
                        }
                    }
                }
                #endregion
                #region CORRECT
                else if (gameState == Game2State.Correct)
                {
                    if (newState)
                    {
                        newState = false;

                        print("correct!");
                        PlayRewardSound();
                        phraseTimer = 0f;
                        phraseTime  = 1f;
                        FullAlpha();
                        personGuessing.UpdateScore(10);
                        var addPoints = Instantiate(addPointsPrefab, personGuessing.scoreText.transform.position + Vector3.up * 0.5f, Quaternion.identity);
                        addPoints.color = personGuessing.character.color;
                        if (phraseState == Game2State.Negate)
                        {
                            ActivateGameObject(noSign, false);
                            iconImage.GetComponent <ActionAnimate>().animate = false;
                        }
                    }

                    if (phraseTimer <= phraseTime)
                    {
                        phraseTimer += Time.deltaTime;
                    }

                    else
                    {
                        phraseTimer = 0f;

                        SetBubbles(0);

                        newState  = true;
                        gameState = phraseState == Game2State.Demand ? Game2State.Negate : Game2State.Demand;
                        iconImage.GetComponent <ActionAnimate>().animate = phraseState == Game2State.Demand ? true : false;
                    }
                }
                #endregion
                #region NEGATE
                else if (gameState == Game2State.Negate)
                {
                    if (newState)
                    {
                        phraseState = Game2State.Negate;
                        phrase      = iconImage.GetComponent <ActionIcon>().action.negateSentence;
                        newState    = false;
                        canGuess    = false;
                    }

                    if (phraseTimer <= phraseTime)
                    {
                        phraseTimer += Time.deltaTime;
                    }
                    else
                    {
                        ActivateGameObject(noSign, true);
                        canGuess = true;
                    }
                }
                #endregion


                if (Input.GetKeyDown(KeyCode.Z))
                {
                    MakeGuess(1);
                }
                if (Input.GetKeyDown(KeyCode.X))
                {
                    MakeGuess(2);
                }
                if (Input.GetKeyDown(KeyCode.C))
                {
                    MakeGuess(3);
                }


                if (Input.GetKeyDown(KeyCode.V))
                {
                    AIGuess(1);
                }


                if (Input.GetKeyDown(KeyCode.P))
                {
                    timer = 2f;
                }
            }
            else
            {
                redButton.transform.GetComponent <RectTransform>().rect.Set(value2, value2, value2, value2);
            }
        }
    }
예제 #4
0
    private void Start()
    {
        voiceActive = false;

        //------------------- Start of Voice Recognition Section --------------------

        //Adding to dictionary
        //Do Commands
        actions.Add("brush", Brush);
        actions.Add("dry", Dry);
        actions.Add("tie", Tie);
        actions.Add("wash", Wash);
        actions.Add("wear", Wear);
        //Don't commands
        actions.Add("don't brush", DontBrush);
        actions.Add("don't dry", DontDry);
        actions.Add("don't tie", DontTie);
        actions.Add("don't wash", DontWash);
        actions.Add("don't wear", DontWear);
        //Do not commands
        actions.Add("do not brush", DoNotBrush);
        actions.Add("do not dry", DoNotDry);
        actions.Add("do not tie", DoNotTie);
        actions.Add("do not wash", DoNotWash);
        actions.Add("do not wear", DoNotWear);

        keywordRecognizer = new KeywordRecognizer(actions.Keys.ToArray());
        keywordRecognizer.OnPhraseRecognized += RecognizedSpeech;

        //------------------- End of Voice Recognition Section ----------------------

        if (gameStart == false)
        {
            gameStart = true;
            InputFieldAnswer.transform.localScale  = new Vector3(0, 0, 0);
            confirmTextButton.transform.localScale = new Vector3(0, 0, 0);
            micIcon.transform.localScale           = new Vector3(0, 0, 0);
        }
        redButton.GetComponent <Button>();
        redButtonIsPushed = false;


        if (MenuSelection.instance)
        {
            MenuSelection.instance.FadeIn(1f);
        }


        if (IntroController.instance)
        {
            listOfCharacters = IntroController.instance.charactersInGame;
        }

        if (AudioManager.instance)
        {
            AudioManager.instance.musicSource.clip = AudioManager.instance.game1;
            AudioManager.instance.musicSource.Play();
        }

        for (int i = 0; i < 3; i++)
        {
            print("here");
            players[i].character = listOfCharacters[i];
            players[i].ChangeSprite();
        }


        iconImageAlpha  = 0f;
        iconImage.color = new Color(1f, 1f, 1f, 0f);
        ActivateGameObject(noSign, false);

        gameState = Game2State.Demand;
        newState  = true;
        canGuess  = true;

        i = 1;

        speechBubble.gameObject.SetActive(false);

        ActivateGameObject(startText.gameObject, true);

        InitGame();
    }