Exemplo n.º 1
0
        private IEnumerator PlayGame()
        {
            while (!partidaCompleta)
            {
                sco.StartSampling();

                if (ppasso)
                {
                    CleanScene();

                    while (!scp.IsConnected && !scm.IsConnected && !scc.IsConnected)
                    {
                        passo = -1;
                        TextPanel.SetActive(true);
                        displayHowTo.text = "Nenhum dispositivo de controle conectado! Conecte e volte ao menu principal.";
                        yield return(null);
                    }

                    // Se o PITACO estiver conectado
                    if (scp.IsConnected)
                    {
                        switch (passo)
                        {
                        case 1:
                            displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir dentro do tempo.";
                            break;

                        case 2:

                            scp.StartSampling();
                            scp.Recalibrate();

                            displayHowTo.text = "";

                            TextPanel.SetActive(false);

                            while (player.sensorValuePitaco <= Pacient.Loaded.PitacoThreshold && jogou)
                            {
                                yield return(null);
                            }

                            StopCountdown();
                            paraTempo = true;

                            //saiu do 0
                            while (player.sensorValuePitaco > Pacient.Loaded.PitacoThreshold && jogou)
                            {
                                FlowAction(player.picoExpiratorio, 1);
                                yield return(null);
                            }

                            scp.StopSampling();

                            //voltou pro 0
                            finalScoreMenu.pikeString[0] = player.picoExpiratorio.ToString();
                            TextPanel.SetActive(true);

                            if (jogou)
                            {
                                displayHowTo.text = "Parabéns!\nPressione [Enter] para ir para a proxima rodada.";
                                SoundManager.Instance.PlaySound("Success");
                            }

                            break;

                        case 3:
                            FindObjectOfType <MinigameLogger>().WriteMinigameRound(1, finalScore[0], player.picoExpiratorio);
                            RestauraVariaveis();
                            displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir";
                            break;

                        case 4:

                            scp.StartSampling();
                            scp.Recalibrate();

                            displayHowTo.text = "";
                            TextPanel.SetActive(false);
                            while (player.sensorValuePitaco <= Pacient.Loaded.PitacoThreshold && jogou)
                            {
                                yield return(null);
                            }

                            StopCountdown();
                            paraTempo = true;

                            //saiu do 0
                            while (player.sensorValuePitaco > Pacient.Loaded.PitacoThreshold && jogou)
                            {
                                FlowAction(player.picoExpiratorio, 2);
                                yield return(null);
                            }

                            scp.StopSampling();

                            //voltou pro 0
                            finalScoreMenu.pikeString[1] = player.picoExpiratorio.ToString();
                            TextPanel.SetActive(true);

                            if (jogou)
                            {
                                displayHowTo.text = "Parabéns!\nPressione [Enter] para ir para a proxima rodada.";
                                SoundManager.Instance.PlaySound("Success");
                            }

                            break;

                        case 5:
                            FindObjectOfType <MinigameLogger>().WriteMinigameRound(2, finalScore[1], player.picoExpiratorio);
                            RestauraVariaveis();
                            displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir";
                            break;

                        case 6:

                            scp.StartSampling();
                            scp.Recalibrate();

                            displayHowTo.text = "";
                            TextPanel.SetActive(false);
                            while (player.sensorValuePitaco <= Pacient.Loaded.PitacoThreshold && jogou)
                            {
                                yield return(null);
                            }

                            StopCountdown();
                            paraTempo = true;

                            //saiu do 0
                            while (player.sensorValuePitaco > Pacient.Loaded.PitacoThreshold && jogou)
                            {
                                FlowAction(player.picoExpiratorio, 3);
                                yield return(null);
                            }

                            scp.StopSampling();

                            //voltou pro 0
                            finalScoreMenu.pikeString[2] = player.picoExpiratorio.ToString();
                            TextPanel.SetActive(true);

                            if (jogou)
                            {
                                displayHowTo.text = "Parabéns!\nPressione [Enter] para ver a sua pontuação.";
                                SoundManager.Instance.PlaySound("Success");
                            }

                            player.picoExpiratorio = 0;
                            break;

                        case 7:
                            FindObjectOfType <MinigameLogger>().WriteMinigameRound(3, finalScore[2], player.picoExpiratorio);

                            TextPanel.SetActive(false);
                            finalScoreMenu.DisplayFinalScore(finalScore[0], finalScore[1], finalScore[2]);
                            finalScoreMenu.ToggleScoreMenu();

                            Debug.Log("Saving minigame data...");
                            GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(true);
                            FindObjectOfType <MinigameLogger>().Save(GameDevice.Pitaco, RespiratoryExercise.ExpiratoryPeak, Minigame.CakeGame);
                            GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(false);
                            Debug.Log("Minigame logs saved.");

                            player.picoExpiratorio = 0;

                            partidaCompleta = true;
                            break;
                        }
                        ppasso = false;
                    }

                    #region Other Controllers

                    else
                    {
                        // Se o MANO estiver conectado
                        if (scm.IsConnected)
                        {
                            switch (passo)
                            {
                            case 1:
                                displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir dentro do tempo.";
                                break;

                            case 2:

                                scm.StartSampling();
                                scm.Recalibrate();

                                displayHowTo.text = "";

                                TextPanel.SetActive(false);

                                while (player.sensorValueMano <= Pacient.Loaded.ManoThreshold && jogou)
                                {
                                    yield return(null);
                                }

                                StopCountdown();
                                paraTempo = true;

                                //saiu do 0
                                while (player.sensorValueMano > Pacient.Loaded.ManoThreshold && jogou)
                                {
                                    FlowAction(player.picoExpiratorio, 1);
                                    yield return(null);
                                }

                                scm.StopSampling();

                                //voltou pro 0
                                finalScoreMenu.pikeString[0] = player.picoExpiratorio.ToString();
                                TextPanel.SetActive(true);

                                if (jogou)
                                {
                                    displayHowTo.text = "Parabéns!\nPressione [Enter] para ir para a proxima rodada.";
                                    SoundManager.Instance.PlaySound("Success");
                                }

                                break;

                            case 3:
                                FindObjectOfType <MinigameLogger>().WriteMinigameRound(1, finalScore[0], player.picoExpiratorio);
                                RestauraVariaveis();
                                displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir";
                                break;

                            case 4:

                                scm.StartSampling();
                                scm.Recalibrate();

                                displayHowTo.text = "";
                                TextPanel.SetActive(false);
                                while (player.sensorValueMano <= Pacient.Loaded.ManoThreshold && jogou)
                                {
                                    yield return(null);
                                }

                                StopCountdown();
                                paraTempo = true;

                                //saiu do 0
                                while (player.sensorValueMano > Pacient.Loaded.ManoThreshold && jogou)
                                {
                                    FlowAction(player.picoExpiratorio, 2);
                                    yield return(null);
                                }

                                scm.StopSampling();

                                //voltou pro 0
                                finalScoreMenu.pikeString[1] = player.picoExpiratorio.ToString();
                                TextPanel.SetActive(true);

                                if (jogou)
                                {
                                    displayHowTo.text = "Parabéns!\nPressione [Enter] para ir para a proxima rodada.";
                                    SoundManager.Instance.PlaySound("Success");
                                }

                                break;

                            case 5:
                                FindObjectOfType <MinigameLogger>().WriteMinigameRound(2, finalScore[1], player.picoExpiratorio);
                                RestauraVariaveis();
                                displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir";
                                break;

                            case 6:

                                scm.StartSampling();
                                scm.Recalibrate();

                                displayHowTo.text = "";
                                TextPanel.SetActive(false);
                                while (player.sensorValueMano <= Pacient.Loaded.ManoThreshold && jogou)
                                {
                                    yield return(null);
                                }

                                StopCountdown();
                                paraTempo = true;

                                //saiu do 0
                                while (player.sensorValueMano > Pacient.Loaded.ManoThreshold && jogou)
                                {
                                    FlowAction(player.picoExpiratorio, 3);
                                    yield return(null);
                                }

                                scm.StopSampling();

                                //voltou pro 0
                                finalScoreMenu.pikeString[2] = player.picoExpiratorio.ToString();
                                TextPanel.SetActive(true);

                                if (jogou)
                                {
                                    displayHowTo.text = "Parabéns!\nPressione [Enter] para ver a sua pontuação.";
                                    SoundManager.Instance.PlaySound("Success");
                                }

                                player.picoExpiratorio = 0;
                                break;

                            case 7:
                                FindObjectOfType <MinigameLogger>().WriteMinigameRound(3, finalScore[2], player.picoExpiratorio);

                                TextPanel.SetActive(false);
                                finalScoreMenu.DisplayFinalScore(finalScore[0], finalScore[1], finalScore[2]);
                                finalScoreMenu.ToggleScoreMenu();

                                Debug.Log("Saving minigame data...");
                                GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(true);
                                FindObjectOfType <MinigameLogger>().Save(GameDevice.Mano, RespiratoryExercise.ExpiratoryPeak, Minigame.CakeGame);
                                GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(false);
                                Debug.Log("Minigame logs saved.");

                                player.picoExpiratorio = 0;

                                partidaCompleta = true;
                                break;
                            }
                            ppasso = false;
                        }
                        else
                        {
                            // Se o CINTA estiver conectado
                            if (scc.IsConnected)
                            {
                                switch (passo)
                                {
                                case 1:
                                    displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir dentro do tempo.";
                                    break;

                                case 2:

                                    scc.StartSampling();
                                    scc.Recalibrate();

                                    displayHowTo.text = "";

                                    TextPanel.SetActive(false);

                                    while (player.sensorValueCinta <= Pacient.Loaded.CintaThreshold && jogou)
                                    {
                                        yield return(null);
                                    }

                                    StopCountdown();
                                    paraTempo = true;

                                    //saiu do 0
                                    while (player.sensorValueCinta > Pacient.Loaded.CintaThreshold && jogou)
                                    {
                                        FlowAction(player.picoExpiratorio, 1);
                                        yield return(null);
                                    }

                                    scc.StopSampling();

                                    //voltou pro 0
                                    finalScoreMenu.pikeString[0] = player.picoExpiratorio.ToString();
                                    TextPanel.SetActive(true);

                                    if (jogou)
                                    {
                                        displayHowTo.text = "Parabéns!\nPressione [Enter] para ir para a proxima rodada.";
                                        SoundManager.Instance.PlaySound("Success");
                                    }

                                    break;

                                case 3:
                                    FindObjectOfType <MinigameLogger>().WriteMinigameRound(1, finalScore[0], player.picoExpiratorio);
                                    RestauraVariaveis();
                                    displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir";
                                    break;

                                case 4:

                                    scc.StartSampling();
                                    scc.Recalibrate();

                                    displayHowTo.text = "";
                                    TextPanel.SetActive(false);
                                    while (player.sensorValueCinta <= Pacient.Loaded.CintaThreshold && jogou)
                                    {
                                        yield return(null);
                                    }

                                    StopCountdown();
                                    paraTempo = true;

                                    //saiu do 0
                                    while (player.sensorValueCinta > Pacient.Loaded.CintaThreshold && jogou)
                                    {
                                        FlowAction(player.picoExpiratorio, 2);
                                        yield return(null);
                                    }

                                    scc.StopSampling();

                                    //voltou pro 0
                                    finalScoreMenu.pikeString[1] = player.picoExpiratorio.ToString();
                                    TextPanel.SetActive(true);

                                    if (jogou)
                                    {
                                        displayHowTo.text = "Parabéns!\nPressione [Enter] para ir para a proxima rodada.";
                                        SoundManager.Instance.PlaySound("Success");
                                    }

                                    break;

                                case 5:
                                    FindObjectOfType <MinigameLogger>().WriteMinigameRound(2, finalScore[1], player.picoExpiratorio);
                                    RestauraVariaveis();
                                    displayHowTo.text = "Pressione [Enter] e assopre o mais forte que conseguir";
                                    break;

                                case 6:

                                    scc.StartSampling();
                                    scc.Recalibrate();

                                    displayHowTo.text = "";
                                    TextPanel.SetActive(false);
                                    while (player.sensorValueCinta <= Pacient.Loaded.CintaThreshold && jogou)
                                    {
                                        yield return(null);
                                    }

                                    StopCountdown();
                                    paraTempo = true;

                                    //saiu do 0
                                    while (player.sensorValueCinta > Pacient.Loaded.CintaThreshold && jogou)
                                    {
                                        FlowAction(player.picoExpiratorio, 3);
                                        yield return(null);
                                    }

                                    scc.StopSampling();

                                    //voltou pro 0
                                    finalScoreMenu.pikeString[2] = player.picoExpiratorio.ToString();
                                    TextPanel.SetActive(true);

                                    if (jogou)
                                    {
                                        displayHowTo.text = "Parabéns!\nPressione [Enter] para ver a sua pontuação.";
                                        SoundManager.Instance.PlaySound("Success");
                                    }

                                    player.picoExpiratorio = 0;
                                    break;

                                case 7:
                                    FindObjectOfType <MinigameLogger>().WriteMinigameRound(3, finalScore[2], player.picoExpiratorio);

                                    TextPanel.SetActive(false);
                                    finalScoreMenu.DisplayFinalScore(finalScore[0], finalScore[1], finalScore[2]);
                                    finalScoreMenu.ToggleScoreMenu();

                                    Debug.Log("Saving minigame data...");
                                    GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(true);
                                    FindObjectOfType <MinigameLogger>().Save(GameDevice.Cinta, RespiratoryExercise.ExpiratoryPeak, Minigame.CakeGame);
                                    GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(false);
                                    Debug.Log("Minigame logs saved.");

                                    player.picoExpiratorio = 0;

                                    partidaCompleta = true;
                                    break;
                                }
                                ppasso = false;
                            }
                        }
                    }

                    #endregion
                }
                yield return(null);
            }
            sco.StopSampling();
        }
