70 lines
1.6 KiB
C#
70 lines
1.6 KiB
C#
using System;
|
|
using System.Windows.Input;
|
|
using Life.Automaton;
|
|
using Life.Misc;
|
|
|
|
namespace Life.ViewModel
|
|
{
|
|
public class AutomatonViewModel : BaseViewModel
|
|
{
|
|
|
|
private int _size;
|
|
private int _separation;
|
|
private IAutomaton _automaton;
|
|
|
|
public int Size
|
|
{
|
|
get => _size;
|
|
set
|
|
{
|
|
_size = value;
|
|
OnPropertyChanged(nameof(Size));
|
|
}
|
|
}
|
|
|
|
public int Separation
|
|
{
|
|
get => _separation;
|
|
set
|
|
{
|
|
_separation = value;
|
|
OnPropertyChanged(nameof(Separation));
|
|
}
|
|
}
|
|
|
|
public IAutomaton Automaton
|
|
{
|
|
get => _automaton;
|
|
set
|
|
{
|
|
_automaton = value;
|
|
OnPropertyChanged(nameof(Field));
|
|
OnPropertyChanged(nameof(Iteration));
|
|
}
|
|
}
|
|
|
|
public IField Field => Automaton.Field;
|
|
public int Iteration => Automaton.Iteration;
|
|
|
|
public ICommand CellClicked => new DelegateCommand<Position>
|
|
{
|
|
Action = HandleCellClick
|
|
};
|
|
|
|
public ICommand StepCommand => new DelegateCommand<object>
|
|
{
|
|
Action = Step
|
|
};
|
|
|
|
private void Step(object param)
|
|
{
|
|
Automaton.Advance();
|
|
}
|
|
|
|
private void HandleCellClick(Position position)
|
|
{
|
|
Field[position.X, position.Y].IsAlive = !Field[position.X, position.Y].IsAlive;
|
|
Field.Notify();
|
|
}
|
|
}
|
|
} |