Esempio n. 1
0
    public void Guess(CardUtil.EntityEnum entity, Participant _participant = null)
    {
        if (gameOver || cardInDelay)
        {
            return;
        }

        Participant participant = _participant == null ? player1 : _participant;

        if (participant.guessed)
        {
            return;
        }

        participant.guessed = true;
        float timeToGuess = participant.Stats.AddGuess(Time.time, correctEntity.Value, entity);

        if (entity == correctEntity)
        {
            participant.points++;

            //Clear coroutine so other cpus will stop guessing
            cpuCoroutines.ForEach(co => StopCoroutine(co));
            cpuCoroutines.Clear();

            if (participant != player1 && !player1.guessed)
            {
                player1.Stats.AddMissed(correctEntity.Value);
            }
            if (GameSettingsUtil.GetGameType() == GameSettingsUtil.GameTypeEnum.Two && participant != player2 && !player2.guessed)
            {
                player2.Stats.AddMissed(correctEntity.Value);
            }
            GameUtil.cpuList.ForEach(cpu =>
            {
                if (participant != cpu && !cpu.guessed)
                {
                    cpu.Stats.AddMissed(correctEntity.Value);
                }
            });

            if (participant == player1 || (GameSettingsUtil.GetGameType() == GameSettingsUtil.GameTypeEnum.Two && participant == player2))
            {
                correctStreak++;
                if (useCorrectColor)
                {
                    GameProgressionUtil.UpdateGameProgression(rep => rep.totalCorrectCorrectlyColoredGuesses++);
                }
                else
                {
                    GameProgressionUtil.UpdateGameProgression(rep => rep.totalCorrectIncorrectlyColoredGuesses++);
                }
                if (correctEntity == CardUtil.EntityEnum.Coco)
                {
                    GameProgressionUtil.UpdateGameProgression(rep => rep.totalTimesCocoWasPicked++);
                }
                if (correctEntity == CardUtil.EntityEnum.Chomp)
                {
                    GameProgressionUtil.UpdateGameProgression(rep => rep.totalTimesChompWasPicked++);
                }
                if (timeToGuess < 1f)
                {
                    GameProgressionUtil.UpdateGameProgression(rep => rep.totalCorrectGuessesUnderOneSecond++);
                }
                if (timeToGuess < .5f)
                {
                    GameProgressionUtil.UpdateGameProgression(rep => rep.totalCorrectGuessesUnderHalfASecond++);
                }
                gameAudioManager.PlayCorrectGuess();
            }
            else
            {
                Cpu cpu = (Cpu)participant;
                gameAudioManager.PlayAVoice(cpu.voiceCorrect);
            }
        }
        else
        {
            if (SettingsUtil.IsPenaltiesAllowed())
            {
                participant.penalties++;
                if (participant.points - participant.penalties < 0 && !SettingsUtil.IsNegativeScoresAllowed())
                {
                    participant.penalties--;
                }
            }

            if (participant == player1 || (GameSettingsUtil.GetGameType() == GameSettingsUtil.GameTypeEnum.Two && participant == player2))
            {
                correctStreak = 0;
                gameAudioManager.PlayIncorrectGuess();
            }
            else
            {
                Cpu cpu = (Cpu)participant;
                gameAudioManager.PlayAVoice(cpu.voiceIncorrect);
            }
        }


        if (participant == player1)
        {
            SetButtonsEnabled(player1Buttons, entity == correctEntity);
        }
        if (participant == player2)
        {
            SetButtonsEnabled(player2Buttons, entity == correctEntity);
        }

        participant.finalScore = participant.points - participant.penalties;
        UpdateScoresAndNameText();

        CheckForGameOver();
        bool player2Guessed = GameSettingsUtil.GetGameType() == GameSettingsUtil.GameTypeEnum.Two && player2.guessed;

        if (entity == correctEntity || ((GameSettingsUtil.GetGameType() == GameSettingsUtil.GameTypeEnum.Single || player2Guessed) && player1.guessed && GameUtil.cpuList.All(cpu => cpu.guessed)))
        {
            if (cardGameObject != null)
            {
                DestroyImmediate(cardGameObject.gameObject);
                cardGameObject = null;
            }

            if (!gameOver)
            {
                StartCoroutine(NewRoundWithDelay());
            }
        }
    }