Example #1
0
    // Spawns the players and moves them to the Start field.
    IEnumerator spawnPlayer()
    {
        Debug.Log("SpawnPlayer Ienum");
        isSpawningPlayers = true;


        // spawn the players
        for (int i = 0; i < playerCount; ++i)
        {
            float t = 0f;

            // create a list of players in menu and don't destroy on load


            GameObject gamer = Instantiate(Resources.Load("Prefabs/Player")) as GameObject;
            sprite = gamer.GetComponent <SpriteRenderer>();
            sprite.sortingOrder = -1;
            gamer.name          = "Player_" + (i + 1); // Gameobjects name doesn't really matter
            gamer.tag           = "Player";

            gamer.GetComponent <Player> ().ID             = gamestate.player_cars[i];
            gamer.GetComponent <Player> ().Name           = "Player_" + (i + 1);
            gamer.GetComponent <Player> ().HasFinished    = false;
            gamer.GetComponent <Player> ().CurrentFieldID = 0;
            gamer.GetComponent <Player> ().beast          = 0;

            PersistentInfo.Pinfo pinfo = new PersistentInfo.Pinfo();
            pinfo.playerID    = gamestate.player_cars[i];
            pinfo.playerNum   = i;
            pinfo.playerName  = "Player_" + (i + 1);
            pinfo.hasFinished = false;
            pinfo.fieldID     = 0;
            pinfo.beast       = 0;

            Vector3 startPosition = gamer.transform.position;
            Vector3 endPosition   = field [0].transform.position + playerSlots[i];

            // lerp the player to the starting field
            while (t < 1f)
            {
                t += Time.deltaTime * 4f;

                gamer.transform.position = Vector3.Lerp(startPosition, endPosition, t);

                yield return(null);
            }

            // add to players list
            pinfo.playerPos = gamer.transform.position;
            PersistentInfo.instance.pinfos.Add(pinfo.playerNum, pinfo);
            player.Add(gamer.GetComponent <Player>());

            yield return(null);
        }

        isSpawningPlayers = false;

        //Destroy (gamestate);
        yield return(0);
    }
Example #2
0
    public void spawnSinglePlayer(PersistentInfo.Pinfo playerInfo)
    {
        Debug.Log("Spawn single player: ");
        isSpawningPlayers = true;
        GameObject gamer = Instantiate(Resources.Load("Prefabs/Player")) as GameObject;

        sprite = gamer.GetComponent <SpriteRenderer>();
        sprite.sortingOrder = -1;
        gamer.name          = "Player_" + (playerInfo.playerNum + 1); // Gameobjects name doesn't really matter
        gamer.tag           = "Player";

        gamer.GetComponent <Player>().ID          = playerInfo.playerID;
        gamer.GetComponent <Player>().Name        = playerInfo.playerName;
        gamer.GetComponent <Player>().HasFinished = playerInfo.hasFinished;
        Debug.Log(gamer.name + ": " + playerInfo.fieldID);
        gamer.GetComponent <Player>().CurrentFieldID = playerInfo.fieldID;
        gamer.GetComponent <Player>().beast          = playerInfo.beast;
        Player p = gamer.GetComponent <Player>();

        p.playerNum = playerInfo.playerNum + 1;
        p.track     = playerInfo.track;
        p.gc        = this;
        player.Add(gamer.GetComponent <Player>());

        gamer.transform.position = field[(playerInfo.fieldID)].transform.position + playerSlots[playerInfo.playerID];
        isSpawningPlayers        = false;
    }
