Exemple #1
0
        /// <summary>
        /// Add item to the list.
        /// </summary>
        /// <param name="item"></param>
        /// <returns>True if item made it in the top 5, False in not.</returns>
        public bool add(HighScoreItem item)
        {
            highScores.Add(item);
            highScores.Sort();

            if (highScores.Count > 5)
            {
                bool madeit = false;

                HighScores temp = new HighScores();
                for (int i = 0; i < 5; i++)
                {
                    temp.highScores[i] = this.highScores[i];
                    if (temp.highScores[i].Equals(item))
                    {
                        madeit = true;
                    }
                }
                this.highScores = temp.highScores;

                return madeit;
            }
            else
            {
                return true;
            }
        }
Exemple #2
0
        public static List <HighScoreItem> GetHighScoreItemList()
        {
            List <HighScoreItem> highScoreItems = new List <HighScoreItem>();
            FileStream           fileStream     = new FileStream(SourceFile, FileMode.Open, FileAccess.Read);

            using (StreamReader reader = new StreamReader(fileStream, Encoding.UTF8))
            {
                int    index = 0;
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    HighScoreItem highScoreItem = new HighScoreItem();
                    if (index % 2 == 0)
                    {
                        highScoreItem.PlayerName = line;
                    }
                    else
                    {
                        Int32.TryParse(line, out int playerScore);
                        highScoreItem.PlayerScore = playerScore;
                    }
                    highScoreItems.Add(highScoreItem);
                    index++;
                }
            }

            return(highScoreItems);
        }
Exemple #3
0
        public static List <HighScoreItem> AddHighScoreItemToFile(HighScoreItem item)
        {
            string[] lines = { item.PlayerName, item.PlayerScore.ToString() };
            File.WriteAllLines(SourceFile, lines);

            return(GetHighScoreItemList());
        }
Exemple #4
0
        public async Task <ActionResult <HighScoreItem> > PostHighScoreItem(HighScoreItem highScoreItem)
        {
            _context.HighScoreItems.Add(highScoreItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetHighScoreItem), new { id = highScoreItem.Id }, highScoreItem));
        }
Exemple #5
0
        public async Task <IActionResult> PutHighScoreItem(int id, HighScoreItem highScoreItem)
        {
            if (id != highScoreItem.Id)
            {
                return(BadRequest());
            }

            _context.Entry(highScoreItem).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HighScoreItemExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
    private HighScoreItem[] m_HighScores = new HighScoreItem[k_NumberOfHighScores + 1]; //Extra slot for the current score, for the sort

    public void loadSavedScores()
    {
        for (int i = 0; i <= k_NumberOfHighScores; i++)
        {
            int           score = PlayerPrefs.GetInt(i.ToString() + "score");
            string        time  = PlayerPrefs.GetString(i.ToString() + "time");
            string        name  = PlayerPrefs.GetString(i.ToString() + "name");
            HighScoreItem currentHighScoreItem = new HighScoreItem(score, name, time);

            m_HighScores[i] = currentHighScoreItem;
        }
    }
    public void UpdateHighScoreList(int i_NewScore)
    {
        loadSavedScores();

        m_HighScores[k_NumberOfHighScores] = new HighScoreItem(i_NewScore, r_RandomNames[(int)UnityEngine.Random.Range(0, r_RandomNames.Length - 1)], DateTime.Now.ToString());

        Array.Sort(m_HighScores);

        for (int i = 0; i <= k_NumberOfHighScores; i++)
        {
            PlayerPrefs.SetInt(i.ToString() + "score", m_HighScores[i].Score);
            PlayerPrefs.SetString(i.ToString() + "time", m_HighScores[i].Time.ToString());
            PlayerPrefs.SetString(i.ToString() + "name", m_HighScores[i].Name);
        }
    }
Exemple #8
0
 public static void Initialize()
 {
     if(File.Exists("HighScores.txt"))
     {
         StreamReader fileIn = new StreamReader("HighScores.txt");
         for (int i = Utility.ZERO; i < Utility.THREE; ++i)
         {
             string[] nextLine = fileIn.ReadLine().Split(Utility.LEVEL_LOADER_DELIMITER);
             var nextHighScoreItem = new HighScoreItem(nextLine[Utility.ZERO], Int32.Parse(nextLine[Utility.ONE]));
             TopScores[i] = nextHighScoreItem;
         }
         fileIn.Close();
     }
     else
     {
         TopScores[0] = new HighScoreItem("AAA", 00000);
         TopScores[1] = new HighScoreItem("BBB", 00000);
         TopScores[2] = new HighScoreItem("CCC", 00000);
         
         SaveScores();
     }
 }
    //Neuen Highscore eintrag verfassen
    public static bool AddScoreItem(string p_name, int p_score, bool saveScore = true)
    {
        int lastItem = _maxScoreItems-1;
        bool newHighscore = false;

        //Ist die Akt Länge kleiner als die Beschränkung
        if (_scoreList.Count < _maxScoreItems) {

            HighScoreItem item = new HighScoreItem (p_name, p_score);

            //In highscore liste speichern
            _scoreList.Add (item);

            newHighscore = true;

        } else if(p_score > GetItemScore(lastItem)) { // Schon alle Plätze belegt dann wenn größer letzten austauschen

            HighScoreItem item = new HighScoreItem (p_name, p_score);

            //In highscore liste letztes Element ersetzten
            _scoreList.Insert(lastItem,item);

            newHighscore = true;

        }

        _actPoints = 0;

        //Sortieren
        SortScoreList ();

        if(saveScore){

            //SaveNewScoreList();
        }

        return newHighscore;
    }
Exemple #10
0
        /// <summary>
        /// Adds an entry to the map, according to the gameType and Difficulty parameters
        /// </summary>
        /// <param name="item">HighScoreItem to be added.</param>
        /// <param name="type">Standard or Squiggly</param>
        /// <param name="diff">Easy, Medium or Hard</param>
        /// <returns></returns>
        public bool add(HighScoreItem item, gameType type, Difficulty diff)
        {
            int d = diff == Difficulty.Easy ? 0 : (diff == Difficulty.Medium ? 1 : 2);

            return HS[type][d].add(item);
        }
Exemple #11
0
 public static void UpdateScores()
 {
     HighScoreItem high = new HighScoreItem(new string(NewHighScoreName),NewScore );
     TopScores[NewScoreIndex] = high;
     SaveScores();
 }