Exemplo n.º 2
0
        //Incremental states(put them into the correct order)
        private IEnumerator PlayGame()
        {
            while (!finished)
            {
                sco.StartSampling();

                while (!scp.IsConnected && !scm.IsConnected && !scc.IsConnected)
                {
                    state = -1;
                    TextPanel.SetActive(true);
                    displayHowTo.text = "Nenhum dispositivo de controle conectado! Conecte e volte ao menu principal.";
                    yield return(null);
                }

                // Se o PITACO estiver conectado
                if (scp.IsConnected)
                {
                    switch (state)
                    {
                    case 1:     //Introduction
                        displayHowTo.text = "Bem-Vindo ao jogo do copo d'agua![ENTER]";

                        while (playable)
                        {
                            yield return(null);
                        }

                        playable = true;
                        break;

                    case 2:
                    case 4:
                    case 6:     //Pre-flow
                        TextPanel.SetActive(true);
                        displayHowTo.text = "Pressione [Enter] e INSPIRE \n o mais forte que conseguir dentro do tempo.";
                        while (playable)
                        {
                            yield return(null);
                        }
                        CleanRound();
                        playable = true;
                        TextPanel.SetActive(false);
                        break;

                    case 3:
                    case 5:
                    case 7:     //Player's Flow
                        scp.StartSampling();
                        scp.Recalibrate();
                        displayHowTo.text = "";
                        EnablePlayerFlow(true, _roundNumber);
                        _roundNumber++;

                        while (playable)
                        {
                            StartCountdown();
                            yield return(null);
                        }
                        scp.StopSampling();
                        ResetCountDown();
                        playable = true;
                        break;

                    case 8:
                        TextPanel.SetActive(true);
                        displayHowTo.text = "Pressione [Enter] para visualizar sua pontuação.";
                        break;

                    case 9:
                        Debug.Log("Saving minigame data...");
                        GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(true);
                        FindObjectOfType <Core.MinigameLogger>().Save(GameDevice.Pitaco, RespiratoryExercise.InspiratoryPeak, Minigame.WaterGame);
                        GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(false);
                        Debug.Log("Minigame logs saved.");

                        NotPlayable();
                        break;

                    case 10:
                        TextPanel.SetActive(false);
                        ShowFinalScore();
                        break;

                    case 99:
                        TextPanel.SetActive(true);
                        while (playable)
                        {
                            yield return(null);
                        }
                        playable = true;
                        break;
                    }
                }
                else
                {
                    // Se o Mano estiver conectado
                    if (scm.IsConnected)
                    {
                        switch (state)
                        {
                        case 1:     //Introduction
                            displayHowTo.text = "Bem-Vindo ao jogo do copo d'agua![ENTER]";

                            while (playable)
                            {
                                yield return(null);
                            }

                            playable = true;
                            break;

                        case 2:
                        case 4:
                        case 6:     //Pre-flow
                            TextPanel.SetActive(true);
                            displayHowTo.text = "Pressione [Enter] e INSPIRE \n o mais forte que conseguir dentro do tempo.";
                            while (playable)
                            {
                                yield return(null);
                            }
                            CleanRound();
                            playable = true;
                            TextPanel.SetActive(false);
                            break;

                        case 3:
                        case 5:
                        case 7:     //Player's Flow
                            scm.StartSampling();
                            scm.Recalibrate();
                            displayHowTo.text = "";
                            EnablePlayerFlow(true, _roundNumber);
                            _roundNumber++;

                            while (playable)
                            {
                                StartCountdown();
                                yield return(null);
                            }
                            scm.StopSampling();
                            ResetCountDown();
                            playable = true;
                            break;

                        case 8:
                            TextPanel.SetActive(true);
                            displayHowTo.text = "Pressione [Enter] para visualizar sua pontuação.";
                            break;

                        case 9:
                            Debug.Log("Saving minigame data...");
                            GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(true);
                            FindObjectOfType <Core.MinigameLogger>().Save(GameDevice.Mano, RespiratoryExercise.InspiratoryPeak, Minigame.WaterGame);
                            GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(false);
                            Debug.Log("Minigame logs saved.");

                            NotPlayable();
                            break;

                        case 10:
                            TextPanel.SetActive(false);
                            ShowFinalScore();
                            break;

                        case 99:
                            TextPanel.SetActive(true);
                            while (playable)
                            {
                                yield return(null);
                            }
                            playable = true;
                            break;
                        }
                    }
                    else
                    {
                        // Se a CINTA estiver conectada
                        if (scc.IsConnected)
                        {
                            switch (state)
                            {
                            case 1:     //Introduction
                                displayHowTo.text = "Bem-Vindo ao jogo do copo d'agua![ENTER]";

                                while (playable)
                                {
                                    yield return(null);
                                }

                                playable = true;
                                break;

                            case 2:
                            case 4:
                            case 6:     //Pre-flow
                                TextPanel.SetActive(true);
                                displayHowTo.text = "Pressione [Enter] e INSPIRE \n o mais forte que conseguir dentro do tempo.";
                                while (playable)
                                {
                                    yield return(null);
                                }
                                CleanRound();
                                playable = true;
                                TextPanel.SetActive(false);
                                break;

                            case 3:
                            case 5:
                            case 7:     //Player's Flow
                                scc.StartSampling();
                                scc.Recalibrate();
                                displayHowTo.text = "";
                                EnablePlayerFlow(true, _roundNumber);
                                _roundNumber++;

                                while (playable)
                                {
                                    StartCountdown();
                                    yield return(null);
                                }
                                scc.StopSampling();
                                ResetCountDown();
                                playable = true;
                                break;

                            case 8:
                                TextPanel.SetActive(true);
                                displayHowTo.text = "Pressione [Enter] para visualizar sua pontuação.";
                                break;

                            case 9:
                                Debug.Log("Saving minigame data...");
                                GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(true);
                                FindObjectOfType <Core.MinigameLogger>().Save(GameDevice.Cinta, RespiratoryExercise.InspiratoryPeak, Minigame.WaterGame);
                                GameObject.Find("Canvas").transform.Find("SavingBgPanel").gameObject.SetActive(false);
                                Debug.Log("Minigame logs saved.");

                                NotPlayable();
                                break;

                            case 10:
                                TextPanel.SetActive(false);
                                ShowFinalScore();
                                break;

                            case 99:
                                TextPanel.SetActive(true);
                                while (playable)
                                {
                                    yield return(null);
                                }
                                playable = true;
                                break;
                            }
                        }
                    }
                }

                yield return(null);
            }
            sco.StopSampling();
        }