Finished scoring system and started tests

This commit is contained in:
KäseToatz
2024-11-06 21:46:37 +01:00
parent 23ae45ba91
commit af7457a9d9
13 changed files with 265 additions and 50 deletions

View File

@ -1,11 +1,18 @@
namespace Memory.Logic
{
public class Game(IScoreHandler scoreHandler)
public class Game(IScoreHandler scoreHandler, string player)
{
public const int DECKSIZE = 10;
public const int GRIDSIZE = 5;
public const int MAXPOINTS = 100;
public const int MINPOINTS = 10;
public const int MAXTIME = 10000;
public const int STARTSCORE = 100;
public List<Card> Cards { get; } = CreateDeck(DECKSIZE);
public IScoreHandler ScoreHandler { get; } = scoreHandler;
public Score Scoring { get; set; } = new(player, STARTSCORE);
public long LastGuess { get; set; } = DateTimeOffset.Now.ToUnixTimeMilliseconds();
private static List<Card> CreateDeck(int pairs)
{
@ -19,6 +26,15 @@
return [..cards.OrderBy(card => random.Next())];
}
public void IncreaseScore()
{
long curTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();
double percentage = 1.0 - (double)(curTime - LastGuess) / MAXTIME;
int points = (int)(percentage * MAXPOINTS);
Scoring.Points += Math.Min(Math.Max(points, MINPOINTS), MAXPOINTS);
LastGuess = curTime;
}
public Card? GetChoice1()
{
return Cards.FirstOrDefault(card => card.IsChoice1);
@ -59,7 +75,15 @@
{
choice1.Completed = true;
card.Completed = true;
// handle score etc
IncreaseScore();
if (IsFinished())
{
ScoreHandler.WriteScore(Scoring);
}
}
else
{
Scoring.Points -= 10;
}
}
}

View File

@ -2,5 +2,7 @@
{
public interface IScoreHandler
{
public void WriteScore(Score score);
public List<Score> GetTopScores();
}
}

8
Memory.Logic/Score.cs Normal file
View File

@ -0,0 +1,8 @@
namespace Memory.Logic
{
public class Score(string name, int points)
{
public string Name { get; } = name;
public int Points { get; set; } = points;
}
}