Example #3
0
    // Move the current Player to the target Position field by field
    IEnumerator moveForwards(int dicedNumber)
    {
        gc.isGamerMoving = true;

        // get the field the player is currently on
        int currentField = CurrentFieldID;

        if (currentField + dicedNumber > track.y)
        {
            dicedNumber = (int)track.y - currentField;
        }

        for (int i = 0; i < dicedNumber; i++)
        {
            float t = 0f;

            // increase the start- and endposition each iteration
            // startposition represents the field the player is on
            // endposition is always one field ahead of the players field
            // to make it look like the player moves one field at the time
            Vector3 startPosition = gc.field[(currentField + i)].transform.position + gc.playerSlots[ID];
            Vector3 endPosition   = gc.field[(currentField + i + 1)].transform.position + gc.playerSlots[ID];
            //Debug.Log("Player: "+ID+" FieldID: "+ CurrentFieldID+" StartPosition="+startPosition+" endPosition="+endPosition+" PlayerSlots: "+gc.playerSlots[ID].x+" "+gc.playerSlots[ID].y);
            float startZ = gc.field [(currentField + i)].transform.rotation.z;
            float endZ   = gc.field [(currentField + i + 1)].transform.rotation.z;

            // lerp to the next field
            while (t < 1f)
            {
                t += Time.deltaTime * 4f;

                transform.position = Vector3.Lerp(startPosition, endPosition, t);
                //Debug.Log ("Rotate angle z="+(endZ-startZ));
                transform.Rotate(0, 0, (endZ - startZ));
                yield return(null);
            }
            yield return(null);
        }
        // update the players current field
        CurrentFieldID = currentField + dicedNumber;
        Debug.Log("IN ACTION FIELD ID7: " + CurrentFieldID);
        PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer];
        pinfo.fieldID = CurrentFieldID;
        PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer] = pinfo;
        Debug.Log(pinfo.playerName + " : " + pinfo.fieldID);

        //move to the hospital and need to pop up menu

        if (gc.field[CurrentFieldID].Type == FieldType.Finish)
        {
            HasFinished = true;
            Debug.Log("IN ACTION FIELD ID8: " + CurrentFieldID);
            PersistentInfo.Pinfo pin = PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer];
            pin.hasFinished = HasFinished;
            PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer] = pin;
            gc.winner.Add(this);

            if (gc.stopWhenFirstPlayerHasFinished)
            {
                gc.isGameOver = false;
            }
            else
            {
                gc.isGameOver = gc.IsGameOver();
            }
            yield return(new WaitForSeconds(0.15f));
        }

        // this player has finished moving

        // wait a little
        yield return(new WaitForSeconds(0.1f));

        gc.isGamerMoving   = false;
        gc.waitForYourTurn = false;

        yield return(0);
    }
