Example #1
0
    void OnGUI()
    {
        //set demensions of the buttons

        if (Resources.Load("levels/level" + (GlobalFlags.getLevel() + 1)))
        {
            //System.IO.File.ReadAllLines("assets/levels/level" + (GlobalFlags.getLevel() + 1) + ".txt");
            //GlobalFlags.setLevel(GlobalFlags.getLevel() + 1);

            float buttonW = Screen.width / 2.8f;
            float buttonH = Screen.width / 6;

            GUIStyle style = new GUIStyle(GUI.skin.button);
            style.fontSize = (int)(buttonH / 2.8);

            //set the play game button
            float halfScreenW = (Screen.width / 4) - buttonW / 2;
            float halfScreenH = (Screen.height / 2) + 0;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Replay", style))
            {
                Application.LoadLevel("game");
            }

            halfScreenW = (3 * Screen.width / 4) - buttonW / 2;
            halfScreenH = (Screen.height / 2) + 0;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Play Next", style))
            {
                GlobalFlags.setLevel(GlobalFlags.getLevel() + 1);
                Application.LoadLevel("game");
            }

            //set the exit button
            halfScreenW = (Screen.width / 4) - buttonW / 2;
            halfScreenH = Screen.height / 2 + buttonH * 1.5f;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Level Select", style))
            {
                Application.LoadLevel("LevelSelectPreMenu");
            }

            //set the exit button
            halfScreenW = (3 * Screen.width / 4) - buttonW / 2;
            halfScreenH = Screen.height / 2 + buttonH * 1.5f;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Main Menu", style))
            {
                Application.LoadLevel("ModeSelectMenu");
            }
        }
        else
        {
            float buttonW = Screen.width / 2.8f;
            float buttonH = Screen.width / 6;

            GUIStyle style = new GUIStyle(GUI.skin.button);
            style.fontSize = (int)(buttonH / 2.8);

            //set the play game button
            float halfScreenW = (Screen.width / 4) - buttonW / 2;
            float halfScreenH = (Screen.height / 2) + 0;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Replay", style))
            {
                Application.LoadLevel("game");
            }

            halfScreenW = (3 * Screen.width / 4) - buttonW / 2;
            halfScreenH = (Screen.height / 2) + 0;
            if (GUI.Button(new Rect(halfScreenW, halfScreenH, buttonW, buttonH), "Main Menu", style))
            {
                Application.LoadLevel("ModeSelectMenu");
            }
        }
    }
Example #2
0
 // Use this for initialization
 void Start()
 {
     score.text = "Score: " + GlobalFlags.getScore();
     title.text = "Level: " + GlobalFlags.getLevel();
 }
Example #3
0
    /**
     * This has to be awake, as the levels have to be parsed before everything else calls the data
     * from the file. Depending on if the RandomLevel flag is flipped in the @GlobalFlag.cs class,
     * then a level will be generated randomly and without the use of a file.
     */
    void Awake()
    {
        bool randomLevel = GlobalFlags.getRandLevel();

        if (!randomLevel)
        {
            //TODO Once we have levels being set globally, get the level here from the global variables.
            try {
                TextAsset file       = (TextAsset)Resources.Load("levels/level" + GlobalFlags.getLevel());
                string    fileString = file.text;

                string[] lines = fileString.Split('\n');
                //string[] lines = System.IO.File.ReadAllLines("assets/Resources/levels/level" + GlobalFlags.getLevel() + ".txt");

                triArray  = new TriInfo[lines.Length - 1];                //first line of the level file is the queue for that level
                queueTris = lines[0].Split(',');
                for (int i = 1; i < lines.Length; i++)
                {
                    int     commaIndex = lines[i].IndexOf(',');
                    int     colonIndex = lines[i].IndexOf(':');
                    int     x          = int.Parse(lines[i].Substring(0, commaIndex));
                    int     y          = int.Parse(lines[i].Substring(commaIndex + 1, colonIndex - 1 - commaIndex));
                    string  colour     = lines[i].Substring(colonIndex + 1, lines[i].Length - 1 - colonIndex);
                    TriInfo triInfo    = new TriInfo(x, y, colour.Trim());

                    triArray[i - 1] = triInfo;                     // first "i" was for the queue
                }
            }
            catch (UnityException e) {
                Debug.Log("error reading file level" + GlobalFlags.getLevel() + ".txt");
                Debug.Log(e.StackTrace);
            }
        }
        else
        {
            //Loads a random level into the Triangle array
            int        negRandY = (int)Random.Range(1, RANDOM_LENGTH) * -1;
            int        randY    = (int)Random.Range(1, RANDOM_LENGTH);
            TriInfo [] temp     = new TriInfo[(RANDOM_LENGTH + Mathf.Abs(RANDOM_LENGTH) + 1) * (RANDOM_LENGTH + Mathf.Abs(RANDOM_LENGTH) + 1) - 1];

            //used to help make sure there is no complete cluster in the random level
            string [,] testComplete = new string[RANDOM_LENGTH * 2 + 1, RANDOM_LENGTH * 2 + 1];

            int arrLoc  = 0;
            int yLocTri = RANDOM_LENGTH - randY;             //y location  of the triangle in an array
            for (int i = randY; i >= negRandY; i--)
            {
                int negRandX = (int)Random.Range(1, RANDOM_LENGTH) * -1;
                int randX    = (int)Random.Range(1, RANDOM_LENGTH);

                int xLocTri = negRandX + RANDOM_LENGTH;                 //x location  of the triangle in an array
                for (int j = negRandX; j <= randX; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        testComplete[xLocTri, yLocTri] = "black";
                        xLocTri++;
                        continue;
                    }

                    string rColour = randomColour();
                    testComplete[xLocTri, yLocTri] = rColour;
                    while (hasCompleteTriangle(testComplete, false, xLocTri, yLocTri))
                    {
                        rColour = randomColour();
                        testComplete[xLocTri, yLocTri] = rColour;
                    }


                    TriInfo triInfo = new TriInfo(j, i, rColour);
                    temp[arrLoc] = triInfo;
                    arrLoc++;
                    xLocTri++;
                }
                yLocTri++;
            }

            triArray = new TriInfo[arrLoc];
            System.Array.Copy(temp, 0, triArray, 0, arrLoc);

            //loops over arbitrary number (just picked 20), to load the queue with that many random colours.
            queueTris = new string[40];
            for (int i = 0; i < queueTris.Length; i++)
            {
                queueTris[i] = randomColour();
            }
        }
    }