Exemplo n.º 1
0
    private static void Save(TrackScores track)
    {
        //Debug.Log(track.names[0]);

        TrackScores[] curList = Load();

        if (curList == null || curList.Length == 0)
        {
            curList             = new TrackScores[1];
            curList[0]          = new TrackScores();
            curList[0].track    = track.track;
            curList[0].times[0] = track.times[0];
            curList[0].names[0] = track.names[0];
            //Debug.Log(curList[0].track);
            //Debug.Log(curList[0].times[0]);
            //Debug.Log(curList[0].names[0]);
        }
        else
        {
            //Debug.Log("its trying to save here");
            for (int i = 0; i < curList.Length; i++)
            {
                if (curList[i].track == track.track)
                {
                    curList[i].times = track.times;
                    curList[i].names = track.names;
                }
            }
        }
        //Debug.Log(curList[0].track);
        //Debug.Log(curList[0].times[0]);
        //Debug.Log(curList[0].names[0]);
        TrackScoresWrapper wrapper = new TrackScoresWrapper();

        wrapper.objects = curList;
        string jsonString = JsonUtility.ToJson(wrapper);

        //Debug.Log("Almost there, " + jsonString);

        File.Create(Application.persistentDataPath + fileName).Dispose();
        File.WriteAllText(Application.persistentDataPath + fileName, jsonString);
    }
Exemplo n.º 2
0
    //checks if score is high
    public static bool CheckScore(string trackName, string time)
    {
        TrackScores track = Load(trackName);

        float playerTime = Int32.Parse(time.Replace(":", ""));


        for (int i = 0; i < track.times.Length; i++)
        {
            if (playerTime < Int32.Parse(track.times [i].Replace(":", "")))
            {
                return(true);
            }
            if (track.times [i] == "" || track.times [i] == null)
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 3
0
 // Use this for initialization
 void Start()
 {
     checkedScore      = false;
     text              = GameObject.Find("LeaderboardBody").GetComponent <Text>();
     submittedNewScore = GameObject.Find("EnterName").GetComponent <EnterName>().scoreSubmitted;
     persString        = Scores.LoadTemp().Split(',');
     track             = persString[1];
     scores            = Scores.GetScores(track);
     names             = scores.names;
     times             = scores.times;
     for (int i = 0; i < names.Length; i++)
     {
         if (i == 0)
         {
             text.text = i + 1 + ". " + names[i] + "  " + times[i] + "\n";
         }
         else
         {
             text.text += i + 1 + ". " + names[i] + "  " + times[i] + "\n";
         }
     }
 }
Exemplo n.º 4
0
 void submit(string track, string time, string name)
 {
     if (scoreSubmitted)
     {
         Debug.Log("Counting");
         Scores.SubmitScore(track, time, name);
         scores = Scores.GetScores(track);
         names  = scores.names;
         times  = scores.times;
         for (int i = 0; i < names.Length; i++)
         {
             if (i == 0)
             {
                 leaderboard.text = i + 1 + ". " + names[i] + "  " + times[i] + "\n";
             }
             else
             {
                 leaderboard.text += i + 1 + ". " + names[i] + "  " + times[i] + "\n";
             }
         }
         winner    = false;
         text.text = "Enter Your Name:\n\n\n\n\n\n_ _ _ _ _ _ _ _ _ _";
     }
 }
Exemplo n.º 5
0
    //returns scores for one track
    public static TrackScores GetScores(string trackName)
    {
        TrackScores track = Load(trackName);

        return(track);
    }
Exemplo n.º 6
0
    //insert into then save
    public static bool SubmitScore(string trackName, string time, string name)
    {
        TrackScores track = Load(trackName);

        //Debug.Log(track.track);
        //Debug.Log(track.names[0]);
        //Debug.Log(track.times[0]);
        //Debug.Log(Application.persistentDataPath);
        //Debug.Log(trackName+ time+ name);
        //for new ones
        if (track == null)
        {
            track          = new TrackScores();
            track.track    = trackName;
            track.times[0] = time;
            track.names[0] = name;
            Save(track);

            return(true);
        }
        else
        {
            int tPos = 420;//arbitrary value

            float playerTime = Int32.Parse(time.Replace(":", ""));


            for (int i = 0; i < track.times.Length; i++)
            {
                //Debug.Log(track.times[i]);
                if (track.times[i] == "" || track.times[i] == null)
                {
                    tPos = i;
                    break;
                }

                else if (playerTime < Int32.Parse(track.times[i].Replace(":", "")))
                {
                    tPos = i;
                    break;
                }
            }
            //Debug.Log(tPos);
            if (tPos < 5)
            {
                //Debug.Log("Issa Save");
                for (int i = track.times.Length - 1; i > tPos; i--)
                {
                    track.times[i] = track.times[i - 1];
                    track.names[i] = track.names[i - 1];
                }
                //Debug.Log("Issa Save 2");
                track.times[tPos] = time;
                track.names[tPos] = name;
                //Debug.Log("Saving");
                Save(track);

                return(true);
            }
        }
        return(false);
    }