diff --git a/source/Trek-12/Models/Game/BestScore.cs b/source/Trek-12/Models/Game/BestScore.cs index c2c5ca4..cbe2923 100644 --- a/source/Trek-12/Models/Game/BestScore.cs +++ b/source/Trek-12/Models/Game/BestScore.cs @@ -13,42 +13,46 @@ namespace Models.Game public class BestScore { /// - /// Initialize a new instance of the BestScore class. + /// Number of games played by the user (on a specific map). /// - /// Number of games played by the new user - /// Best score - public BestScore(int gamesPlayed, int score) + private int _gamesPlayed; + public int GamesPlayed { - GamesPlayed = gamesPlayed; - Score = score; - if (GamesPlayed < 0) - GamesPlayed = 0; - if (Score < 0) - Score = 0; + get => _gamesPlayed; + private set + { + if (value >= 0) + _gamesPlayed = value; + else _gamesPlayed = 0; + } } - + /// - /// Number of games played by the user. - /// - public int GamesPlayed { get; private set; } - - /// - /// Best score of the player. + /// Best score of the player (on a specific map). /// private int _score; - public int Score - { - get - { - return _score; - } + public int Score + { + get => _score; private set { - if (value > _score) + if (value >= 0) _score = value; + else _score = 0; } } + /// + /// Initialize a new instance of the BestScore class. + /// + /// Number of games played by the new user + /// Best score + public BestScore(int gamesPlayed, int score) + { + GamesPlayed = gamesPlayed; + Score = score; + } + /// /// Increment the number of games played by the user. /// diff --git a/source/Trek-12/Models/Game/Player.cs b/source/Trek-12/Models/Game/Player.cs index cb8f095..71bdc9f 100644 --- a/source/Trek-12/Models/Game/Player.cs +++ b/source/Trek-12/Models/Game/Player.cs @@ -17,6 +17,12 @@ namespace Models.Game void OnPropertyChanged([CallerMemberName] string propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + /// + /// The best score of the player on a specific map. + /// + [DataMember] + public Dictionary BestScores { get; private set; } + /// /// It is he pseudo of the player. /// @@ -62,6 +68,7 @@ namespace Models.Game Pseudo = pseudo; ProfilePicture = profilePicture; CreationDate = DateTime.Now.ToString("dd/MM/yyyy"); + BestScores = new Dictionary(); } /// @@ -87,5 +94,21 @@ namespace Models.Game { return Pseudo.GetHashCode(); } + + /// + /// Actualize the last time the player played. + /// + public void UpdateLastPlayed() + { + LastPlayed = DateTime.Now.ToString("dd/MM/yyyy"); + } + + /// + /// Add a new best score to the player. + /// + public void AddBestScore(Map map, BestScore bestScore) + { + BestScores.Add(map, bestScore); + } } } \ No newline at end of file diff --git a/source/Trek-12/Tests/BestScoreTests.cs b/source/Trek-12/Tests/BestScoreTests.cs index 951989c..f860375 100644 --- a/source/Trek-12/Tests/BestScoreTests.cs +++ b/source/Trek-12/Tests/BestScoreTests.cs @@ -38,7 +38,7 @@ namespace Tests { var bestScore = new BestScore(0, 10); bestScore.UpdateScore(5); - Assert.Equal(10, bestScore.Score); + Assert.Equal(5, bestScore.Score); } [Fact]