Beispiel #1
0
    // ----------------------------------------------------------------------------------------------------------- //

    public void ManageState()
    {
        // Called by game controller

        List <int> seen = new List <int> ();

        switch (stateTuto)
        {
        case TLTutoF.Init:

            position         = initialPlayerPosition;
            price            = initialPlayerPrice;
            opponentPosition = initialOpponentPosition;
            opponentPrice    = initialOpponentPrice;

            scoreManager.ResetScores();

            Debug.Log("Player: Start tutorial. Player position and price are " + position + ", " + price +
                      " and opponent position and price are " + opponentPosition + ", " + opponentPrice + ".");

            positionsSeenByExampleConsumer = GameTools.PositionsSeenByAConsumer(exampleConsumerPosition, consumersFieldOfView);
            firmsSeenByExampleConsumer     = GameTools.FirmsSeenByAConsumer(positionsSeenByExampleConsumer, position, opponentPosition);

            populationController.PlaceAgentsToInitialPosition(position, opponentPosition);

            uiController.PrepareTutorial(
                position, price, opponentPrice,
                scoreManager.GetScoreCumulative(),
                scoreManager.GetOpponentScoreCumulative()
                );

            submitProgression = true;
            StartCoroutine(SubmitProgression());

            TutoNextStep();
            break;

        case TLTutoF.Messenger:

            ac.indicatorMessenger.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.You:

            populationController.MakePlayerAppear();

            ac.indicatorMessenger.SetBool(Bool.visible, false);
            ac.indicatorYou.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Opponent:

            populationController.MakeOpponentAppear();

            ac.indicatorYou.SetBool(Bool.visible, false);
            ac.indicatorOpponent.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Consumer:

            populationController.MakeConsumerAppear(exampleConsumerPosition);

            ac.indicatorOpponent.SetBool(Bool.visible, false);
            ac.indicatorConsumer.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.ConsumerProcess:

            ac.indicatorConsumer.SetBool(Bool.visible, false);
            texts.indicatorCentral.text = TutorialTextsF.consumerProcess;
            ac.indicatorCentral.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.ConsumerLimitedFieldOfView:

            if (firmsSeenByExampleConsumer.Contains(GameRole.opponent))
            {
                ac.HUDOpponent.SetBool(Bool.visible, true);
            }

            if (firmsSeenByExampleConsumer.Contains(GameRole.player))
            {
                ac.HUDPlayer.SetBool(Bool.visible, true);
            }


            fogController.RevealPositions(positionsSeenByExampleConsumer);

            ac.indicatorConsumer.SetBool(Bool.visible, false);
            texts.indicatorCentral.text = TutorialTextsF.consumerLimitedFieldOfView;
            ac.indicatorCentral.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.ConsumerFirmTurn:

            texts.indicatorCentral.text = TutorialTextsF.consumerFirmTurn;

            TutoNextStep();
            break;

        case TLTutoF.ConsumerSee:

            texts.indicatorCentral.text = TutorialTextsF.consumerSee;

            TutoNextStep();
            break;

        case TLTutoF.ConsumerNoOne:

            texts.indicatorCentral.text = TutorialTextsF.consumerNoOne;

            TutoNextStep();
            break;


        case TLTutoF.ConsumerNoChoice:

            texts.indicatorCentral.text = TutorialTextsF.consumerNoChoice;

            TutoNextStep();
            break;

        case TLTutoF.ConsumerLessExpensive:

            texts.indicatorCentral.text = TutorialTextsF.consumerLessExpensive;

            TutoNextStep();
            break;


        case TLTutoF.ConsumerMoving:

            int target = GameTools.GetConsumerTarget(firmsSeenByExampleConsumer, price, opponentPrice);

            ac.indicatorCentral.SetBool(Bool.visible, false);

            if (target == GameRole.player)
            {
                StartCoroutine(
                    populationController.MoveExampleConsumer(exampleConsumerPosition, GameRole.player));
            }
            else if (target == GameRole.opponent)
            {
                StartCoroutine(
                    populationController.MoveExampleConsumer(exampleConsumerPosition, GameRole.opponent));
            }
            else
            {
                ConsumersAreArrived();
            }

            TutoNextStep();
            break;

        case TLTutoF.ConsumerBot:

            seen = new List <int> ();

            seen = firmsSeenByExampleConsumer;

            if (seen.Contains(GameRole.opponent))
            {
                ac.HUDOpponent.SetBool(Bool.visible, false);
            }

            if (seen.Contains(GameRole.player))
            {
                ac.HUDPlayer.SetBool(Bool.visible, false);
            }

            fogController.NoFog();

            populationController.MakeAllConsumerAppear();

            texts.indicatorCentral.text = TutorialTextsF.consumerBot;
            ac.indicatorCentral.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Score:

            ac.cumulativeScore.SetBool(Bool.visible, true);

            ac.indicatorCentral.SetBool(Bool.visible, false);
            ac.indicatorScore.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.ScoreTurn:

            fakeConsumerChoices = GameTools.NewFakeConsumerChoices(consumersFieldOfView, position, opponentPosition, price, opponentPrice);

            ac.indicatorScore.SetBool(Bool.visible, false);            // uiController.UpdateScoreToAddAndNClients (client.GetScoreTurn(), client.GetOpponentScoreTurn(), client.GetNClients());
            ac.indicatorScoreTurn.SetBool(Bool.visible, true);

            uiController.ResetScoreTexts();
            uiController.FloatingScoreAnimaton();
            ac.scores.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Training:

            ac.indicatorScoreTurn.SetBool(Bool.visible, false);

            texts.indicatorCentral.text = TutorialTextsF.training;
            ac.indicatorCentral.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.TurnPlayer:

            ac.indicatorCentral.SetBool(Bool.visible, false);
            ac.indicatorTurnPlayer.SetBool(Bool.visible, true);

            // For turn selection
            uiController.ChangeSelectedTurn(Turn.player);
            ac.turns.SetBool(Bool.visible, true);
            uiController.TurnSelectionAnimation(true);

            // For HUD
            ac.HUDOpponent.SetBool(Bool.visible, true);
            ac.HUDPlayer.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.ChangePosition:

            ac.strategicButtons.SetBool(Bool.visible, true);
            ac.buttonYes.SetBool(Bool.visible, true);

            uiController.AuthorizeDeplacement(true);

            ac.indicatorTurnPlayer.SetBool(Bool.visible, false);
            ac.indicatorChangePosition.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Highlight:

            ac.indicatorChangePosition.SetBool(Bool.visible, false);
            texts.indicatorCentral.text = TutorialTextsF.highlight;
            ac.indicatorCentral.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.ChangePrice:

            uiController.AuthorizePriceSelection(true);

            ac.indicatorCentral.SetBool(Bool.visible, false);
            ac.indicatorChangePrice.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Validation:

            if (!populationController.PlayerIsMoving())
            {
                uiController.AuthorizeValidation(true);

                ac.indicatorChangePrice.SetBool(Bool.visible, false);
                ac.indicatorValidation.SetBool(Bool.visible, true);

                TutoNextStep();
            }
            break;

        case TLTutoF.MovingConsumers1:
        case TLTutoF.MovingConsumers2:

            if (stateTuto == TLTutoF.MovingConsumers1)
            {
                ac.indicatorTurnConsumers1.SetBool(Bool.visible, false);
            }
            else
            {
                ac.indicatorTurnConsumers2.SetBool(Bool.visible, false);
            }

            position = uiController.GetSelectedPosition();
            price    = uiController.GetSelectedPrice();

            Debug.Log("TutorialF: Position " + position);
            Debug.Log("TutorialF: Price " + price);
            Debug.Log("TutorialF: Opp postion " + opponentPosition);
            Debug.Log("TutorialF: Opp pirice " + opponentPrice);

            fakeConsumerChoices = GameTools.NewFakeConsumerChoices(consumersFieldOfView, position, opponentPosition, price, opponentPrice);

            scoreManager.ComputeScores(fakeConsumerChoices, price, opponentPrice);

            StartCoroutine(populationController.MoveConsumers(fakeConsumerChoices));

            TutoNextStep();
            break;

        case TLTutoF.MovingBackConsumers1:
        case TLTutoF.MovingBackConsumers2:

            ac.buttonCashRegister.SetBool(Bool.visible, false);

            ac.indicatorValidation.SetBool(Bool.visible, false);

            uiController.AddScoreAnimation();

            uiController.TurnSelectionAnimation(true);

            StartCoroutine(populationController.MoveBackConsumers());

            TutoNextStep();
            break;

        case TLTutoF.Collect:
        case TLTutoF.Collect2:

            uiController.TurnSelectionAnimation(false);
            uiController.GlowingCurrentScoreAnimation();

            uiController.UpdateScoreTurnAndCumulative(
                scoreManager.GetNClients(),
                scoreManager.GetScoreTurn(),
                scoreManager.GetOpponentScoreTurn(),
                scoreManager.GetScoreCumulative(),
                scoreManager.GetOpponentScoreCumulative()
                );

            uiController.AuthorizeCollect(true);
            ac.buttonCashRegister.SetBool(Bool.visible, true);

            texts.indicatorValidation.text = TutorialTextsF.collect;
            ac.indicatorValidation.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.TurnConsumers1:

            uiController.ChangeSelectedTurn(Turn.consumers1);
            uiController.FloatingConsumerAndCurrentScoreAnimation();

            uiController.AuthorizeDeplacement(false);
            ac.buttonYes.SetBool(Bool.visible, false);
            ac.strategicButtons.SetBool(Bool.visible, false);

            ac.indicatorValidation.SetBool(Bool.visible, false);
            ac.indicatorTurnConsumers1.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.TurnConsumers2:

            uiController.SetOpponentPrice(opponentPrice);

            uiController.ResetScoreTexts();
            uiController.FloatingConsumerAndCurrentScoreAnimation();

            uiController.ChangeSelectedTurn(Turn.consumers2);

            ac.indicatorTurnConsumers2.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.TurnOpponent:

            ac.indicatorTurnOpponent.SetBool(Bool.visible, true);
            uiController.ChangeSelectedTurn(Turn.opponent);

            TutoNextStep();
            break;

        case TLTutoF.MovingOpponent:

            ac.indicatorTurnOpponent.SetBool(Bool.visible, false);

            opponentPosition = GameTools.NewFakeOpponentPosition(opponentPosition);
            opponentPrice    = GameTools.NewFakeOpponentPrice(opponentPrice);

            StartCoroutine(populationController.MoveOpponentAndSendSignal(opponentPosition));

            TutoNextStep();
            break;

        case TLTutoF.EndTraining:

            uiController.TurnSelectionAnimation(false);

            texts.indicatorCentral.text = TutorialTextsF.endOfTraining;
            ac.indicatorCentral.SetBool(Bool.visible, true);

            TutoNextStep();
            break;

        case TLTutoF.Money:

            texts.indicatorCentral.text = TutorialTextsF.money;

            TutoNextStep();
            break;

        case TLTutoF.End:

            fogController.NoFog();

            uiController.HideObjects();

            populationController.EndRound();

            submitProgression = false;

            gameController.EndTutorial();

            TutoNextStep();
            break;

        case TLTutoF.Dead:
            break;
        }
    }