Example #4
0
    public void Action()
    {
        if (gc.inAction)
        {
            if (gc.field[CurrentFieldID].Type == FieldType.Action && gc.field[CurrentFieldID].Action == ActionType.GoToField)
            {
                cc = GameObject.FindGameObjectWithTag("ChoosePanel").GetComponent <ChooseCharacters>();
                cc.setActive(true);
                if (cc.isChoosen && cc.choice > 0)
                {
                    track = gc.tracks[cc.choice - 1];

                    CurrentFieldID = (int)track.x;
                    Debug.Log("IN ACTION FIELD ID: " + CurrentFieldID);
                    PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer];
                    pinfo.fieldID = CurrentFieldID;
                    pinfo.track   = track;
                    Debug.Log("Track: " + track);
                    PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer] = pinfo;
                    transform.position = gc.field[CurrentFieldID].transform.position + gc.playerSlots[ID];
                    cc.reset();


                    //gc.resetPlayer();
                    if (PersistentInfo.instance.goToGame)
                    {
                        PersistentInfo.instance.goToGame    = false;
                        PersistentInfo.instance.remakeScene = true;
                        gc.inAction = false;
                        int randScene = UnityEngine.Random.Range(6, 8);
                        SceneManager.LoadScene(randScene);
                    }
                    cc.setActive(false);
                }
            }
            else if (gc.field[CurrentFieldID].Type == FieldType.Action && gc.field[CurrentFieldID].Action == ActionType.GoBack &&
                     gc.field[CurrentFieldID].GoBackNumSteps != 0)
            {
                string msg = "Move back " + gc.field[CurrentFieldID].GoBackNumSteps + " cells";
                StartCoroutine(showMessage(msg));
                CurrentFieldID = (int)(CurrentFieldID - gc.field[CurrentFieldID].GoBackNumSteps);
                Debug.Log("IN ACTION FIELD ID2: " + CurrentFieldID);
                PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer];
                pinfo.fieldID = CurrentFieldID;
                PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer] = pinfo;
                transform.position = gc.field[CurrentFieldID].transform.position + gc.playerSlots[ID];
                gc.resetPlayer();
            }
            else if (gc.field[CurrentFieldID].Type == FieldType.Action && gc.field[CurrentFieldID].Action == ActionType.GoAhead &&
                     gc.field[CurrentFieldID].GoAheadNumSteps != 0)
            {
                string msg = "Move ahead " + gc.field[CurrentFieldID].GoAheadNumSteps + " cells";
                StartCoroutine(showMessage(msg));
                CurrentFieldID = (int)(CurrentFieldID + gc.field[CurrentFieldID].GoAheadNumSteps);
                Debug.Log("IN ACTION FIELD ID3: " + CurrentFieldID);
                PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer];
                pinfo.fieldID = CurrentFieldID;
                PersistentInfo.instance.pinfos[PersistentInfo.instance.currentPlayer] = pinfo;
                transform.position = gc.field[CurrentFieldID].transform.position + gc.playerSlots[ID];
                gc.resetPlayer();
            }
            else if (gc.field[CurrentFieldID].Type == FieldType.Action && gc.field[CurrentFieldID].Action == ActionType.Action)
            {
                // if the action cell is between home to hospital: appear purple card track:(0,25) ;beast card(0,13)
                if (0 <= CurrentFieldID && CurrentFieldID <= 26)
                {
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().randomIndex = UnityEngine.Random.Range(0, 13);
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().setActive(true);
                }
                // if the action cell is in the first track. This is Stan's track:(26,52); beast card(44,58)
                else if (26 <= CurrentFieldID && CurrentFieldID <= 51)
                {
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().randomIndex = UnityEngine.Random.Range(44, 58);
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().setActive(true);
                }
                // if the action cell is in the second track. This is Sugar Ray's track(53,78); beast card(59,73)
                else if (53 <= CurrentFieldID && CurrentFieldID <= 77)
                {
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().randomIndex = UnityEngine.Random.Range(59, 73);
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().setActive(true);
                }
                // if the action cell is in the third track. This is Dora's track(79,104); beast card(14,28)
                else if (79 <= CurrentFieldID && CurrentFieldID <= 103)
                {
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().randomIndex = UnityEngine.Random.Range(14, 28);
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().setActive(true);
                }
                // if the action cell is in the fourth track. This is Sid's track(105,130); beast card(29,43)
                else if (105 <= CurrentFieldID && CurrentFieldID <= 129)
                {
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().randomIndex = UnityEngine.Random.Range(29, 43);
                    GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().setActive(true);
                }
                int new_beast = beast;
                new_beast += GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().points[GameObject.FindGameObjectWithTag("beastCard").GetComponent <cards>().randomIndex];

                if (0 <= new_beast && new_beast < 7)
                {
                    Debug.Log("IN ACTION FIELD ID4: " + CurrentFieldID);
                    PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[gc.currentPlayer];
                    pinfo.beast = new_beast;
                    PersistentInfo.instance.pinfos[gc.currentPlayer] = pinfo;
                    beast = new_beast;
                }
                else if (new_beast < 0)
                {
                    Debug.Log("IN ACTION FIELD ID5: " + CurrentFieldID);
                    PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[gc.currentPlayer];
                    pinfo.beast = 0;
                    PersistentInfo.instance.pinfos[gc.currentPlayer] = pinfo;
                    beast = 0;
                }

                else if (new_beast > 6)
                {
                    Debug.Log("IN ACTION FIELD ID6: " + CurrentFieldID);
                    PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[gc.currentPlayer];
                    pinfo.beast = 6;
                    PersistentInfo.instance.pinfos[gc.currentPlayer] = pinfo;
                    beast = 6;
                }


                gc.resetPlayer();
            }

            else if (gc.field[CurrentFieldID].Type == FieldType.Action && gc.field[CurrentFieldID].Action == ActionType.Question)
            {
                // move to the question cell and need the quesiton panel set active;
                if (!gc.questionPanel.activeSelf)
                {
                    qc = GameObject.FindGameObjectWithTag("questionCard").GetComponent <questioncard>();
                    if (random == 0)
                    {
                        qc.randomIndex = UnityEngine.Random.Range(0, 24);
                        random         = qc.randomIndex;
                    }
                    else
                    {
                        qc.randomIndex = random;
                    }
                    qc.setActive(true);

                    gc.questionPanel.SetActive(true);

                    // blocking other user from playing
                }
                if (loopCount == 0)
                {
                    GameObject.FindGameObjectWithTag("Text").GetComponent <textInput>().ranInt = random + 1;
                    loopCount += 1;
                }

                random = 0;
            }
            else if (gc.field[CurrentFieldID].Type == FieldType.Action && gc.field[CurrentFieldID].Action == ActionType.MultiQues)
            {
                if (!gc.multiQuestionPanel.activeSelf)
                {
                    gc.multiQuestionPanel.SetActive(true);
                    Debug.Log(gc.multiQuestionPanel.GetComponent <MultiQuesP>());
                    string[] all_questions = gc.multiQuestionPanel.GetComponent <MultiQuesP>().readFile();
                    int      maxLength     = all_questions.Length;
                    gc.multiQuestionPanel.GetComponent <MultiQuesP>().processText(all_questions, UnityEngine.Random.Range(0, maxLength));
                    gc.multiQuestionPanel.GetComponent <MultiQuesP>().showPanel();
                }
            }
            else
            {
                gc.resetPlayer();
            }
        }
    }
