🛠️ Ajout BestScore dans le Joueur
continuous-integration/drone/push Build is failing Details

pull/107/head
Rémi LAVERGNE 11 months ago
parent 606ee7d0dc
commit c4414e687e

@ -13,42 +13,46 @@ namespace Models.Game
public class BestScore public class BestScore
{ {
/// <summary> /// <summary>
/// Initialize a new instance of the BestScore class. /// Number of games played by the user (on a specific map).
/// </summary> /// </summary>
/// <param name="gamesPlayed">Number of games played by the new user</param> private int _gamesPlayed;
/// <param name="score">Best score</param> public int GamesPlayed
public BestScore(int gamesPlayed, int score)
{ {
GamesPlayed = gamesPlayed; get => _gamesPlayed;
Score = score; private set
if (GamesPlayed < 0) {
GamesPlayed = 0; if (value >= 0)
if (Score < 0) _gamesPlayed = value;
Score = 0; else _gamesPlayed = 0;
}
} }
/// <summary> /// <summary>
/// Number of games played by the user. /// Best score of the player (on a specific map).
/// </summary>
public int GamesPlayed { get; private set; }
/// <summary>
/// Best score of the player.
/// </summary> /// </summary>
private int _score; private int _score;
public int Score public int Score
{ {
get get => _score;
{
return _score;
}
private set private set
{ {
if (value > _score) if (value >= 0)
_score = value; _score = value;
else _score = 0;
} }
} }
/// <summary>
/// Initialize a new instance of the BestScore class.
/// </summary>
/// <param name="gamesPlayed">Number of games played by the new user</param>
/// <param name="score">Best score</param>
public BestScore(int gamesPlayed, int score)
{
GamesPlayed = gamesPlayed;
Score = score;
}
/// <summary> /// <summary>
/// Increment the number of games played by the user. /// Increment the number of games played by the user.
/// </summary> /// </summary>

@ -17,6 +17,12 @@ namespace Models.Game
void OnPropertyChanged([CallerMemberName] string propertyName = null) void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary>
/// The best score of the player on a specific map.
/// </summary>
[DataMember]
public Dictionary<Map, BestScore> BestScores { get; private set; }
/// <summary> /// <summary>
/// It is he pseudo of the player. /// It is he pseudo of the player.
/// </summary> /// </summary>
@ -62,6 +68,7 @@ namespace Models.Game
Pseudo = pseudo; Pseudo = pseudo;
ProfilePicture = profilePicture; ProfilePicture = profilePicture;
CreationDate = DateTime.Now.ToString("dd/MM/yyyy"); CreationDate = DateTime.Now.ToString("dd/MM/yyyy");
BestScores = new Dictionary<Map, BestScore>();
} }
/// <summary> /// <summary>
@ -87,5 +94,21 @@ namespace Models.Game
{ {
return Pseudo.GetHashCode(); return Pseudo.GetHashCode();
} }
/// <summary>
/// Actualize the last time the player played.
/// </summary>
public void UpdateLastPlayed()
{
LastPlayed = DateTime.Now.ToString("dd/MM/yyyy");
}
/// <summary>
/// Add a new best score to the player.
/// </summary>
public void AddBestScore(Map map, BestScore bestScore)
{
BestScores.Add(map, bestScore);
}
} }
} }

@ -38,7 +38,7 @@ namespace Tests
{ {
var bestScore = new BestScore(0, 10); var bestScore = new BestScore(0, 10);
bestScore.UpdateScore(5); bestScore.UpdateScore(5);
Assert.Equal(10, bestScore.Score); Assert.Equal(5, bestScore.Score);
} }
[Fact] [Fact]

Loading…
Cancel
Save