Finished scoring system and started tests
This commit is contained in:
@ -1,14 +1,8 @@
|
||||
using System.Configuration;
|
||||
using System.Data;
|
||||
using System.Windows;
|
||||
using System.Windows;
|
||||
|
||||
namespace Memory.Gui
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for App.xaml
|
||||
/// </summary>
|
||||
public partial class App : Application
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,14 +11,23 @@
|
||||
ResizeMode="NoResize">
|
||||
<Grid>
|
||||
<Grid Name="StartScreen">
|
||||
<Label Content="Memory" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="100px" Margin="0,180,0,0"/>
|
||||
<Button Content="Start" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,320,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
<Label Content="Memory" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="100px" Margin="0,140,0,0"/>
|
||||
<Label Content="Name:" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="220,275,0,0"></Label>
|
||||
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Margin="330,280,0,0" Width="280" Height="40" FontSize="24" Name="Name"></TextBox>
|
||||
<Label Content="Name must be between 2 and 32 characters." HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,320,0,0" FontSize="20" Foreground="Red" Name="ErrorLabel" Visibility="Hidden"></Label>
|
||||
<Button Content="Start" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,360,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
</Grid>
|
||||
<Grid Name="GameScreen" Visibility="Hidden" Margin="50, 100, 50, 50">
|
||||
<Grid Name="GameScreen" Visibility="Hidden">
|
||||
<Label Name="Score" Content="Score: 0" FontSize="50px" HorizontalAlignment="Center" Margin="0, 30, 0, 0"></Label>
|
||||
<Grid Name="Cards" Margin="50, 100, 50, 50">
|
||||
</Grid>
|
||||
</Grid>
|
||||
<Grid Name="FinishScreen" Visibility="Hidden">
|
||||
<Label Content="Game Finished" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="100px" Margin="0,180,0,0"/>
|
||||
<Button Content="Restart" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,320,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
<Label Content="Game Finished" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="40px" Margin="0,10,0,0"/>
|
||||
<Label Content="Your score: 0" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="30px" Margin="0,50,0,0" Name="OwnScore"/>
|
||||
<Label Content="Top 10 Highscores:" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,100,0,0"/>
|
||||
<Grid Name="Highscores"></Grid>
|
||||
<Button Content="Restart" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="50px" Margin="0,480,0,0" Width="240" Height="80" Click="StartGame"></Button>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</Window>
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user