Example #5
0
    // two bugs. 1. after first click, only the second click will appear right/wrong sign.
    //           2. how to deactive the panel after show the answer.
    public IEnumerator CheckAnswer(Button b)
    {
        Debug.Log(b.name);
        bool right = false;

        if (ButtonNum < 3)
        {
            D.enabled = false;
            C.enabled = false;
            if (b.name == "ButtonA" && "A" == rightAnswer)
            {
                Awin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/right", typeof(Sprite)) as Sprite;
                Debug.Log("AButtonclickright");
                right = true;
            }
            else if (b.name == "ButtonA" && "A" != rightAnswer)
            {
                Awin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/wrong", typeof(Sprite)) as Sprite;
                Debug.Log("AButtonClickwrong");
            }
            else if (b.name == "ButtonB" && "B" == rightAnswer)
            {
                Bwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/right", typeof(Sprite)) as Sprite;
                Debug.Log("BButtonclickright");
                right = true;
            }
            else if (b.name == "ButtonB" && "B" != rightAnswer)
            {
                Bwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/wrong", typeof(Sprite)) as Sprite;
                Debug.Log("AButtonClickwrong");
            }
        }
        else
        {
            C.enabled = true;
            D.enabled = true;
            if (b.name == "ButtonA" && "A" == rightAnswer)
            {
                Awin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/right", typeof(Sprite)) as Sprite;
                Debug.Log("AButtonclickright");
                right = true;
            }
            else if (b.name == "ButtonA" && "A" != rightAnswer)
            {
                Awin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/wrong", typeof(Sprite)) as Sprite;
                Debug.Log("AButtonClickwrong");
            }
            else if (b.name == "ButtonB" && "B" == rightAnswer)
            {
                Bwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/right", typeof(Sprite)) as Sprite;
                Debug.Log("BButtonclickright");
                right = true;
            }
            else if (b.name == "ButtonB" && "B" != rightAnswer)
            {
                Bwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/wrong", typeof(Sprite)) as Sprite;
                Debug.Log("BButtonClickwrong");
            }
            else if (b.name == "ButtonC" && "C" == rightAnswer)
            {
                Cwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/right", typeof(Sprite)) as Sprite;
                Debug.Log("CButtonclickright");
                right = true;
            }
            else if (b.name == "ButtonC" && "C" != rightAnswer)
            {
                Cwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/wrong", typeof(Sprite)) as Sprite;
                Debug.Log("CButtonClickwrong");
            }
            else if (b.name == "ButtonD" && "D" == rightAnswer)
            {
                Dwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/right", typeof(Sprite)) as Sprite;
                Debug.Log("DButtonclickright");
                right = true;
            }
            else if (b.name == "ButtonD" && "D" != rightAnswer)
            {
                Dwin.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/wrong", typeof(Sprite)) as Sprite;
                Debug.Log("DButtonClickwrong");
            }
        }
        if (right)
        {
            card.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/card" + cardNum.ToString() + "/right", typeof(Sprite)) as Sprite;
            //    A.image.overrideSprite = Resources.Load<Sprite>("Multiple Choice UI/card" + cardNum.ToString() + "/A");
            newBeast = gc.player[gc.currentPlayer].beast - beastSize;
        }
        else
        {
            card.GetComponent <Image>().sprite = Resources.Load("Multiple Choice UI/card" + cardNum.ToString() + "/wrong", typeof(Sprite)) as Sprite;
            newBeast = gc.player[gc.currentPlayer].beast + beastSize;
        }

        if (0 <= newBeast && newBeast < 7)
        {
            PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[gc.currentPlayer];
            pinfo.beast = newBeast;
            PersistentInfo.instance.pinfos[gc.currentPlayer] = pinfo;

            gc.player[gc.currentPlayer].beast = newBeast;
        }
        else if (newBeast < 0)
        {
            gc.player[gc.currentPlayer].beast = 0;
            PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[gc.currentPlayer];
            pinfo.beast = 0;

            PersistentInfo.instance.pinfos[gc.currentPlayer] = pinfo;
        }

        else if (newBeast > 6)
        {
            gc.player[gc.currentPlayer].beast = 6;
            PersistentInfo.Pinfo pinfo = PersistentInfo.instance.pinfos[gc.currentPlayer];
            pinfo.beast = 6;
            PersistentInfo.instance.pinfos[gc.currentPlayer] = pinfo;
        }



        yield return(new WaitForSeconds(2));

        gc.multiQuestionPanel.SetActive(false);
        resetImage();
        gc.resetPlayer();
    }