|
|
|
@ -135,22 +135,42 @@ namespace Models.Game
|
|
|
|
|
Maps.Add(map);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Adds a new best score to the list of best scores. Or updates it if it already exists.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="finalScore">The final score of the game.</param>
|
|
|
|
|
public void AddBestScore(int finalScore)
|
|
|
|
|
{
|
|
|
|
|
BestScore bs = new BestScore(UsedMap.Name, CurrentPlayer, 1, finalScore);
|
|
|
|
|
foreach (var score in BestScores)
|
|
|
|
|
{
|
|
|
|
|
if (!bs.Equals(score)) continue;
|
|
|
|
|
var existingScore = BestScores.FirstOrDefault(score => score.Equals(bs));
|
|
|
|
|
|
|
|
|
|
score.IncrGamesPlayed();
|
|
|
|
|
score.UpdateScore(finalScore);
|
|
|
|
|
return;
|
|
|
|
|
if (existingScore != null)
|
|
|
|
|
{
|
|
|
|
|
existingScore.IncrGamesPlayed();
|
|
|
|
|
existingScore.UpdateScore(finalScore);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BestScores.Add(bs);
|
|
|
|
|
BestScores.OrderByDescending(p => p.Score);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Sorting the best scores
|
|
|
|
|
List<BestScore> sortedScores = BestScores.OrderByDescending(score => score.Score).ToList();
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < sortedScores.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (!BestScores[i].Equals(sortedScores[i]))
|
|
|
|
|
{
|
|
|
|
|
BestScores.Move(BestScores.IndexOf(sortedScores[i]), i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a player from the list of players.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="playerName"></param>
|
|
|
|
|
/// <returns>True if the player was removed successfully, false otherwise.</returns>
|
|
|
|
|
public bool RemovePlayer(string playerName)
|
|
|
|
|
{
|
|
|
|
|
Player player = Players.FirstOrDefault(p => p.Pseudo == playerName);
|
|
|
|
@ -163,6 +183,12 @@ namespace Models.Game
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Modifies the pseudo of a player.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pseudo"></param>
|
|
|
|
|
/// <param name="newpseudo"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public bool ModifyPlayer(string pseudo, string newpseudo)
|
|
|
|
|
{
|
|
|
|
|
foreach (var index in Players)
|
|
|
|
@ -178,6 +204,10 @@ namespace Models.Game
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Removes a game from the list of games.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="playerName"></param>
|
|
|
|
|
public void CheckAndRemoveBestScoresDependencies(string playerName)
|
|
|
|
|
{
|
|
|
|
|
List<BestScore> bs = new List<BestScore>();
|
|
|
|
@ -194,6 +224,11 @@ namespace Models.Game
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Modifies the pseudo of a player in the best scores.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="playerName"></param>
|
|
|
|
|
/// <param name="newPlayerName"></param>
|
|
|
|
|
public void CheckAndChangeBestScoresDependencies(string playerName, string newPlayerName)
|
|
|
|
|
{
|
|
|
|
|
foreach (var bestScore in BestScores)
|
|
|
|
@ -393,7 +428,6 @@ namespace Models.Game
|
|
|
|
|
{
|
|
|
|
|
IsRunning = true;
|
|
|
|
|
GameStarted?.Invoke(this, new GameStartedEventArgs(CurrentPlayer));
|
|
|
|
|
GameLoop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|