Ejemplo n.º 1
0
    public void finishedLevel()
    {
        _gamePlaying = false;
        _finishedLevelPanel.SetActive(true);

        int      miliseconds = Mathf.RoundToInt((_elapsedTime - Mathf.RoundToInt(_elapsedTime)) * 1000);
        TimeSpan span        = new TimeSpan(0, 0, 0, Mathf.RoundToInt(_elapsedTime), miliseconds);

        _finishTimeText.text = "You finished in " + span.Minutes.ToString("00") + ":" + span.Seconds.ToString("00") + ":" + span.Milliseconds.ToString("000");
        List <Highscore> all            = Highscore.All();
        Highscore        levelHighscore = null;
        float            ft             = 0;

        if (all != null && all.Count > 0)
        {
            IEnumerable <Highscore> hs = all.Where(x => x.levelnumber == LevelToLoad.levelNumber);
            if (hs.Count() > 0)
            {
                levelHighscore = hs.First();
                ft             = levelHighscore.time;
            }
        }
        if (_elapsedTime < ft || ft == 0)
        {
            int      pfmiliseconds = Mathf.RoundToInt((ft - Mathf.RoundToInt(ft)) * 1000);
            TimeSpan pfspan        = new TimeSpan(0, 0, 0, Mathf.RoundToInt(ft), pfmiliseconds);
            string   pftime        = pfspan.Minutes.ToString("00") + ":" + pfspan.Seconds.ToString("00") + ":" + pfspan.Milliseconds.ToString("000");
            _finishTimeText.text += "\nYou beat your fastest time!\nThe previous fastest time was " + pftime;
            if (levelHighscore == null)
            {
                levelHighscore             = new Highscore();
                levelHighscore.levelnumber = LevelToLoad.levelNumber;
                levelHighscore.New();
            }
            levelHighscore.time = _elapsedTime;
            levelHighscore.Save();
        }
        else if (_elapsedTime > ft)
        {
            int      fmiliseconds = Mathf.RoundToInt((ft - Mathf.RoundToInt(ft)) * 1000);
            TimeSpan fspan        = new TimeSpan(0, 0, 0, Mathf.RoundToInt(ft), fmiliseconds);
            string   ftime        = fspan.Minutes.ToString("00") + ":" + fspan.Seconds.ToString("00") + ":" + fspan.Milliseconds.ToString("000");
            _finishTimeText.text += "\nYour fastest time is " + ftime;
        }
        else
        {
            Debug.Log("Elapsed: " + _elapsedTime + " / Fastets " + ft);
        }
        if (GameController.Instance.levelController.levels.Count < LevelToLoad.levelNumber + 1)
        {
            _nextLevelButton.interactable = false;
            Debug.Log(GameController.Instance.levelController.levels.Count + " < " + (LevelToLoad.levelNumber + 1));
        }
        else
        {
            Debug.Log(GameController.Instance.levelController.levels.Count + " > " + (LevelToLoad.levelNumber + 1));
            MeshData newleveltoload = GameController.Instance.levelController.levels.First(x => x.levelNumber == LevelToLoad.levelNumber + 1);
            LevelToLoad = newleveltoload;
        }
    }
Ejemplo n.º 2
0
    public void initialize(MeshData level)
    {
        _level          = level;
        _levelName.text = level.name;

        float            elapsedTime = 0;
        List <Highscore> all         = Highscore.All();

        if (all != null && all.Count > 0)
        {
            List <Highscore> hsw = all.Where(x => x.levelnumber == level.levelNumber).ToList();
            if (hsw != null && hsw.Count > 0)
            {
                Highscore hs = hsw.First();
                if (hs != null)
                {
                    elapsedTime = hs.time;
                }
            }
        }
        int      miliseconds = Mathf.RoundToInt((elapsedTime - Mathf.RoundToInt(elapsedTime)) * 1000);
        TimeSpan span        = new TimeSpan(0, 0, 0, Mathf.RoundToInt(elapsedTime), miliseconds);

        _highScoreText.text = "Fastest: " + span.Minutes.ToString("00") + ":" + span.Seconds.ToString("00") + ":" + span.Milliseconds.ToString("000");
    }
Ejemplo n.º 3
0
 // Read
 public static void DemoHighscoreRead()
 {
     Debug.Print("--- DemoHighscoreRead ---");
     foreach (Highscore highscore in Highscore.All())
     {
         Debug.Print("Highscore Id:" + highscore.Id + " Points:" + highscore.Points);
     }
 }