Пример #1
0
    public void moveTo(GameObject go, int i, int j)
    {
        UnitBehaviour ub = go.GetComponent <UnitBehaviour> ();

        ub.moveAct();
        int pi = (int)go.transform.position.z;
        int pj = (int)go.transform.position.x;

        //List<position> movement = getPathBFS (pi, pj, i, j);
        //TODO: MOVEMENT

        if (ub.remainingActions == 0)
        {
            currentNumFinishedChars += 1;
        }
        //Move the unit
        go.transform.position = new Vector3(j, 0, i);
        //Update matrices
        unitMap.SetValue(null, pi, pj);
        unitMap.SetValue(go, i, j);
        ub.stopMoveAct();
    }
Пример #2
0
    void Start()
    {
        puzzleManager = GameObject.FindObjectOfType <PuzzleManager>();
        lights        = new GameObject[gridWidth, gridWidth];
        int indexH = 0;
        int indexV = 0;

        foreach (GameObject light in lightObjects)
        {
            lights.SetValue(light, indexH, indexV);
            if (indexH == 4)
            {
                indexV += 1;
                indexH  = 0;
            }
            else
            {
                indexH += 1;
            }
        }
    }
Пример #3
0
    /* If the playerSelected array is full of non initialized Vector3, then continue
     * If the selected objects are next to each other, then continue checking
     * If the game is not moving anything else, then continue
     */
    private bool isValidMove()
    {
        /* Makes sure that the player's moves are only valid while the board is not changing
         */
        if (wasChanged)
        {
            initializeMove();
            return(false);
        }

        //Checks if the playerSelected is full or not, if it is full then continue, else returns false
        foreach (Vector3 r in playerSelected)
        {
            if (r.Equals(new Vector3(-1f, -1f, -1f)))
            {
                return(false);
            }
        }

        /* Checks if the selected tiles are 1 apart ie. next to each other
         * The magnitude of the difference between two positions that are next to each other is 1
         * If they're not next to each other, then the older position is removed and the new one is kept
         */
        if ((playerSelected[0] - playerSelected[1]).magnitude != 1f)
        {
            Vector3 temp = playerSelected[1];
            initializeMove();
            playerSelected[0] = temp;
            return(false);
        }

        /* Holds the old fields in case the switch does not yield a valid move
         */
        GameObject[,] oldMatrix = new GameObject[matrix.GetLength(0), matrix.GetLength(1)];
        System.Array.Copy(matrix, oldMatrix, matrix.Length);

        Debug.Log("Old matrix");
        foreach (GameObject obj in matrix)
        {
            Debug.Log(obj.name + ": " + obj.tag + " " + obj.transform.localPosition.ToString());
        }

        List <MatchTwo> oldMatchTwos = new List <MatchTwo>();

        oldMatchTwos.AddRange(matchTwos);

        List <MatchThree> oldMatchThrees = new List <MatchThree>();

        oldMatchThrees.AddRange(matchThrees);

        /* Checks if the move creates a match three
         * If the move does create a match three, then wasChanged will be true and is a valid move
         * If the move does not create a match three, then wasChanged will be false and is an invalid move
         */
        GameObject[] holder = { matrix[(int)playerSelected[0].y, (int)playerSelected[0].x], matrix[(int)playerSelected[1].y, (int)playerSelected[1].x] };

        //Debug.Log(matrix[(int)playerSelected[0].y, (int)playerSelected[0].x].tag + "\n" + matrix[(int)playerSelected[1].y, (int)playerSelected[1].x].tag);
        matrix.SetValue(holder[0], (int)playerSelected[1].y, (int)playerSelected[1].x);
        matrix.SetValue(holder[1], (int)playerSelected[0].y, (int)playerSelected[0].x);
        matrix[(int)playerSelected[0].y, (int)playerSelected[0].x].transform.localPosition = playerSelected[0];
        matrix[(int)playerSelected[1].y, (int)playerSelected[1].x].transform.localPosition = playerSelected[1];

        /*
         * Debug.Log(matrix[(int)playerSelected[0].y, (int)playerSelected[0].x] + "\n" + matrix[(int)playerSelected[1].y, (int)playerSelected[1].x]);
         * Debug.Log(matrix[(int)playerSelected[0].y, (int)playerSelected[0].x].transform.localPosition + "\n" + matrix[(int)playerSelected[1].y, (int)playerSelected[1].x].transform.localPosition);
         * Debug.Log(matrix[(int)playerSelected[0].y, (int)playerSelected[0].x].tag + "\n" + matrix[(int)playerSelected[1].y, (int)playerSelected[1].x].tag);
         */

        checkForTwo();

        /*
         * foreach(MatchTwo m in matchTwos)
         * {
         *  Debug.Log(m.ToString());
         * }
         */

        checkForThree(matchTwos);

        /*
         * Debug.Log("New Match Threes");
         * foreach(MatchThree m in matchThrees)
         * {
         *  Debug.Log(m.ToString());
         * }
         */

        matrix.SetValue(holder[0], (int)playerSelected[0].y, (int)playerSelected[0].x);
        matrix.SetValue(holder[1], (int)playerSelected[1].y, (int)playerSelected[1].x);
        matrix[(int)playerSelected[0].y, (int)playerSelected[0].x].transform.localPosition = playerSelected[0];
        matrix[(int)playerSelected[1].y, (int)playerSelected[1].x].transform.localPosition = playerSelected[1];

        Debug.Log("Revert to old matrix");
        foreach (GameObject obj in matrix)
        {
            Debug.Log(obj.name + ": " + obj.tag + " " + obj.transform.localPosition.ToString());
        }

        return(matchThrees.Count > 0);
    }