Archived
1
0
Fork 0

Sort scoreboard by points and update when game over

This commit is contained in:
p2111528 2022-06-08 07:57:23 +02:00
parent 51cd3adb9c
commit 919a29e376

View file

@ -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();
}
}
}