Fixed all requirements
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user