Ejemplo n.º 1
0
    public void ShowCompletedLevels()
    {
        try
        {
            StreamReader leveldata = new StreamReader(level_path.CreateLevelDataPath());

            using (leveldata)
            {
                string levels_complete = leveldata.ReadToEnd();
                int    level_number    = 1;

                foreach (char complete in levels_complete)
                {
                    if (complete == '1')
                    {
#if UNITY_EDITOR
                        GameObject _object = Instantiate(AssetDatabase.LoadAssetAtPath <GameObject>("Assets/Resources/StarCompleted.prefab"));
                        _object.transform.SetParent(GameObject.Find("Level " + level_number).transform);
                        _object.transform.localScale    = Vector3.one;
                        _object.transform.localPosition = Vector3.zero;
                        _object.tag = "LevelComplete";
                        _object.transform.SetAsFirstSibling();
#endif
                    }

                    level_number++;
                }

                leveldata.Close();
            }
        }
        catch (Exception except)
        {
            Debug.Log(except);
        }
    }
Ejemplo n.º 2
0
    void CheckIfLevelWon()
    {
        bool won = true;
        int  filled_square_count = 0;
        int  connected_count     = 0;

        for (int i = 0; i < width * width && won; i++)
        {
            bool found = false;

            for (int j = 0; j < number_of_flows && !found; j++)
            {
                if (paths[j].ConnectedSquares.Contains(grid[i].GetComponent <Square>()))
                {
                    filled_square_count++;
                    found = true;
                }
            }

            if (found)
            {
                if (grid[i].GetComponent <FlowEnd>() != null)
                {
                    if (grid[i].GetComponent <FlowEnd>().connected)
                    {
                        connected_count++;
                    }
                    else
                    {
                        won = false;
                    }
                }
            }
            else
            {
                won = false;
            }
        }

        if (won && (connected_count == (number_of_flows * 2)) && (filled_square_count == (width * width)))
        {
            Debug.Log("We won!!");

            try
            {
                string oldcontents, newcontents;

                StreamReader oldfile = new StreamReader(level_path.CreateLevelDataPath());
                using (oldfile)
                {
                    oldcontents = oldfile.ReadToEnd();
                    oldfile.Close();
                }

                //write completed level to file
                StreamWriter newfile = new StreamWriter(level_path.CreateLevelDataPath());

                using (newfile)
                {
                    int level_number = int.Parse(level_path.LevelName[6].ToString());
                    if (char.IsDigit(level_path.LevelName[7]))
                    {
                        level_number += int.Parse(level_path.LevelName[7].ToString());
                    }

                    newcontents = oldcontents.Substring(0, level_number - 1) + "1" + oldcontents.Substring(level_number);

                    newfile.Write(newcontents);
                    newfile.Close();
                }
            }
            catch (Exception except)
            {
                Debug.Log(except);
            }

            win_screen.SetActive(true);
            enabled = false;
        }
    }