Exemplo n.º 1
0
    void Update()
    {
        //Waiting for step1
        if (!dialoguesCompleted[0])
        {
            Vector3 entryPos = myMap.getEntranceBarrierPos();
            if (!myMap.getTrainsPosSet().Contains(myMap.TwoDToOneD((int)entryPos[0] + 1, (int)entryPos[1]))) // Step 1 Fullfiled
            {
                dialoguesCompleted[0] = true;
                // Replace
                dialogues[0].SetActive(false);
                dialogues[1].SetActive(true);
            }
            else
            {
                return;
            }
        }

        //Waiting for step2
        if (!dialoguesCompleted[1])
        {
            Vector3 entryPos = myMap.getEntranceBarrierPos();
            if (!myMap.getCarsPosSet().Contains(myMap.TwoDToOneD((int)entryPos[0], (int)entryPos[1]))) // Step 2 Fullfiled
            {
                dialoguesCompleted[1] = true;
                // Replace
                dialogues[1].SetActive(false);
                dialogues[2].SetActive(true);
            }
            else
            {
                return;
            }
        }

        //Waiting for step3
        if (!dialoguesCompleted[2])
        {
            Vector3 exitPos = myMap.getExitPos();
            if (!myMap.getTrainsPosSet().Contains(myMap.TwoDToOneD((int)exitPos[0] - 1, (int)exitPos[1])) &&
                !myMap.getTrainsPosSet().Contains(myMap.TwoDToOneD((int)exitPos[0] - 2, (int)exitPos[1])))  // Step 3 Fullfiled
            {
                dialoguesCompleted[2] = true;
                // Replace
                dialogues[2].SetActive(false);
                dialogues[3].SetActive(true);
            }
            else
            {
                return;
            }
        }
        //Waiting for step4
        if (!dialoguesCompleted[3])
        {
            if (GameObject.Find("ACarObject0") == null) // Step 4 Fullfiled
            {
                dialoguesCompleted[3] = true;
                // Replace
                dialogues[3].SetActive(false);
                finishDialogues = true;
            }
            else
            {
                return;
            }
        }
    }
Exemplo n.º 2
0
    private bool determineMove(int dx, int dy)
    {
        if (dx == 0 && dy == 0)
        {
            return(false);
        }

        // the position of left side of the car
        float leftx  = transform.position.x + dx + leftOffset;
        float rightx = transform.position.x + dx + rightOffset;

        float nx = transform.position.x + dx + centerOffset;
        int   ny = (int)transform.position.y + dy;

        if (isExit((int)leftx + 1, ny) && currentTime > timeToRemoveTheCar)
        {
            myGameManager.showBlueCarText();
            return(false);
        }
        // in Enter, Can't Go Back
        if (isEntry((int)(transform.position.x + leftOffset), (int)(transform.position.x + rightOffset), (int)transform.position.y) && dx == -1)
        {
            return(false);
        }

        // detect whether there is a wall in the front part of the car or back part of the car.
        if (isWall((int)leftx, ny) || isWall((int)rightx, ny))
        {
            return(false);
        }

        if (dx == 1 && isCar((int)rightx, ny))
        {
            return(false);
        }
        else if (dx == -1 && isCar((int)leftx, ny))
        {
            return(false);
        }
        else if (dx == 0 && (isCar((int)leftx, ny) || isCar((int)rightx, ny)))
        { // when car move up or move down
            return(false);
        }


        // Only check the levels that have gates (Level 3 ~ Level 7)
        if (myMap.isLevelThree() || myMap.isLevelFour() || myMap.isLevelFive() || myMap.isLevelSix() || myMap.isLevelSeven())
        {
            // detect whether there is a gate in the front part of the car or back part of the car.
            if (isGate((int)leftx, ny) || isGate((int)rightx, ny))
            {
                for (int i = 0; i < myMap.gate_pos.Count; i++)
                {
                    if ((myMap.gate_pos[i].Key == (int)leftx || myMap.gate_pos[i].Key == (int)rightx) && (myMap.gate_pos[i].Value == ny))
                    {
                        if (myMap.isLevelThree())
                        {
                            if (i < 2 && myMap.gateOne.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if (i >= 2 && myMap.gateTwo.activeInHierarchy)
                            {
                                return(false);
                            }
                        }
                        else if (myMap.isLevelFour())
                        {
                            if (i == 0 && myMap.l4GateOne.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if ((i == 1 || i == 2) && myMap.l4GateTwo.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if ((i == 3 || i == 4) && myMap.l4GateThree.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if (i == 5 && myMap.l4GateFour.activeInHierarchy)
                            {
                                return(false);
                            }
                        }
                        else if (myMap.isLevelFive())
                        {
                            if (i == 0 && myMap.l5GateOne.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if (i == 1 && myMap.l5GateTwo.activeInHierarchy)
                            {
                                return(false);
                            }
                        }
                        else if (myMap.isLevelSix())
                        {
                            if ((i == 0 || i == 1) && myMap.l6GateOne.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if (i == 2 && myMap.l6GateTwo.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if (i >= 3 && i <= 9 && myMap.l6GateThree.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if (i >= 10 && i <= 13 && myMap.l6GateFour.activeInHierarchy)
                            {
                                return(false);
                            }
                        }
                        else if (myMap.isLevelSeven())
                        {
                            if ((i == 0 || i == 1) && myMap.l7GateOne.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if ((i == 2 || i == 3) && myMap.l7GateTwo.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if ((i == 4 || i == 5) && myMap.l7GateThree.activeInHierarchy)
                            {
                                return(false);
                            }
                            else if ((i == 6 || i == 7) && myMap.l7GateFour.activeInHierarchy)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
        }

        // Determine earned tips when leave at exit
        if (isExit((int)rightx, ny))
        {
            if (myMap.multi_exit_pos_set.Count == 1)
            {
                updateTips();
            }
            else if (myMap.multi_exit_pos_set.Count == 2)
            {
                // Determine if car goes out from the correct exit
                // Car can't go out from the wrong exit
                if (myMap.isLevelThree())
                {
                    string  label    = gameObject.name.Substring(0, 1);
                    Vector3 exitPos  = myMap.getExitPos();
                    int     exitOneX = (int)exitPos[0];
                    int     exitOneY = (int)exitPos[1];
                    List <KeyValuePair <int, int> > exitPos2 = myMap.multi_exit_pos_set;
                    int exitTwoX = (int)exitPos2[0].Key;
                    int exitTwoY = (int)exitPos2[0].Value;
                    if (string.Equals(label, "A") && (int)rightx == exitTwoX && ny == exitTwoY)
                    {
                        updateTips();
                    }
                    else if (string.Equals(label, "B") && (int)rightx == exitOneX && ny == exitOneY)
                    {
                        updateTips();
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    updateTips();
                }
            }
        }

        if (isBelt())
        {
            moveCarOnBelt(nx, ny, (int)rightx, (int)leftx);
        }
        else
        {
            moveCar(nx, ny, (int)rightx, (int)leftx);
        }

        if (isExit((int)rightx, ny))
        {
            if (!minusTip)
            {
                myGameManager.showTip10();
            }
            myMap.removeCars((int)leftx, ny);
            myMap.removeCars((int)rightx, ny);
            myGameManager.setSelectedCar(null);
            Destroy(gameObject);
        }

        return(true);
    }