Beispiel #2
0
    public void ManageState()
    {
        switch (stateGame)
        {
        case TLRoundF.Init:

            //client.AskInit (parameters.GetRoomId (), parameters.GetPlayerId ());
            client.AskInit();

            timeOfInit = Time.time;

            RoundNextStep();
            break;

        case TLRoundF.WaitingInfo:

            if (client.IsState(TLClientF.GotInit))
            {
                if (client.GotFatalError())
                {
                    stateGame = TLRoundF.EndingGame;
                    LogGameState();
                    break;
                }

                if (client.GetTime() == CodeErrorF.haveToWait)
                {
                    client.AskInit();
                    uiController.ShowMessageProgressOtherPlayer(client.GetProgressOtherPlayer());
                }
                else
                {
                    float delta = Time.time - timeOfInit;
                    if (delta > timeForInitialAnimation)
                    {
                        RoundNextStep();
                    }
                }
            }
            break;

        case TLRoundF.GotInfo:

            gameController.GotInitInfo();
            stateGame = TLRoundF.WaitingGoCommand;
            // RoundNextStep ();
            break;

        case TLRoundF.Preparation:

            // Instruction to scoreManager
            scoreManager.SetCumulativeScores(client.GetScore(), client.GetOpponentScore());

            // Instructions for uiController
            uiController.PrepareNewRound(client.GetPosition(), client.GetPrice(), client.GetOpponentPrice(),
                                         client.GetScore(), client.GetOpponentScore());
            uiController.SetProgress(ComputeProgress());

            // Instructions for populationController
            populationController.PrepareNewRound(client.GetPosition(), client.GetOpponentPosition());

            if (client.GetInitialStateOfPlay() == "active")
            {
                // Update state
                stateGame = TLRoundF.ActiveBeginningOfTurn;
            }
            else
            {
                uiController.EnableChoice(false);

                // Update state
                stateGame = TLRoundF.PassiveBeginningOfTurn;
            }

            LogGameState();
            break;

        case TLRoundF.PassiveBeginningOfTurn:

            client.AskFirmPassiveOpponentChoice();

            // Instructions for UIController
            uiController.ChangeSelectedTurn(Turn.opponent);
            uiController.ResetScoreTexts();
            uiController.FloatingConsumerAndCurrentScoreAnimation();

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.PassiveWaitingOpponent:

            if (client.IsState(TLClientF.GotPassiveOpponentChoice))
            {
                if (client.GotFatalError())
                {
                    stateGame = TLRoundF.EndingGame;
                    LogGameState();
                    break;
                }

                // Instructions for populationController
                StartCoroutine(populationController.MoveOpponentAndSendSignal(client.GetOpponentPosition()));

                // Update state
                RoundNextStep();
            }
            else if (!populationController.OpponentIsMoving())
            {
                populationController.MoveOpponent(UnityEngine.Random.Range(0, GameFeatures.nPositions - 1));
            }

            break;

        case TLRoundF.PassiveOpponentHasMoved:          // this state is reached once the opponent has done his move (signal is sent by the population control)

            // Instructions for UIController
            uiController.SetOpponentPrice(client.GetOpponentPrice());
            uiController.ChangeSelectedTurn(Turn.consumers2);

            scoreManager.ComputeScores(client.GetConsumerChoicesPassive(), client.GetPrice(), client.GetOpponentPrice());

            // Instructions to populationController
            StartCoroutine(populationController.MoveConsumers(client.GetConsumerChoicesPassive()));

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.PassiveConsumersHaveMoved:

            // Instructions to UIController
            uiController.UpdateScoreTurnAndCumulative(
                scoreManager.GetNClients(),
                scoreManager.GetScoreTurn(),
                scoreManager.GetOpponentScoreTurn(),
                scoreManager.GetScoreCumulative(),
                scoreManager.GetOpponentScoreCumulative()
                );

            uiController.AuthorizeCollect(true);
            ac.buttonCashRegister.SetBool(Bool.visible, true);
            uiController.TurnSelectionAnimation(false);
            uiController.GlowingCurrentScoreAnimation();

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.PassiveNextTurn:

            // Instructions for uiController
            uiController.AddScoreAnimation();
            uiController.TurnSelectionAnimation(true);

            ac.buttonCashRegister.SetBool(Bool.visible, false);

            // Instructions for populationController
            StartCoroutine(populationController.MoveBackConsumers());

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.PassiveEndOfTurn:

            if (client.GetEndGame() == 1)
            {
                uiController.SetProgress(1.0f);

                stateGame = TLRoundF.EndingGame;
            }
            else
            {
                uiController.SetProgress(ComputeProgress());

                // Update state
                stateGame = TLRoundF.ActiveBeginningOfTurn;
            }

            LogGameState();
            break;

        case TLRoundF.ActiveBeginningOfTurn:

            // Instructions to UIController
            uiController.AuthorizeDeplacement(true);
            uiController.ResetScoreTexts();
            uiController.FloatingScoreAnimaton();
            uiController.EnableChoice(true);
            uiController.ChangeSelectedTurn(Turn.player);

            // Animations
            ac.buttonYes.SetBool(Bool.visible, true);
            ac.strategicButtons.SetBool(Bool.visible, true);


            // Instructions for populationController
            populationController.ShowConsumersOutline();

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.ActiveChoiceMade:

            // Inform client that the user made his choice.
            client.AskFirmActiveChoiceRecording(uiController.GetSelectedPosition(), uiController.GetSelectedPrice());

            // Instructions for UIController
            uiController.FloatingConsumerAndCurrentScoreAnimation();
            uiController.ChangeSelectedTurn(Turn.consumers1);

            // Animations
            ac.buttonYes.SetBool(Bool.visible, false);
            ac.strategicButtons.SetBool(Bool.visible, false);

            // Instructions for populationController
            populationController.HideConsumersOutline();

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.ActiveChoiceSubmitting:

            if (client.IsState(TLClientF.GotActiveChoiceRecording))
            {
                if (client.GotFatalError())
                {
                    stateGame = TLRoundF.EndingGame;
                    LogGameState();
                    break;
                }

                RoundNextStep();
            }

            break;

        case TLRoundF.ActiveChoiceSubmitted:

            scoreManager.ComputeScores(client.GetConsumerChoicesActive(), client.GetPrice(), client.GetOpponentPrice());

            // Instructions for populationController
            StartCoroutine(populationController.MoveConsumers(client.GetConsumerChoicesActive()));

            RoundNextStep();
            break;

        case TLRoundF.ActiveConsumersHaveMoved:

            // Instructions for UIController
            uiController.UpdateScoreTurnAndCumulative(
                scoreManager.GetNClients(),
                scoreManager.GetScoreTurn(),
                scoreManager.GetOpponentScoreTurn(),
                scoreManager.GetScoreCumulative(),
                scoreManager.GetOpponentScoreCumulative()
                );

            uiController.TurnSelectionAnimation(false);
            uiController.AuthorizeCollect(true);
            uiController.GlowingCurrentScoreAnimation();

            // Animations
            ac.buttonCashRegister.SetBool(Bool.visible, true);

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.ActiveNextTurn:

            // Instructions for uiController
            uiController.AddScoreAnimation();
            ac.buttonCashRegister.SetBool(Bool.visible, false);
            uiController.TurnSelectionAnimation(true);

            // Instructions for populationController
            StartCoroutine(populationController.MoveBackConsumers());

            // Update state
            RoundNextStep();
            break;

        case TLRoundF.ActiveEndOfTurn:

            if (client.GetEndGame() == 1)
            {
                uiController.SetProgress(1.0f);

                // Update state
                stateGame = TLRoundF.EndingGame;
            }
            else
            {
                uiController.SetProgress(ComputeProgress());

                // Update state
                stateGame = TLRoundF.PassiveBeginningOfTurn;
            }

            LogGameState();

            break;

        case TLRoundF.EndingGame:

            uiController.HideObjects();

            ////

            stateGame = TLRoundF.EndOfGame;

            if (client.GotFatalError())
            {
                gameController.FatalError();
            }
            else
            {
                gameController.EndOfRound();
            }
            break;

        case TLRoundF.EndOfGame:

            break;

        default:
            break;
        }
    }