Sort scoreboard by points and update when game over
This commit is contained in:
parent
51cd3adb9c
commit
919a29e376
1 changed files with 20 additions and 3 deletions
|
@ -33,7 +33,10 @@ public class GameViewModel : INotifyPropertyChanged
|
|||
private string _scoreText = "";
|
||||
private string _userNameText = "";
|
||||
|
||||
public GameViewModel() {
|
||||
public GameViewModel()
|
||||
{
|
||||
fetchScoreBoard();
|
||||
|
||||
_writeableBitmap = BitmapFactory.New(_width, _height);
|
||||
|
||||
var dispatcherRenderTimer = new DispatcherTimer
|
||||
|
@ -65,10 +68,15 @@ public class GameViewModel : INotifyPropertyChanged
|
|||
}
|
||||
}
|
||||
|
||||
private List<Score> _scoreBoard;
|
||||
|
||||
public List<Score> ScoreBoard {
|
||||
get {
|
||||
using var db = new ScoreContext();
|
||||
return db.Scores.ToList();
|
||||
return _scoreBoard;
|
||||
}
|
||||
set {
|
||||
_scoreBoard = value;
|
||||
OnPropertyChanged("ScoreBoard");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -82,6 +90,14 @@ public class GameViewModel : INotifyPropertyChanged
|
|||
}
|
||||
}
|
||||
|
||||
private void fetchScoreBoard()
|
||||
{
|
||||
using var db = new ScoreContext();
|
||||
List<Score> scores = db.Scores.ToList();
|
||||
scores.Sort((x, y) => y.Points.CompareTo(x.Points));
|
||||
ScoreBoard = scores;
|
||||
}
|
||||
|
||||
private void Render(object? sender, EventArgs eventArgs)
|
||||
{
|
||||
_writeableBitmap.Lock();
|
||||
|
@ -154,6 +170,7 @@ public class GameViewModel : INotifyPropertyChanged
|
|||
Game.Playing = false;
|
||||
Game.PrintTetrominoe();
|
||||
Game.SaveGame();
|
||||
fetchScoreBoard();
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue