INotifyPropertyChanged added
This commit is contained in:
@ -16,7 +16,7 @@
|
||||
<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>
|
||||
<Label Content="{Binding DeckSize}" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="535,300,0,0" FontSize="30px" Name="Size"></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,335,0,0" FontSize="16" 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>
|
||||
|
@ -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