Esempio n. 1
0
    public static void Draw(int i, int j, int k)
    {
        //play audio
        AudioScript.PlayAudio("box");

        MainGameScript.Grid_Boxes[i, j, k].GetComponentsInChildren <MeshRenderer>()[0].material.color =
            MainGameScript._Players[Convert.ToInt32(MainGameScript.Player_2_Turn)];

        MainGameScript.Grid_Boxes[i, j, k].GetComponentsInChildren <MeshRenderer>()[0].enabled = true;
    }
Esempio n. 2
0
    private void startNewGame()
    {
        // Restart score and level
        gameOver = false;
        speed    = 1;
        score    = 0;
        backgroundPanel.SetActive(false);
        highScoreManager.HideHighScoreScreen();
        audioManager.SetGameOver(false);
        updateText();

        // Destroy all blocks
        for (int i = 0; i < blockGrid.GetLength(0); i++)
        {
            for (int j = 0; j < blockGrid.GetLength(1); j++)
            {
                GameObject blockObject = blockGrid[i, j];
                if (blockObject != null)
                {
                    Destroy(blockObject);
                    blockGrid[i, j] = null;
                }
            }
        }
        if (blockPair.leftBlock != null)
        {
            Destroy(blockPair.leftBlock.gameObject);
        }
        if (blockPair.rightBlock != null)
        {
            Destroy(blockPair.rightBlock.gameObject);
        }
        currentHeights = new int[6] {
            0, 0, 0, 0, 0, 0
        };

        // Add start blocks to column
        // AddBlockToColumn(blockPair.SpawnBlock("earth", 1).gameObject);
        // AddBlockToColumn(blockPair.SpawnBlock("air", 2).gameObject);
        // AddBlockToColumn(blockPair.SpawnBlock("water", 3).gameObject);
        // AddBlockToColumn(blockPair.SpawnBlock("fire", 4).gameObject);

        // // initialize block pair
        blockPair.isActive = true;
        blockPair.gameOver = false;
        blockPair.InitializePreviewBlocks();
        blockPair.InitializeBlockPair();

        flashPermanentAlert("");

        audioManager.PlayAudio();
    }
