Example #1
0
    void LoadHiscores()
    {
        Debug.Log("Load pref");
        string prefString = PlayerPrefs.GetString(prefKey);

        if (prefString != null)
        {
            HiscoreList loadedList = JsonUtility.FromJson <HiscoreList>(prefString);
            if (loadedList != null)
            {
                hiscoreList = loadedList.list;
            }
        }
    }
Example #2
0
    public bool NewHiscore(string level, HiscoreEntry entry)
    {

        int i;
        for (i = 0; i < hscores.Count; i++)
        {
            if (hscores[i].name == level)
                break;
        }

        //If it's a new level
        if (i == hscores.Count)
        {
            HiscoreList newHSList = new HiscoreList();
            newHSList.name = level;
            newHSList.list[0] = entry;

            hscores.Add(newHSList);
            createHiscoresFile();
            return true;
        }
        //If it's not
        else
        {
            bool found = false;
            HiscoreEntry temporal = null;

            for (int z = 0; z < hscores[i].list.Length; z++)
            {
                //If the position hasn't been found
                if (!found)
                {
                    //If this position is unnasigned
                    if (hscores[i].list[z] == null || hscores[i].list[z].name == "" || hscores[i].list[z].points == -1)
                    {
                        hscores[i].list[z] = entry;
                        found = true;
                        break;
                    }
                    //If this possition is assigned and worse
                    else if (entry.points > hscores[i].list[z].points)
                    {
                        temporal = hscores[i].list[z];
                        hscores[i].list[z] = entry;
                        found = true;
                    }
                }
                //If has been found, move this position to the right
                else
                {
                    HiscoreEntry tp2 = hscores[i].list[z];
                    hscores[i].list[z] = temporal;
                    temporal = tp2;
                }
            }

            if (found)
            {
                createHiscoresFile();
                return true;
            }
            else
                return false;

        }

    }
Example #3
0
    public bool NewHiscore(string level, HiscoreEntry entry)
    {
        int i;

        for (i = 0; i < hscores.Count; i++)
        {
            if (hscores[i].name == level)
            {
                break;
            }
        }

        //If it's a new level
        if (i == hscores.Count)
        {
            HiscoreList newHSList = new HiscoreList();
            newHSList.name    = level;
            newHSList.list[0] = entry;

            hscores.Add(newHSList);
            createHiscoresFile();
            return(true);
        }
        //If it's not
        else
        {
            bool         found    = false;
            HiscoreEntry temporal = null;

            for (int z = 0; z < hscores[i].list.Length; z++)
            {
                //If the position hasn't been found
                if (!found)
                {
                    //If this position is unnasigned
                    if (hscores[i].list[z] == null || hscores[i].list[z].name == "" || hscores[i].list[z].points == -1)
                    {
                        hscores[i].list[z] = entry;
                        found = true;
                        break;
                    }
                    //If this possition is assigned and worse
                    else if (entry.points > hscores[i].list[z].points)
                    {
                        temporal           = hscores[i].list[z];
                        hscores[i].list[z] = entry;
                        found = true;
                    }
                }
                //If has been found, move this position to the right
                else
                {
                    HiscoreEntry tp2 = hscores[i].list[z];
                    hscores[i].list[z] = temporal;
                    temporal           = tp2;
                }
            }

            if (found)
            {
                createHiscoresFile();
                return(true);
            }
            else
            {
                return(false);
            }
        }
    }
Example #4
0
    private bool loadHiscores()
    {
        if (!System.IO.File.Exists("scr.txt"))
            return false;

        XmlDocument xmlDoc = new XmlDocument();
        xmlDoc = new XmlDocument();

        string txt = System.IO.File.ReadAllText("scr.txt");
        xmlDoc.LoadXml(txt);

        XmlNodeList nodes = xmlDoc.SelectNodes("SCORES/Level");
        if (nodes == null)
            return false;

        for (int i = 0; i < nodes.Count; i++)
        {

            XmlAttribute id = nodes[i].Attributes["id"];
            if (id == null || id.Value == null || id.Value == "")
                return false;

            HiscoreList list = new HiscoreList();
            list.name = id.Value;

            if (nodes[i].ChildNodes.Count > 10)
                return false;

            for (int entry = 0; entry < nodes[i].ChildNodes.Count; entry++)
            {
                if (nodes[i].ChildNodes[entry].Name != "Entry")
                    return false;

                if (nodes[i].ChildNodes[entry].ChildNodes.Count != 2)
                    return false;

                if (nodes[i].ChildNodes[entry].ChildNodes[0].Name != "Name"
                    || nodes[i].ChildNodes[entry].ChildNodes[1].Name != "Score")
                    return false;

                HiscoreEntry hsentry = new HiscoreEntry();
                hsentry.name = nodes[i].ChildNodes[entry].ChildNodes[0].InnerText;

                int result;
                if (int.TryParse(nodes[i].ChildNodes[entry].ChildNodes[1].InnerText, out result))
                {
                    hsentry.points = result;
                }
                else return false;

                list.list[entry] = hsentry;

            }

            hscores.Add(list);

        }
        
        return true;
    }
Example #5
0
    private bool loadHiscores()
    {
        if (!System.IO.File.Exists("scr.txt"))
        {
            return(false);
        }

        XmlDocument xmlDoc = new XmlDocument();

        xmlDoc = new XmlDocument();

        string txt = System.IO.File.ReadAllText("scr.txt");

        xmlDoc.LoadXml(txt);

        XmlNodeList nodes = xmlDoc.SelectNodes("SCORES/Level");

        if (nodes == null)
        {
            return(false);
        }

        for (int i = 0; i < nodes.Count; i++)
        {
            XmlAttribute id = nodes[i].Attributes["id"];
            if (id == null || id.Value == null || id.Value == "")
            {
                return(false);
            }

            HiscoreList list = new HiscoreList();
            list.name = id.Value;

            if (nodes[i].ChildNodes.Count > 10)
            {
                return(false);
            }

            for (int entry = 0; entry < nodes[i].ChildNodes.Count; entry++)
            {
                if (nodes[i].ChildNodes[entry].Name != "Entry")
                {
                    return(false);
                }

                if (nodes[i].ChildNodes[entry].ChildNodes.Count != 2)
                {
                    return(false);
                }

                if (nodes[i].ChildNodes[entry].ChildNodes[0].Name != "Name" ||
                    nodes[i].ChildNodes[entry].ChildNodes[1].Name != "Score")
                {
                    return(false);
                }

                HiscoreEntry hsentry = new HiscoreEntry();
                hsentry.name = nodes[i].ChildNodes[entry].ChildNodes[0].InnerText;

                int result;
                if (int.TryParse(nodes[i].ChildNodes[entry].ChildNodes[1].InnerText, out result))
                {
                    hsentry.points = result;
                }
                else
                {
                    return(false);
                }

                list.list[entry] = hsentry;
            }

            hscores.Add(list);
        }

        return(true);
    }