/// <summary> /// saveHighscore updates and prepares the highscore-list with the new entry, removes the bottom one and prepares the /// layout to receive a name for the entry. /// </summary> /// <param name="setRank">Set rank.</param> private void saveHighscore(int setRank) { scoreHeader.Text = "Rank " + setRank + " - Slutpoäng:"; nameEdit.Visibility = ViewStates.Visible; nameButton.Visibility = ViewStates.Visible; replayButton.Visibility = ViewStates.Gone; menuButton.Visibility = ViewStates.Gone; HighScoreEntry newEntry = new HighScoreEntry(); getRank = setRank; newEntry.NameValue = "Inget givet namn"; newEntry.ScoreValue = finalScore; Console.WriteLine("Gained rank: " + setRank); list.Insert(setRank - 1, newEntry); for (int i = 0; i < list.Count; i++) { list [i].Rank = i + 1; Console.WriteLine("Setting ranks: " + i + " - " + list [i].Rank); } for (int i = 0; i < list.Count; i++) { if (list[i].Rank > 10) { Console.WriteLine("Entry removed: " + list[i].Rank + " - " + list[i].NameValue + " - " + list[i].ScoreValue); list.RemoveAt(i); i--; } } }
/// <summary> /// firstTimeSetup inserts ten preset-entries into the database the first time that you start the app. /// </summary> public void firstTimeSetup() { db = new SQLiteConnection(dbPath); HighScoreEntry newEntry = new HighScoreEntry(); newEntry.Rank = 1; newEntry.NameValue = "The Best"; newEntry.ScoreValue = 100; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 2; newEntry.NameValue = "Färgfantasten"; newEntry.ScoreValue = 70; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 3; newEntry.NameValue = "Stan"; newEntry.ScoreValue = 66; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 4; newEntry.NameValue = "Anja"; newEntry.ScoreValue = 60; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 5; newEntry.NameValue = "Medelmåttiga Morgan"; newEntry.ScoreValue = 50; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 6; newEntry.NameValue = "Tim"; newEntry.ScoreValue = 40; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 7; newEntry.NameValue = "Lata Larry"; newEntry.ScoreValue = 20; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 8; newEntry.NameValue = "Bob"; newEntry.ScoreValue = 11; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 9; newEntry.NameValue = "Färgblinde Bob"; newEntry.ScoreValue = 3; db.Insert(newEntry); newEntry = new HighScoreEntry(); newEntry.Rank = 10; newEntry.NameValue = "Jerry"; newEntry.ScoreValue = 0; db.Insert(newEntry); db.Close(); }