Esempio n. 3
0
    public static void Draw(char objType, int i, int j, int k)
    {
        //play audio
        AudioScript.PlayAudio("line");

        GameObject drawnLine = null;

        if (objType == 'X')
        {
            drawnLine = MainGameScript.Grid_LinesX[i, j, k];
        }
        else if (objType == 'Y')
        {
            drawnLine = MainGameScript.Grid_LinesY[i, j, k];
        }
        else if (objType == 'Z')
        {
            drawnLine = MainGameScript.Grid_LinesZ[i, j, k];
        }

        drawnLine.GetComponentsInChildren <MeshRenderer>()[0].enabled = true;

        if (objType == 'X')
        {
            if (j == 0)
            {
                if (k == 0)
                {
                    if (!MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (k == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i, j, k - 1))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i, j, k - 1) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }

            else if (j == MainGameScript.GRID_SIZE)
            {
                if (k == 0)
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (k == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k - 1))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k - 1) &
                        !MainGameScript.UpdateBox(i, j - 1, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }
            else
            {
                if (k == 0)
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (k == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k - 1) &
                        !MainGameScript.UpdateBox(i, j, k - 1))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k - 1) &
                        !MainGameScript.UpdateBox(i, j - 1, k) &
                        !MainGameScript.UpdateBox(i, j, k - 1) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }
        }

        else if (objType == 'Y')
        {
            if (i == 0)
            {
                if (k == 0)
                {
                    if (!MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (k == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i, j, k - 1))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i, j, k - 1) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }

            else if (i == MainGameScript.GRID_SIZE)
            {
                if (k == 0)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (k == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k - 1))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k - 1) &
                        !MainGameScript.UpdateBox(i - 1, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }
            else
            {
                if (k == 0)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (k == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k - 1) &
                        !MainGameScript.UpdateBox(i, j, k - 1))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k - 1) &
                        !MainGameScript.UpdateBox(i - 1, j, k) &
                        !MainGameScript.UpdateBox(i, j, k - 1) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }
        }

        else if (objType == 'Z')
        {
            if (i == 0)
            {
                if (j == 0)
                {
                    if (!MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (j == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i, j - 1, k) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }

            else if (i == MainGameScript.GRID_SIZE)
            {
                if (j == 0)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (j == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j - 1, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i - 1, j - 1, k) &
                        !MainGameScript.UpdateBox(i - 1, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }
            else
            {
                if (j == 0)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j, k) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else if (j == MainGameScript.GRID_SIZE)
                {
                    if (!MainGameScript.UpdateBox(i - 1, j - 1, k) &
                        !MainGameScript.UpdateBox(i, j - 1, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
                else
                {
                    if (!MainGameScript.UpdateBox(i - 1, j - 1, k) &
                        !MainGameScript.UpdateBox(i - 1, j, k) &
                        !MainGameScript.UpdateBox(i, j - 1, k) &
                        !MainGameScript.UpdateBox(i, j, k))
                    {
                        MainGameScript.SwitchPlayer();
                    }
                }
            }
        }
    }
Esempio n. 4
0
    // Called when the user has pressed the mouse button while over the collider
    void OnMouseDown()
    {
        //if this is first dot to be clicked on by user
        if (MainGameScript.First_Dot)
        {
            //play audio
            AudioScript.PlayAudio("dot");

            //save first dot in main script
            MainGameScript.Dot_One = this.gameObject;

            //color first dot the current player's color, so user knows it was clicked
            this.gameObject.GetComponent <MeshRenderer>().material.color =
                MainGameScript._Players[Convert.ToInt32(MainGameScript.Player_2_Turn)];

            //sets FirstDot bool to false, so next dot will execute the contents of the else statement
            MainGameScript.First_Dot = false;

            //loops through all dots to enlarge selectable ones
            foreach (GameObject currentDot in MainGameScript.Grid_Dots)
            {
                //save the names of the first dot and the current dot in the array
                string thisDotName   = MainGameScript.Dot_One.name;
                string secondDotName = currentDot.name;

                //save integers of firstDotNames for line coordinates
                int[] firstDot = new int[] { (int)Char.GetNumericValue(thisDotName[1]),
                                             (int)Char.GetNumericValue(thisDotName[2]),
                                             (int)Char.GetNumericValue(thisDotName[3]) };

                //save integers of secondDotNames for line coordinates
                int[] secondDot = new int[] { (int)Char.GetNumericValue(secondDotName[1]),
                                              (int)Char.GetNumericValue(secondDotName[2]),
                                              (int)Char.GetNumericValue(secondDotName[3]) };

                //checks if the two dots are the same dot
                if (firstDot[0] == secondDot[0] && firstDot[1] == secondDot[1] && firstDot[2] == secondDot[2])
                {
                    //leave selectable for cancelling purposes
                }

                //checks if the dots have the same Y and Z values, which means they are on the same X plane
                else if (firstDot[1] == secondDot[1] && firstDot[2] == secondDot[2])
                {
                    //Determines if they are close enough to be valid
                    int difference = firstDot[0] - secondDot[0];
                    if (Math.Abs(difference) == 1)
                    {
                        currentDot.transform.localScale = new Vector3((MainGameScript.DOT_BASE_SCALE * bigScale), (MainGameScript.DOT_BASE_SCALE * bigScale), (MainGameScript.DOT_BASE_SCALE * bigScale));
                        currentDot.gameObject.GetComponent <MeshRenderer>().material.color = selectableCol;
                    }
                    else
                    {
                        currentDot.gameObject.GetComponent <SphereCollider>().enabled = false;
                    }
                }
                //checks if the dots have the same X and Z values, which means they are on the same Y plane
                else if (firstDot[0] == secondDot[0] && firstDot[2] == secondDot[2])
                {
                    //Determines if they are close enough to be valid
                    int difference = firstDot[1] - secondDot[1];
                    if (Math.Abs(difference) == 1)
                    {
                        currentDot.transform.localScale = new Vector3((MainGameScript.DOT_BASE_SCALE * bigScale), (MainGameScript.DOT_BASE_SCALE * bigScale), (MainGameScript.DOT_BASE_SCALE * bigScale));
                        currentDot.gameObject.GetComponent <MeshRenderer>().material.color = selectableCol;
                    }
                    else
                    {
                        currentDot.gameObject.GetComponent <SphereCollider>().enabled = false;
                    }
                }
                //checks if the dots have the same X and Y values, which means they are on the same Z plane
                else if (firstDot[0] == secondDot[0] && firstDot[1] == secondDot[1])
                {
                    //Determines if they are close enough to be valid
                    int difference = firstDot[2] - secondDot[2];
                    if (Math.Abs(difference) == 1)
                    {
                        currentDot.transform.localScale = new Vector3((MainGameScript.DOT_BASE_SCALE * bigScale), (MainGameScript.DOT_BASE_SCALE * bigScale), (MainGameScript.DOT_BASE_SCALE * bigScale));
                        currentDot.gameObject.GetComponent <MeshRenderer>().material.color = selectableCol;
                    }
                    else
                    {
                        currentDot.gameObject.GetComponent <SphereCollider>().enabled = false;
                    }
                }
                //catches the rest of the dots
                else
                {
                    currentDot.gameObject.GetComponent <SphereCollider>().enabled = false;
                }
            }
        }

        //if this is the second dot to be clicked on by user
        else
        {
            //play audio
            AudioScript.PlayAudio("dot");

            //loop through and deactivate each dot
            foreach (GameObject currentDot in MainGameScript.Grid_Dots)
            {
                currentDot.gameObject.GetComponent <SphereCollider>().enabled = false;
            }

            //save second dot in main script
            MainGameScript.Dot_Two = this.gameObject;

            //color second dot the current player's color, so user knows it was clicked
            this.gameObject.GetComponent <MeshRenderer>().material.color =
                MainGameScript._Players[Convert.ToInt32(MainGameScript.Player_2_Turn)];

            //save the names of two last dots from main script
            string firstDotName  = MainGameScript.Dot_One.name;
            string secondDotName = MainGameScript.Dot_Two.name;

            //save integers of firstDotNames for line coordinates
            int[] firstDot = new int[] { (int)Char.GetNumericValue(firstDotName[1]),
                                         (int)Char.GetNumericValue(firstDotName[2]),
                                         (int)Char.GetNumericValue(firstDotName[3]) };

            //save integers of secondDotNames for line coordinates
            int[] secondDot = new int[] { (int)Char.GetNumericValue(secondDotName[1]),
                                          (int)Char.GetNumericValue(secondDotName[2]),
                                          (int)Char.GetNumericValue(secondDotName[3]) };

            //checks if the dots are the same dot, deselects the original dot
            if (firstDot[0] == secondDot[0] && firstDot[1] == secondDot[1] && firstDot[2] == secondDot[2])
            {
                MainGameScript.ResetDots();
            }

            //checks if the dots have the same Y and Z values, which means they will draw a X line
            else if (firstDot[1] == secondDot[1] && firstDot[2] == secondDot[2])
            {
                //Determines which X line is drawn based on dot's X position relative to one another
                int difference = firstDot[0] - secondDot[0];
                if (difference == -1)
                {
                    MainGameScript._currLine = ("X" + firstDotName[1] + firstDotName[2] + firstDotName[3]);
                    MainGameScript.DisplayConfirmUI();
                }
                else if (difference == 1)
                {
                    MainGameScript._currLine = ("X" + secondDotName[1] + secondDotName[2] + secondDotName[3]);
                    MainGameScript.DisplayConfirmUI();
                }
            }
            //checks if the dots have the same X and Z values, which means they will draw a Y line
            else if (firstDot[0] == secondDot[0] && firstDot[2] == secondDot[2])
            {
                //Determines which Y line is drawn based on dot's Y position relative to one another
                int difference = firstDot[1] - secondDot[1];
                if (difference == -1)
                {
                    MainGameScript._currLine = ("Y" + firstDotName[1] + firstDotName[2] + firstDotName[3]);
                    MainGameScript.DisplayConfirmUI();
                }
                else if (difference == 1)
                {
                    MainGameScript._currLine = ("Y" + secondDotName[1] + secondDotName[2] + secondDotName[3]);
                    MainGameScript.DisplayConfirmUI();
                }
            }
            //checks if the dots have the same X and Y values, which means they will draw a Z line
            else if (firstDot[0] == secondDot[0] && firstDot[1] == secondDot[1])
            {
                //Determines which Z line is drawn based on dot's Z position relative to one another
                int difference = firstDot[2] - secondDot[2];
                if (difference == -1)
                {
                    MainGameScript._currLine = ("Z" + firstDotName[1] + firstDotName[2] + firstDotName[3]);
                    MainGameScript.DisplayConfirmUI();
                }
                else if (difference == 1)
                {
                    MainGameScript._currLine = ("Z" + secondDotName[1] + secondDotName[2] + secondDotName[3]);
                    MainGameScript.DisplayConfirmUI();
                }
            }
        }
    }