diff --git a/Life/App.xaml b/Life/App.xaml
index 28bcbde..0dc76a5 100644
--- a/Life/App.xaml
+++ b/Life/App.xaml
@@ -7,12 +7,11 @@
diff --git a/Life/Automaton/BasicField.cs b/Life/Automaton/BasicField.cs
index f2afbda..ac32053 100644
--- a/Life/Automaton/BasicField.cs
+++ b/Life/Automaton/BasicField.cs
@@ -24,7 +24,7 @@ namespace Life.Automaton
private Cell[,] _cells;
- public Size Size { get; }
+ public Size Size { get; private set; }
public Cell this[int x, int y]
{
@@ -52,6 +52,20 @@ namespace Life.Automaton
_observers.ForEach(observer => observer.OnNext(this));
}
+ public void Resize(int width, int height)
+ {
+ var cells = new Cell[width, height];
+
+ for (int x = 0; x < width; x++)
+ for (int y = 0; y < height; y++)
+ cells[x, y] = (x >= Size.Width || y >= Size.Height) ? new Cell() : _cells[x, y];
+
+ Size = new Size(width, height);
+ _cells = cells;
+
+ Notify();
+ }
+
public IDisposable Subscribe(IObserver observer)
{
_observers.Add(observer);
diff --git a/Life/Automaton/IField.cs b/Life/Automaton/IField.cs
index 6b25e1d..1107314 100644
--- a/Life/Automaton/IField.cs
+++ b/Life/Automaton/IField.cs
@@ -18,5 +18,7 @@ namespace Life.Automaton
void Transform(Rule rule);
void Notify();
+
+ void Resize(int width, int height);
}
}
\ No newline at end of file
diff --git a/Life/AutomatonField.xaml.cs b/Life/AutomatonField.xaml.cs
index afe1d5a..a7dd19f 100644
--- a/Life/AutomatonField.xaml.cs
+++ b/Life/AutomatonField.xaml.cs
@@ -64,13 +64,13 @@ namespace Life
#region Dependency Properties
public static readonly DependencyProperty SizeProperty = DependencyProperty.Register(
- "Size",
+ nameof(Size),
typeof(int), typeof(AutomatonField),
new PropertyMetadata(OnSizeChanged)
);
public static readonly DependencyProperty SeparationProperty = DependencyProperty.Register(
- "Separation",
+ nameof(Separation),
typeof(int), typeof(AutomatonField),
new PropertyMetadata(OnSeparationChanged)
);
@@ -80,7 +80,7 @@ namespace Life
typeof(IField), typeof(AutomatonField),
new PropertyMetadata(OnFieldChanged)
);
-
+
public static readonly DependencyProperty ClickCommandProperty = DependencyProperty.Register(
nameof(ClickCommand),
typeof(ICommand), typeof(AutomatonField)
diff --git a/Life/MainWindow.xaml b/Life/MainWindow.xaml
index 8d9aa62..0352c0b 100644
--- a/Life/MainWindow.xaml
+++ b/Life/MainWindow.xaml
@@ -30,23 +30,27 @@
-
- Iteracja
+
+ Iteration
+
+
+ Size
+
+
+
+
+
+
- Rozmiar
-
-
-
-
-
-
+ Cell Size
+
diff --git a/Life/ViewModel/AutomatonViewModel.cs b/Life/ViewModel/AutomatonViewModel.cs
index 4cd47c9..cdfec2e 100644
--- a/Life/ViewModel/AutomatonViewModel.cs
+++ b/Life/ViewModel/AutomatonViewModel.cs
@@ -13,9 +13,23 @@ namespace Life.ViewModel
{
private int _size;
private int _separation;
+ private int _width;
+ private int _height;
private IAutomaton _automaton;
private IFormatter _formatter = new BinaryFormatter();
+ public AutomatonViewModel()
+ {
+ PropertyChanged += (sender, args) =>
+ {
+ if (args.PropertyName == nameof(Field))
+ {
+ Width = Field.Size.Width;
+ Height = Field.Size.Height;
+ }
+ };
+ }
+
public int Size
{
get => _size;
@@ -35,6 +49,26 @@ namespace Life.ViewModel
OnPropertyChanged(nameof(Separation));
}
}
+
+ public int Width
+ {
+ get => _width;
+ set
+ {
+ _width = value;
+ OnPropertyChanged(nameof(Width));
+ }
+ }
+
+ public int Height
+ {
+ get => _height;
+ set
+ {
+ _height = value;
+ OnPropertyChanged(nameof(Height));
+ }
+ }
public IAutomaton Automaton
{
@@ -54,6 +88,11 @@ namespace Life.ViewModel
{
Action = HandleCellClick
};
+
+ public ICommand ChangeSizeCommand => new DelegateCommand