INotifyPropertyChanged added
This commit is contained in:
@ -5,10 +5,11 @@ using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media.Imaging;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Memory.Gui
|
||||
{
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow : Window, INotifyPropertyChanged
|
||||
{
|
||||
public const int SCOREPADDING = 160;
|
||||
public const int SCOREMARGIN = 30;
|
||||
@ -16,11 +17,21 @@ namespace Memory.Gui
|
||||
public const int GRIDHEIGHT = 500;
|
||||
|
||||
private Game? game;
|
||||
private int deckSize = 5;
|
||||
private int _deckSize = 5;
|
||||
|
||||
public int DeckSize { get => _deckSize; set
|
||||
{
|
||||
_deckSize = value;
|
||||
OnPropertyChanged(nameof(DeckSize));
|
||||
}
|
||||
}
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
DataContext = this;
|
||||
}
|
||||
|
||||
private void StartGame(object sender, RoutedEventArgs args)
|
||||
@ -32,7 +43,7 @@ namespace Memory.Gui
|
||||
}
|
||||
else
|
||||
{
|
||||
game = new(new ScoreHandler(), name, deckSize);
|
||||
game = new(new ScoreHandler(), name, DeckSize);
|
||||
ErrorLabel.Visibility = Visibility.Hidden;
|
||||
StartScreen.Visibility = Visibility.Hidden;
|
||||
FinishScreen.Visibility = Visibility.Hidden;
|
||||
@ -42,17 +53,9 @@ namespace Memory.Gui
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
protected void OnPropertyChanged(string propertyName) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||
private void Decrease(object sender, RoutedEventArgs args) => DeckSize = Math.Max(DeckSize - 1, 2);
|
||||
private void Increase(object sender, RoutedEventArgs args) => DeckSize = Math.Min(DeckSize + 1, 10);
|
||||
|
||||
private void DrawScores()
|
||||
{
|
||||
@ -85,7 +88,7 @@ namespace Memory.Gui
|
||||
{
|
||||
Cards.ColumnDefinitions.Clear();
|
||||
Cards.RowDefinitions.Clear();
|
||||
Deck grid = Game.GetGridSize(deckSize);
|
||||
Deck grid = Game.GetGridSize(DeckSize);
|
||||
int columns = grid.Columns;
|
||||
int rows = grid.Rows;
|
||||
for (int i = 0; i < columns; i++)
|
||||
@ -117,7 +120,7 @@ namespace Memory.Gui
|
||||
private void Redraw()
|
||||
{
|
||||
Cards.Children.Clear();
|
||||
Deck grid = Game.GetGridSize(deckSize);
|
||||
Deck grid = Game.GetGridSize(DeckSize);
|
||||
for (int i = 0; i < game!.Cards.Count; i++)
|
||||
{
|
||||
Card card = game.Cards[i];
|
||||
|
Reference in New Issue
Block a user