void SetUpParameterization(GameParameterization parameterization)
    {
        GameGlobals.players.Clear();
        int currPlayerId = 0;

        for (int i = 0; i < parameterization.playerParameterizations.Count; i++)
        {
            PlayerParameterization currParam = parameterization.playerParameterizations[i];

            GameProperties.Instrument currLikedInstrument = GameProperties.Instrument.NONE;

            switch (currParam.likedInstrument)
            {
            case "GUITAR":
                currLikedInstrument = GameProperties.Instrument.GUITAR;
                break;

            case "DRUMS":
                currLikedInstrument = GameProperties.Instrument.DRUMS;
                break;

            case "VOCALS":
                currLikedInstrument = GameProperties.Instrument.VOCALS;
                break;

            case "KEYBOARD":
                currLikedInstrument = GameProperties.Instrument.KEYBOARD;
                break;

            case "BASS":
                currLikedInstrument = GameProperties.Instrument.BASS;
                break;

            default:
                currLikedInstrument = GameProperties.Instrument.GUITAR;
                //isErrorEncountered = true;
                //setupWarningPoppupRef.DisplayPoppup("did not parse the liked instrument of player. Guitar assumed..." + currParam.name);
                break;
            }

            switch (currParam.playerType)
            {
            case "HUMAN":
                GameGlobals.players.Add(new UIPlayer(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name));
                break;

            case "SIMPLE":
                GameGlobals.players.Add(new AIPlayerSimpleStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            case "RANDOM":
                GameGlobals.players.Add(new AIPlayerRandomStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            case "COOPERATIVE":
                GameGlobals.players.Add(new AIPlayerCoopStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            case "GREEDY":
                GameGlobals.players.Add(new AIPlayerGreedyStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            case "BALANCED":
                GameGlobals.players.Add(new AIPlayerBalancedStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            case "UNBALANCED":
                GameGlobals.players.Add(new AIPlayerUnbalancedStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            case "TITFORTAT":
                GameGlobals.players.Add(new AIPlayerTitForTatStrategy(playerUIPrefab, playerCanvas, GameGlobals.monoBehaviourFunctionalities, playerWarningPoppupRef, currPlayerId++, currParam.name, currParam.isSpeechAllowed, currLikedInstrument));
                break;

            default:
                isErrorEncountered = true;
                setupWarningPoppupRef.DisplayPoppup("Error on parsing the player type of " + currParam.name);
                Debug.Log("[ERROR]: Error on parsing the player type of " + currParam.name);
                break;
            }
        }

        string pattern = "FIXED:[WL]+";
        Match  m       = Regex.Match(parameterization.ngType, pattern, RegexOptions.IgnoreCase);

        if (m.Success)
        {
            int    index       = parameterization.ngType.IndexOf(":");
            string gameResults = parameterization.ngType.Substring(index + 1);
            GameGlobals.gameDiceNG = new PredefinedDiceNG(gameResults);
        }
        else
        {
            switch (parameterization.ngType)
            {
            case "RANDOM":
                GameGlobals.gameDiceNG = new RandomDiceNG();
                break;

            case "FIXED:LOSS":
                GameGlobals.gameDiceNG = new LossDiceNG();
                break;

            case "FIXED:VICTORY":
                GameGlobals.gameDiceNG = new VictoryDiceNG();
                break;

            default:
                isErrorEncountered = true;
                setupWarningPoppupRef.DisplayPoppup("Error on parsing the NG Type of parameterization " + parameterization.ngType);
                Debug.Log("[ERROR]: Error on parsing the NG Type of parameterization " + parameterization.ngType);
                break;
            }
        }


        //Game.gameParameterizations.Add(parameterization);
        //string json = JsonUtility.ToJson(GameProperties.configurableProperties);
    }
    private void LoadEndScreenUIElements()
    {
        PoppupScreenFunctionalities infoPoppupNeutralRef = new PoppupScreenFunctionalities(false, null, null, poppupPrefab, mainScene, this.GetComponent <MonoBehaviourFunctionalities>(), Resources.Load <Sprite>("Textures/UI/Icons/Info"), new Color(0.9f, 0.9f, 0.9f));

        GameGlobals.players.Sort(SortPlayersByMoney);
        int numPlayers = GameGlobals.players.Count;

        for (int i = 0; i < numPlayers; i++)
        {
            Player     currPlayer    = GameGlobals.players[i];
            GameObject newTableEntry = Object.Instantiate(UIIndividualTableEntryPrefab, UIIndividualTable.transform);
            newTableEntry.GetComponentsInChildren <Text>()[0].text = currPlayer.GetName();
            newTableEntry.GetComponentsInChildren <Text>()[1].text = currPlayer.GetMoney().ToString();
        }

        //Text UIEndGameButtonText = UIEndGameButton.GetComponentInChildren<Text>();
        Text UIRestartGameButtonText = UIRestartGameButton.GetComponentInChildren <Text>();

        if (GameProperties.configurableProperties.isAutomaticalBriefing)
        {
            if (GameGlobals.currGameId >= GameProperties.configurableProperties.numSessionGames)
            {
                //infoPoppupNeutralRef.DisplayPoppup("You reached the end of the experiment. You should now fill in the first questionnaire and you need to memorize the following code and also your score.");
                infoPoppupNeutralRef.DisplayPoppup("You reached the end of the second game. Please write down your score, as well as the following gamecode, and fill the second questionnaire to finish the experiment.");
                //UIEndGameButton.gameObject.SetActive(true);
                //UIEndGameButton.interactable = true;
                //UIEndGameButtonText.text = "Final Notes";
                UIWarningText.text = "You reached the end of the second game.Please write down your score, as well as the following gamecode, and fill the second questionnaire to finish the experiment.";

                UIEndGameButton.gameObject.SetActive(false);
                UIEndGameButton.interactable = false;
                UIRestartGameButton.gameObject.SetActive(false);
                UIRestartGameButton.interactable = false;

                UIFinishedGameOverlay.SetActive(true);
            }
            else
            {
                //infoPoppupNeutralRef.DisplayPoppup("You reached the end of one of the games to play in this session. We assume that you are prepared for the experiment game. Good luck!");
                infoPoppupNeutralRef.DisplayPoppup("You reached the end of the first game. Please write down your score (the total amount of money you made) and fill the first questionnaire. Please, do not move to next game until the questionnaire mentions you to do so.");
                UIRestartGameButton.gameObject.SetActive(true);
                UIRestartGameButton.interactable = true;
                UIRestartGameButtonText.text     = "Next game";
                UIWarningText.text = "Please write down your score (the total amount of money you made) and fill the first questionnaire. Please, do not move to next game until the questionnaire mentions you to do so.";

                UIEndGameButton.gameObject.SetActive(false);
                UIEndGameButton.interactable = false;

                UIFinishedGameOverlay.SetActive(false);
            }
        }
        else
        {
            UIRestartGameButton.gameObject.SetActive(true);
            UIRestartGameButton.interactable = true;
            UIRestartGameButtonText.text     = "Restart Game";
            UIEndGameButton.gameObject.SetActive(false);
            UIEndGameButton.interactable = false;
        }



        if (GameGlobals.albums != null)
        {
            //disable rendering of some albums and selecting others
            int numAlbumsPlayed = GameGlobals.albums.Count;
            for (int i = 0; i < numAlbumsPlayed; i++)
            {
                Album      currAlbum   = GameGlobals.albums[i];
                GameObject currAlbumUI = currAlbum.GetAlbumUI();
                if ((numAlbumsPlayed - i) > 5) //maximum of 5 last albums rendered albums
                {
                    currAlbumUI.SetActive(false);
                    continue;
                }
                currAlbumUI.SetActive(true);

                Animator animator = currAlbumUI.GetComponentInChildren <Animator>();
                animator.Rebind();
                animator.Play(0);
                animator.speed = (i * 0.1f < animator.speed) ? animator.speed - i * 0.1f : animator.speed;

                currAlbumUI.transform.SetParent(UIAlbumCollectionDisplay.transform);
                currAlbumUI.transform.localPosition = new Vector3(0, 0, 0);
                currAlbumUI.transform.localScale    = new Vector3(1, 1, 1);

                currAlbumUI.transform.Translate(new Vector3(i * Screen.width * 0.03f, 0, 0));
            }
            //write gameId in finish experiment text
            UIFinishedGameOverlay.transform.Find("text/gameId").GetComponent <Text>().text = GameGlobals.currSessionId;
            UIFinishedGameOverlay.transform.Find("text/WebGLInputField/Text").GetComponent <Text>().text = GameGlobals.currSessionId;
            Button UICopyGameIdButton = UIFinishedGameOverlay.transform.Find("text/copyGameIdButton").GetComponent <Button>();
            Button UINextGameButton   = UIFinishedGameOverlay.transform.Find("text/nextGameButton").GetComponent <Button>();

            UINextGameButton.onClick.AddListener(delegate() {
                RestartGame();
            });
        }

        UIRestartGameButton.onClick.AddListener(delegate() {
            RestartGame();
        });
    }
Exemple #3
0
    public override int SpendToken(GameProperties.Instrument instrument)
    {
        int result = base.SpendToken(instrument);

        if (result != 0) //handle the error in the UI
        {
            switch (result)
            {
            case 1:
                warningScreenRef.DisplayPoppup("You cannot level up more skills in this round!");
                break;

            case 2:
                warningScreenRef.DisplayPoppup("You cannot develop the same skill more than " + GameProperties.configurableProperties.maximumSkillLevelPerInstrument + " times!");
                break;
            }
        }
        return(result);
    }
Exemple #4
0
    // wait for all players to exit one phase and start other phase
    void Update()
    {
        //avoid rerun in this case because load scene is asyncronous
        if (this.gameMainSceneFinished || this.interruptionRequests > 0)
        {
            //Debug.Log("pause...");
            return;
        }


        //middle of the phases
        if (choosePreferedInstrumentResponseReceived)
        {
            currSpeakingPlayerId = Random.Range(0, GameGlobals.numberOfSpeakingPlayers);

            choosePreferedInstrumentResponseReceived = false;
            Player currPlayer = GameGlobals.players[currPlayerIndex];
            Player nextPlayer = ChangeToNextPlayer(currPlayer);
            //if (numPlayersToChooseDiceRollInstrument > 0)
            //{
            foreach (var player in GameGlobals.players)
            {
                if (player == currPlayer)
                {
                    continue;
                }
                player.InformChoosePreferredInstrument(nextPlayer);
            }
            //}
            numPlayersToChooseDiceRollInstrument--;
            if (numPlayersToChooseDiceRollInstrument > 0)
            {
                nextPlayer.ChoosePreferredInstrumentRequest(currAlbum);
            }
        }
        if (levelUpResponseReceived)
        {
            currSpeakingPlayerId = Random.Range(0, GameGlobals.numberOfSpeakingPlayers);

            levelUpResponseReceived = false;
            Player currPlayer = GameGlobals.players[currPlayerIndex];
            Player nextPlayer = ChangeToNextPlayer(currPlayer);
            //if (numPlayersToLevelUp > 0)
            //{
            foreach (var player in GameGlobals.players)
            {
                if (player == currPlayer)
                {
                    continue;
                }
                player.InformLevelUp(currPlayer, currPlayer.GetLeveledUpInstrument());
            }
            //}
            numPlayersToLevelUp--;
            if (numPlayersToLevelUp > 0)
            {
                nextPlayer.LevelUpRequest(currAlbum);
            }
        }
        if (playForInstrumentResponseReceived)
        {
            currSpeakingPlayerId = Random.Range(0, GameGlobals.numberOfSpeakingPlayers);

            playForInstrumentResponseReceived = false;
            Player currPlayer = GameGlobals.players[currPlayerIndex];
            Player nextPlayer = ChangeToNextPlayer(currPlayer);
            //if (numPlayersToPlayForInstrument > 0)
            //{
            foreach (var player in GameGlobals.players)
            {
                if (player == currPlayer)
                {
                    continue;
                }
                player.InformPlayForInstrument(nextPlayer);
            }

            //}
            numPlayersToPlayForInstrument--;
            if (numPlayersToPlayForInstrument > 0)
            {
                nextPlayer.PlayForInstrumentRequest(currAlbum);
            }
        }
        if (lastDecisionResponseReceived)
        {
            currSpeakingPlayerId = Random.Range(0, GameGlobals.numberOfSpeakingPlayers);

            lastDecisionResponseReceived = false;
            Player currPlayer = GameGlobals.players[currPlayerIndex];
            Player nextPlayer = ChangeToNextPlayer(currPlayer);
            //if (numPlayersToStartLastDecisions > 0)
            //{
            foreach (var player in GameGlobals.players)
            {
                if (player == currPlayer)
                {
                    continue;
                }
                player.InformLastDecision(nextPlayer);
            }
            //}
            numPlayersToStartLastDecisions--;
            if (numPlayersToStartLastDecisions > 0)
            {
                nextPlayer.LastDecisionsPhaseRequest(currAlbum);
            }
        }

        //end of first phase; trigger second phase
        if (!preferredInstrumentsChoosen && numPlayersToChooseDiceRollInstrument == 0)
        {
            //Debug.Log("running1...");
            StartPlayForInstrumentPhase(); //choose instrument phase skips level up phase
            //numPlayersToChooseDiceRollInstrument = GameGlobals.players.Count; //is not performed to ensure this phase is only played once
            preferredInstrumentsChoosen = true;
        }

        //end of second phase; trigger third phase
        if (numPlayersToLevelUp == 0)
        {
            //Debug.Log("running2...");
            StartPlayForInstrumentPhase();
            numPlayersToLevelUp = GameGlobals.players.Count;
        }

        //end of third phase;
        if (numPlayersToPlayForInstrument == 0)
        {
            if (checkedAlbumResult)
            {
                //Debug.Log("running3...");
                checkedAlbumResult = false;
                StartLastDecisionsPhase();
                numPlayersToPlayForInstrument = GameGlobals.players.Count;
            }
            else if (canSelectToCheckAlbumResult)
            {
                canSelectToCheckAlbumResult = false;
                if (GameProperties.configurableProperties.isSimulation) //if simulation just do it, with no loads!
                {
                    canCheckAlbumResult = true;
                }
                else
                {
                    //make phase UI active (this step is interim but must be done before last phase)
                    UIRollDiceForMarketValueScreen.SetActive(true);
                }
            }

            if (canCheckAlbumResult)
            {
                CheckAlbumResult();
                canCheckAlbumResult         = false;
                canSelectToCheckAlbumResult = true;

                if (!GameProperties.configurableProperties.isSimulation)
                {
                    UIRollDiceForMarketValueScreen.SetActive(false);
                }
            }
        }

        //end of forth phase; trigger and log album result
        if (numPlayersToStartLastDecisions == 0)
        {
            //Debug.Log("running4...");
            int numPlayedAlbums = GameGlobals.albums.Count;

            //write curr game logs
            GameGlobals.gameLogManager.WriteAlbumResultsToLog(GameGlobals.currSessionId.ToString(), GameGlobals.currGameId.ToString(), GameGlobals.currGameRoundId.ToString(), currAlbum.GetId().ToString(), currAlbum.GetName(), currAlbum.GetMarketingState().ToString());
            foreach (Player player in GameGlobals.players)
            {
                GameGlobals.gameLogManager.WritePlayerResultsToLog(GameGlobals.currSessionId.ToString(), GameGlobals.currGameId.ToString(), GameGlobals.currGameRoundId.ToString(), player.GetId().ToString(), player.GetName(), player.GetMoney().ToString());
            }

            numPlayersToStartLastDecisions = GameGlobals.players.Count;
            GameGlobals.currGameRoundId++;

            //start next game round whenever ready, but only if game hasn't finished
            if (GameGlobals.currGameState == GameProperties.GameState.NOT_FINISHED)
            {
                if (!GameProperties.configurableProperties.isSimulation)
                {
                    UIAddAlbumToCollection(currAlbum);
                    UInewRoundScreen.SetActive(true);
                }
                else
                {
                    StartGameRoundForAllPlayers("SimAlbum");
                }

                if (GameGlobals.albums.Count < GameProperties.configurableProperties.numberOfAlbumsPerGame)
                {
                    currSpeakingPlayerId = Random.Range(0, GameGlobals.numberOfSpeakingPlayers);
                    foreach (var player in GameGlobals.players)
                    {
                        player.InformNewAlbum();
                    }
                }
            }


            //enter international market on the next album, increase the number of dices played for market
            if (GameGlobals.currGameRoundId == marketLimit)
            {
                int oldNumberOfMarketDices = currNumberOfMarketDices;
                currNumberOfMarketDices++;

                //poppups are not displayed on simulations
                if (!GameProperties.configurableProperties.isSimulation)
                {
                    infoPoppupNeutralRef.DisplayPoppup("You gained some experience publishing your last albums and so you will try your luck on the international market. From now on, " + currNumberOfMarketDices + " dices (instead of " + oldNumberOfMarketDices + ") are rolled for the market.");
                }
            }


            //reinit some things for next game if game result is known or max albums are achieved
            if (GameGlobals.currGameState != GameProperties.GameState.NOT_FINISHED)
            {
                GameGlobals.currGameRoundId = 0;
                //GameGlobals.currGameState = GameProperties.GameState.NOT_FINISHED;
                Debug.Log("GameGlobals.currGameState: " + GameGlobals.currGameState);

                //move albums to root so they can be saved through scenes
                foreach (Album album in GameGlobals.albums)
                {
                    UIRemoveAlbumFromCollection(album);
                    album.GetAlbumUI().SetActive(false);          //do not show albums before final scene
                    Object.DontDestroyOnLoad(album.GetAlbumUI()); //can only be made after getting the object on root
                }

                if (GameGlobals.currGameState == GameProperties.GameState.LOSS)
                {
                    foreach (Player player in GameGlobals.players)
                    {
                        player.TakeAllMoney();
                    }

                    if (!GameProperties.configurableProperties.isSimulation)
                    {
                        endPoppupLossRef.DisplayPoppup("The band incurred in too much debt! No more albums can be produced!");
                    }
                }
                else
                {
                    if (!GameProperties.configurableProperties.isSimulation)
                    {
                        endPoppupWinRef.DisplayPoppup("The band had a successful journey! Congratulations!");
                    }
                }


                //players see the game result
                currSpeakingPlayerId = Random.Range(0, GameGlobals.numberOfSpeakingPlayers);
                foreach (Player player in GameGlobals.players)
                {
                    player.InformGameResult(GameGlobals.currGameState);
                }


                this.gameMainSceneFinished = true;
                if (!GameProperties.configurableProperties.isSimulation)
                {
                    UIadvanceRoundButton.gameObject.SetActive(false);
                    UIPrototypeArea.gameObject.SetActive(false);
                }
                else
                {
                    GameSceneManager.LoadEndScene();
                }
            }
        }
    }