Finished scoring system and started tests
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user