Exemplo n.º 1
0
 void Start()
 {
     state = TimeLineLfp.RegisteredAsPlayerAsk;
     Screen.sleepTimeout = SleepTimeout.NeverSleep;
 }
Exemplo n.º 2
0
    // ------------------- Between user and client --------------------------- //

    void ManageState()
    {
        switch (state)
        {
        case TimeLineLfp.RegisteredAsPlayerAsk:

            uiController.ShowMessageLookingForARoomAvailable();

            client.SetUserName(parameters.GetUserName());
            client.SetState(TimeLineClientLfp.RegisteredAsPlayerAsk);

            state = TimeLineLfp.RegisteredAsPlayerWaitReply;
            LogState();
            break;

        case TimeLineLfp.RegisteredAsPlayerWaitReply:

            if (client.IsState(TimeLineClientLfp.RegisteredAsPlayerGotAnswer))
            {
                if (client.GetRegisteredAsPlayer())
                {
                    if (client.GetCurrentStep() == GameStep.end)
                    {
                        uiController.ShowMessageAlreadyPlayed();
                        state = TimeLineLfp.Dead;
                    }
                    else
                    {
                        parameters.SetPlayerId(client.GetPlayerId());
                        state = TimeLineLfp.MissingPlayersAsk;
                    }
                }
                else
                {
                    state = TimeLineLfp.RoomAvailableAsk;
                }
            }
            break;

        case TimeLineLfp.RoomAvailableAsk:

            client.SetState(TimeLineClientLfp.RoomAvailableAsk);

            state = TimeLineLfp.RoomAvailableWaitReply;

            LogState();
            break;

        case TimeLineLfp.RoomAvailableWaitReply:

            if (client.IsState(TimeLineClientLfp.RoomAvailableGotAnswer))
            {
                if (client.GetRoomAvailable())
                {
                    uiController.Participation();

                    state = TimeLineLfp.WaitingForUserToParticipate;
                    LogState();
                }
                else
                {
                    uiController.NoRoomAvailable();

                    client.SetState(TimeLineClientLfp.WaitingCommand);
                    StartCoroutine(SetClientStateWithDelay(TimeLineClientLfp.RoomAvailableAsk));
                }
            }
            break;

        case TimeLineLfp.WaitingForUserToParticipate:

            if (client.IsState(TimeLineClientLfp.RoomAvailableGotAnswer))
            {
                if (client.GetRoomAvailable())
                {
                    if (uiController.GotUserParticipaton())
                    {
                        state = TimeLineLfp.GotUserParticipation;
                        LogState();
                    }
                    else
                    {
                        client.SetState(TimeLineClientLfp.WaitingCommand);
                        StartCoroutine(SetClientStateWithDelay(TimeLineClientLfp.RoomAvailableAsk));
                    }
                }
                else
                {
                    uiController.NoRoomAvailable();
                    client.SetState(TimeLineClientLfp.RoomAvailableAsk);
                    state = TimeLineLfp.RoomAvailableWaitReply;
                    LogState();
                }
            }

            break;

        case TimeLineLfp.GotUserParticipation:

            client.SetState(TimeLineClientLfp.ProceedToRegistrationAsPlayerAsk);

            state = TimeLineLfp.ProceedToRegistrationAsPlayerWaitReply;
            LogState();
            break;

        case TimeLineLfp.ProceedToRegistrationAsPlayerWaitReply:

            if (client.IsState(TimeLineClientLfp.ProceedToRegistrationAsPlayerGotAnswer))
            {
                if (client.GetRegisteredAsPlayer())
                {
                    state = TimeLineLfp.MissingPlayersAsk;
                    LogState();
                }
                else
                {
                    uiController.NoRoomAvailable();

                    state = TimeLineLfp.RoomAvailableAsk;
                    LogState();
                }
            }
            break;

        case TimeLineLfp.MissingPlayersAsk:

            client.SetState(TimeLineClientLfp.MissingPlayersAsk);
            state = TimeLineLfp.MissingPlayersWaitReply;
            LogState();
            break;

        case TimeLineLfp.MissingPlayersWaitReply:

            if (client.IsState(TimeLineClientLfp.MissingPlayersGotAnswer))
            {
                if (client.GetErrorRaised())
                {
                    if (client.GetError() == CodeErrorLfp.playerDisconnected)
                    {
                        uiController.ShowMessagePlayerDisconnected();
                    }
                    else if (client.GetError() == CodeErrorLfp.opponentDisconnected)
                    {
                        uiController.ShowMessageOpponentDisconnected();
                    }
                    else
                    {
                        uiController.ShowMessageNoOtherPlayer();
                    }

                    state = TimeLineLfp.Dead;
                    LogState();
                }
                else if (client.GetMissingPlayers() == 0)
                {
                    uiController.WaitingForPlay();

                    state = TimeLineLfp.PrepareNewScene;
                    LogState();
                }
                else
                {
                    uiController.UpdateMissingPlayers(client.GetMissingPlayers());

                    client.SetState(TimeLineClientLfp.WaitingCommand);
                    StartCoroutine(SetClientStateWithDelay(TimeLineClientLfp.MissingPlayersAsk));
                }
            }
            break;

        case TimeLineLfp.PrepareNewScene:

            parameters.SetPlayerId(client.GetPlayerId());
            parameters.SetCurrentStep(client.GetCurrentStep());
            parameters.SetDisplayOpponentScore(client.GetDisplayOpponentScore());
            parameters.SetConsumersFieldOfView(client.GetConsumersFieldOfView());

            // Load next scene
            sceneToLoad = sceneFirm;

            uiController.QuitScene();

            state = TimeLineLfp.WaitEndAnimationQuitScene;
            LogState();
            break;

        case TimeLineLfp.WaitEndAnimationQuitScene:
            break;

        case TimeLineLfp.EndAnimationQuitScene:

            LoadNewScene();
            state = TimeLineLfp.Dead;
            LogState();
            break;

        case TimeLineLfp.Dead:
            break;

        default:
            throw new System.Exception("GC (LookForPlaying): Bad state ('" + state + "').");
        }
    }
Exemplo n.º 3
0
    // ----------- From UIManager ---------------- //

    public void EndAnimationQuitScene()
    {
        state = TimeLineLfp.EndAnimationQuitScene;
    }