private void SaveScore(int score) { if (scoreboard.IsAScoreBeaten(score)) { GameControl.PlaySound(GameControl.Sound.Record); Point wtbPosition = new Point(Left + Width / 2.0, Top + Height / 2.0); WindowTextBox wtb = new WindowTextBox("Enter your name", "score: " + score + "!", wtbPosition); string name = wtb.TextBox.Text; ScoreboardItem item = new ScoreboardItem(name, score); scoreboard.AddItem(item); SaveScoreboard(); } }
//------------------------------------------- public void AddItem(ScoreboardItem item) { for (int i = _scoreboardItems.Length - 2; i >= 0; i--) { if (item > _scoreboardItems[i]) { _scoreboardItems[i + 1] = _scoreboardItems[i]; if (i == 0) //Best score _scoreboardItems[0] = item; } else //First higher than that one { _scoreboardItems[i + 1] = item; break; } } }
public bool IsAScoreBeaten(ScoreboardItem item) { return (item > _scoreboardItems[_scoreboardItems.Length - 1]); }
//------------------------------------------- public Scoreboard() { _scoreboardItems = new ScoreboardItem[10]; for (int i = 0; i < _scoreboardItems.Length; i++) _scoreboardItems[i] = new ScoreboardItem(); }