Fixed all requirements

This commit is contained in:
KäseToatz
2024-11-07 01:52:51 +01:00
parent af7457a9d9
commit 0121584708
20 changed files with 171 additions and 69 deletions

View File

@ -10,16 +10,19 @@
Height="600"
ResizeMode="NoResize">
<Grid>
<Grid Name="StartScreen">
<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>
<Grid Name="StartScreen" Visibility="Visible">
<Label Content="Memory" HorizontalAlignment="Center" VerticalAlignment="Top" FontSize="100px" Margin="0,120,0,0"/>
<Label Content="Name:" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="220,250,0,0"></Label>
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Margin="330,255,0,0" Width="280" Height="40" FontSize="24" Name="Name"></TextBox>
<Label Content="Pairs of cards in deck:" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="120,300,0,0"></Label>
<Button Content="←" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="470,300,0,0" Click="Decrease"></Button>
<Label Content="5" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="535,300,0,0" FontSize="30px" Name="DeckSize"></Label>
<Button Content="→" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="30px" Margin="600,300,0,0" Click="Increase"></Button>
<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">
<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 Name="GameScreen" Visibility="Visible">
<Grid Name="Cards" HorizontalAlignment="Center" VerticalAlignment="Center" Width="700" Height="500">
</Grid>
</Grid>
<Grid Name="FinishScreen" Visibility="Hidden">

View File

@ -3,6 +3,8 @@ using Memory.Logic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Data;
using System.Windows.Media.Imaging;
namespace Memory.Gui
{
@ -12,11 +14,11 @@ namespace Memory.Gui
public const int SCOREMARGIN = 30;
private Game? game;
private int deckSize = 5;
public MainWindow()
{
InitializeComponent();
CreateGrid();
}
private void StartGame(object sender, RoutedEventArgs args)
@ -28,15 +30,28 @@ namespace Memory.Gui
}
else
{
game = new(new ScoreHandler(), name);
game = new(new ScoreHandler(), name, deckSize);
ErrorLabel.Visibility = Visibility.Hidden;
StartScreen.Visibility = Visibility.Hidden;
FinishScreen.Visibility = Visibility.Hidden;
GameScreen.Visibility = Visibility.Visible;
CreateGrid();
Redraw();
}
}
private void Decrease(object sender, RoutedEventArgs args)
{
deckSize = Math.Max(deckSize - 1, 2);
DeckSize.Content = deckSize;
}
private void Increase(object sender, RoutedEventArgs args)
{
deckSize = Math.Min(deckSize + 1, 10);
DeckSize.Content = deckSize;
}
private void DrawScores()
{
Highscores.Children.Clear();
@ -66,8 +81,11 @@ namespace Memory.Gui
private void CreateGrid()
{
int columns = Game.GRIDSIZE;
int rows = Game.DECKSIZE * 2 / Game.GRIDSIZE;
Cards.ColumnDefinitions.Clear();
Cards.RowDefinitions.Clear();
Deck grid = Game.GetGridSize(deckSize);
int columns = grid.Columns;
int rows = grid.Rows;
for (int i = 0; i < columns; i++)
{
ColumnDefinition colDef = new()
@ -84,25 +102,40 @@ namespace Memory.Gui
};
Cards.RowDefinitions.Add(rowDef);
}
if (rows > columns)
{
Cards.Width /= (double)rows / columns;
}
else if (columns > rows)
{
Cards.Height /= (double)columns / rows;
}
}
private void Redraw()
{
Cards.Children.Clear();
Score.Content = $"Score: {game!.Scoring.Points}";
Deck grid = Game.GetGridSize(deckSize);
for (int i = 0; i < game!.Cards.Count; i++)
{
Card card = game.Cards[i];
if (!card.Completed)
{
Image image = new()
{
Source = new BitmapImage(new($"pack://application:,,,/images/{card.ID}.png")),
Stretch = Stretch.Fill,
};
Button button = new()
{
Content = card.Selected() ? card.ID : null,
Content = card.Selected() ? image : null,
FontSize = 30,
Background = new SolidColorBrush(card.Selected() ? Color.FromRgb(0, 255, 0) : Color.FromRgb(255, 0, 0))
Background = new SolidColorBrush(card.Selected() ? Color.FromRgb(0, 255, 0) : Color.FromRgb(255, 0, 0)),
Padding = new Thickness(0)
};
Grid.SetColumn(button, i % Game.GRIDSIZE);
Grid.SetRow(button, i / Game.GRIDSIZE);
Grid.SetColumn(button, i % grid.Columns);
Grid.SetRow(button, i / grid.Columns);
button.Click += (object sender, RoutedEventArgs args) =>
{
game.ClickCard(card);

View File

@ -8,9 +8,35 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<None Remove="images\1.png" />
<None Remove="images\10.png" />
<None Remove="images\2.png" />
<None Remove="images\3.png" />
<None Remove="images\4.png" />
<None Remove="images\5.png" />
<None Remove="images\6.png" />
<None Remove="images\7.png" />
<None Remove="images\8.png" />
<None Remove="images\9.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Memory.Data\Memory.Data.csproj" />
<ProjectReference Include="..\Memory.Logic\Memory.Logic.csproj" />
</ItemGroup>
<ItemGroup>
<Resource Include="images\1.png" />
<Resource Include="images\10.png" />
<Resource Include="images\2.png" />
<Resource Include="images\3.png" />
<Resource Include="images\4.png" />
<Resource Include="images\5.png" />
<Resource Include="images\6.png" />
<Resource Include="images\7.png" />
<Resource Include="images\8.png" />
<Resource Include="images\9.png" />
</ItemGroup>
</Project>

BIN
Memory.Gui/images/1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
Memory.Gui/images/10.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

BIN
Memory.Gui/images/2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 43 KiB

BIN
Memory.Gui/images/3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

BIN
Memory.Gui/images/4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

BIN
Memory.Gui/images/5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

BIN
Memory.Gui/images/6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

BIN
Memory.Gui/images/7.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 47 KiB

BIN
Memory.Gui/images/8.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

BIN
Memory.Gui/images/9.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB