🛠️ 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
{
/// <summary>
/// Initialize a new instance of the BestScore class.
/// Number of games played by the user (on a specific map).
/// </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)
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;
}
}
/// <summary>
/// Number of games played by the user.
/// </summary>
public int GamesPlayed { get; private set; }
/// <summary>
/// Best score of the player.
/// Best score of the player (on a specific map).
/// </summary>
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;
}
}
/// <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>
/// Increment the number of games played by the user.
/// </summary>

@ -17,6 +17,12 @@ namespace Models.Game
void OnPropertyChanged([CallerMemberName] string propertyName = null)
=> 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>
/// It is he pseudo of the player.
/// </summary>
@ -62,6 +68,7 @@ namespace Models.Game
Pseudo = pseudo;
ProfilePicture = profilePicture;
CreationDate = DateTime.Now.ToString("dd/MM/yyyy");
BestScores = new Dictionary<Map, BestScore>();
}
/// <summary>
@ -87,5 +94,21 @@ namespace Models.Game
{
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);
bestScore.UpdateScore(5);
Assert.Equal(10, bestScore.Score);
Assert.Equal(5, bestScore.Score);
}
[Fact]

Loading…
Cancel
Save