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

@ -8,6 +8,9 @@ namespace Memory.Gui
{
public partial class MainWindow : Window
{
public const int SCOREPADDING = 160;
public const int SCOREMARGIN = 30;
private Game? game;
public MainWindow()
@ -18,15 +21,45 @@ namespace Memory.Gui
private void StartGame(object sender, RoutedEventArgs args)
{
game = new(new ScoreHandler());
StartScreen.Visibility = Visibility.Hidden;
FinishScreen.Visibility = Visibility.Hidden;
GameScreen.Visibility = Visibility.Visible;
Redraw();
string name = Name.Text;
if (name.Length > 32 || name.Length < 2)
{
ErrorLabel.Visibility = Visibility.Visible;
}
else
{
game = new(new ScoreHandler(), name);
ErrorLabel.Visibility = Visibility.Hidden;
StartScreen.Visibility = Visibility.Hidden;
FinishScreen.Visibility = Visibility.Hidden;
GameScreen.Visibility = Visibility.Visible;
Redraw();
}
}
private void DrawScores()
{
Highscores.Children.Clear();
OwnScore.Content = $"Your score: {game!.Scoring.Points}";
List<Score> highscores = game.ScoreHandler.GetTopScores();
for (int i = 0; i < highscores.Count; i++)
{
Score score = highscores[i];
Label label = new()
{
Content = $"{i+1}. {score.Name}: {score.Points}",
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Top,
FontSize = 30,
Margin = new Thickness(0, SCOREPADDING + SCOREMARGIN * i, 0, 0)
};
Highscores.Children.Add(label);
}
}
private void FinishGame()
{
DrawScores();
GameScreen.Visibility = Visibility.Hidden;
FinishScreen.Visibility = Visibility.Visible;
}
@ -41,7 +74,7 @@ namespace Memory.Gui
{
Width = new(1, GridUnitType.Star)
};
GameScreen.ColumnDefinitions.Add(colDef);
Cards.ColumnDefinitions.Add(colDef);
}
for (int i = 0; i < rows; i++)
{
@ -49,14 +82,15 @@ namespace Memory.Gui
{
Height = new(1, GridUnitType.Star)
};
GameScreen.RowDefinitions.Add(rowDef);
Cards.RowDefinitions.Add(rowDef);
}
}
private void Redraw()
{
GameScreen.Children.Clear();
for (int i = 0; i < game.Cards.Count; i++)
Cards.Children.Clear();
Score.Content = $"Score: {game!.Scoring.Points}";
for (int i = 0; i < game!.Cards.Count; i++)
{
Card card = game.Cards[i];
if (!card.Completed)
@ -81,7 +115,7 @@ namespace Memory.Gui
FinishGame();
}
};
GameScreen.Children.Add(button);
Cards.Children.Add(button);
}
}
}