Пример #1
0
    ////////////////////////////////////////////////
    //void OpponentSequence()                     //
    //Randomizes the opponents for arcade mode    //
    //Last three opponents will always be the same//
    ////////////////////////////////////////////////
    public void OpponentSequence()
    {
        Opponents[7] = -1;
        Opponents[8] = -2;
        Opponents[9] = -3;

        int[] temp = new int[] { 0, 1, 2, 3, 4, 5, 6 };
        temp = MathStuff.Shuffle(temp);

        for (int i = 0; i < temp.Length; i++)
        {
            Opponents[i] = temp[i];
        }
    }
Пример #2
0
    ///////////////////////////////////////////////////////
    //IEnumerator GarbageHandler()                       //
    //Handles incoming garbage blocks.                   //
    //Will apply no more than 7 garbage blocks per cycle.//
    ///////////////////////////////////////////////////////
    private IEnumerator GarbageHandler()
    {
        if (garbageType == 0)
        {
            bool[] temp = new bool[7];
            int    drop = 0;
            if (garbage >= 7)
            {
                drop     = 7;
                garbage -= 7;
            }

            else
            {
                drop    = garbage;
                garbage = 0;
            }

            for (int i = 0; i < drop; i++)
            {
                temp[i] = true;
            }

            MathStuff.Shuffle(temp);

            for (int i = 0; i < temp.Length; i++)
            {
                if (temp[i])
                {
                    GameObject block = Instantiate(MasterController.Blocks[4], new Vector3(-3 + i, 6, 0), Quaternion.identity);
                    block.GetComponent <BlockBehavior>().playerBlock = true;
                    bool isFalling = block.GetComponent <BlockBehavior>().fall();

                    if (isFalling)
                    {
                        numFalling++;
                        fallStack.Push(block);
                    }
                }
            }

            while (numFalling > 0)
            {
                yield return(null);
            }

            while (fallStack.Count > 0)
            {
                GameObject tempObj = (GameObject)fallStack.Pop();

                int new_x = (int)tempObj.transform.position.x + x_correct;
                int new_y = (int)tempObj.transform.position.y + y_correct;

                board[new_x, new_y] = tempObj;
            }
        }

        else if (garbageType == 1)
        {
            int drop = 0;
            if (garbage >= 7)
            {
                drop     = 7;
                garbage -= 7;
            }

            else
            {
                drop    = garbage;
                garbage = 0;
            }

            Stack tempStack = new Stack();
            for (int i = 0; i < board_h; i++)
            {
                for (int k = 0; k < board_w; k++)
                {
                    if (board[k, i] != null && (board[k, i].tag.Equals("Block_Atk") || board[k, i].tag.Equals("Block_Con")))
                    {
                        tempStack.Push(board[k, i]);
                    }
                }
            }

            if (tempStack.Count < drop)
            {
                drop = tempStack.Count;
            }

            GameObject[] temp = new GameObject[tempStack.Count];

            for (int i = 0; i < temp.Length; i++)
            {
                temp[i] = (GameObject)tempStack.Pop();
            }

            MathStuff.Shuffle(temp);

            for (int i = 0; i < drop; i++)
            {
                GameObject tempObj = Instantiate(MasterController.Blocks[4], temp[i].transform.position, Quaternion.identity);;
                tempObj.GetComponent <BlockBehavior>().playerBlock = true;

                int new_x = (int)tempObj.transform.position.x + x_correct;
                int new_y = (int)tempObj.transform.position.y + y_correct;

                board[new_x, new_y] = tempObj;
                Destroy(temp[i]);
            }
        }

        else if (garbageType == 2)
        {
            int drop = 0;
            if (garbage >= 7)
            {
                drop     = 7;
                garbage -= 7;
            }

            else
            {
                drop    = garbage;
                garbage = 0;
            }

            Stack tempStack = new Stack();
            for (int i = 0; i < board_h; i++)
            {
                for (int k = 0; k < board_w; k++)
                {
                    if (board[k, i] != null && (board[k, i].tag.Equals("Block_Mag") || board[k, i].tag.Equals("Block_Sup")))
                    {
                        tempStack.Push(board[k, i]);
                    }
                }
            }

            if (tempStack.Count < drop)
            {
                drop = tempStack.Count;
            }

            GameObject[] temp = new GameObject[tempStack.Count];

            for (int i = 0; i < temp.Length; i++)
            {
                temp[i] = (GameObject)tempStack.Pop();
            }

            MathStuff.Shuffle(temp);

            for (int i = 0; i < drop; i++)
            {
                GameObject tempObj = Instantiate(MasterController.Blocks[4], temp[i].transform.position, Quaternion.identity);;
                tempObj.GetComponent <BlockBehavior>().playerBlock = true;

                int new_x = (int)tempObj.transform.position.x + x_correct;
                int new_y = (int)tempObj.transform.position.y + y_correct;

                board[new_x, new_y] = tempObj;
                Destroy(temp[i]);
            }
        }

        yield return(new WaitForSeconds(0.5f));
    }