Modyfikacja zasady z UI
This commit is contained in:
parent
5240ef7ce6
commit
d6435fc7c9
@ -13,5 +13,8 @@
|
|||||||
<Setter Property="FontSize" Value="24" />
|
<Setter Property="FontSize" Value="24" />
|
||||||
<Setter Property="FontWeight" Value="Black"/>
|
<Setter Property="FontWeight" Value="Black"/>
|
||||||
</Style>
|
</Style>
|
||||||
|
<Style x:Key="Setting" TargetType="Panel">
|
||||||
|
<Setter Property="Margin" Value="0 0 0 8"></Setter>
|
||||||
|
</Style>
|
||||||
</Application.Resources>
|
</Application.Resources>
|
||||||
</Application>
|
</Application>
|
||||||
|
@ -40,6 +40,11 @@ namespace Life.Automaton
|
|||||||
|
|
||||||
return @new;
|
return @new;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
return $"{born}/{survive}";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public GameOfLife(int width, int height)
|
public GameOfLife(int width, int height)
|
||||||
|
@ -6,6 +6,7 @@ namespace Life.Automaton
|
|||||||
{
|
{
|
||||||
int Iteration { get; }
|
int Iteration { get; }
|
||||||
IField Field { get; }
|
IField Field { get; }
|
||||||
|
IRule Rule { get; set; }
|
||||||
|
|
||||||
void Advance();
|
void Advance();
|
||||||
|
|
||||||
|
@ -30,13 +30,13 @@
|
|||||||
<GridSplitter Grid.Column="1" Width="3" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext"/>
|
<GridSplitter Grid.Column="1" Width="3" ResizeDirection="Columns" ResizeBehavior="PreviousAndNext"/>
|
||||||
|
|
||||||
<StackPanel Orientation="Vertical" Margin="8" Grid.Column="2" HorizontalAlignment="Stretch">
|
<StackPanel Orientation="Vertical" Margin="8" Grid.Column="2" HorizontalAlignment="Stretch">
|
||||||
<DockPanel Margin="0 0 0 8">
|
<DockPanel Style="{StaticResource Setting}">
|
||||||
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center">Iteration</TextBlock>
|
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center">Iteration</TextBlock>
|
||||||
<TextBlock Style="{StaticResource Value}" Text="{Binding Iteration}" HorizontalAlignment="Stretch"/>
|
<TextBlock Style="{StaticResource Value}" Text="{Binding Iteration}" HorizontalAlignment="Stretch"/>
|
||||||
<Button VerticalAlignment="Stretch" Command="{Binding StepCommand}" CommandParameter="{Binding Steps}" DockPanel.Dock="Right" HorizontalAlignment="Right" Padding="8">step</Button>
|
<Button VerticalAlignment="Stretch" Command="{Binding StepCommand}" CommandParameter="{Binding Steps}" DockPanel.Dock="Right" HorizontalAlignment="Right" Padding="8">step</Button>
|
||||||
<TextBox Text="{Binding Steps}" VerticalAlignment="Stretch" HorizontalAlignment="Right" DockPanel.Dock="Right" Padding="8" BorderThickness="1 1 0 1"/>
|
<TextBox Text="{Binding Steps}" VerticalAlignment="Stretch" HorizontalAlignment="Right" DockPanel.Dock="Right" Padding="8" BorderThickness="1 1 0 1"/>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<DockPanel HorizontalAlignment="Stretch" Margin="0 0 0 8">
|
<DockPanel Style="{StaticResource Setting}">
|
||||||
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center" DockPanel.Dock="Left">Size</TextBlock>
|
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center" DockPanel.Dock="Left">Size</TextBlock>
|
||||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
||||||
<TextBox Text="{Binding Width, Mode=TwoWay}"/>
|
<TextBox Text="{Binding Width, Mode=TwoWay}"/>
|
||||||
@ -47,10 +47,14 @@
|
|||||||
<TextBlock Margin="2">change</TextBlock>
|
<TextBlock Margin="2">change</TextBlock>
|
||||||
</Button>
|
</Button>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
<DockPanel HorizontalAlignment="Stretch">
|
<DockPanel Style="{StaticResource Setting}">
|
||||||
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center" DockPanel.Dock="Left">Cell Size</TextBlock>
|
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center" DockPanel.Dock="Left">Cell Size</TextBlock>
|
||||||
<Slider Minimum="8" Maximum="32" Value="{Binding Size}" VerticalAlignment="Center" />
|
<Slider Minimum="8" Maximum="32" Value="{Binding Size}" VerticalAlignment="Center" />
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
<DockPanel Style="{StaticResource Setting}">
|
||||||
|
<TextBlock Style="{StaticResource Header}" VerticalAlignment="Center" DockPanel.Dock="Left">Rule (born/survive)</TextBlock>
|
||||||
|
<TextBox Text="{Binding Rule, Mode=TwoWay}" HorizontalAlignment="Right" Padding="8"/>
|
||||||
|
</DockPanel>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</DockPanel>
|
</DockPanel>
|
||||||
|
@ -16,6 +16,8 @@ namespace Life.ViewModel
|
|||||||
private int _width;
|
private int _width;
|
||||||
private int _height;
|
private int _height;
|
||||||
private int _steps;
|
private int _steps;
|
||||||
|
private string _rule = "3/23";
|
||||||
|
|
||||||
private IAutomaton _automaton;
|
private IAutomaton _automaton;
|
||||||
private IFormatter _formatter = new BinaryFormatter();
|
private IFormatter _formatter = new BinaryFormatter();
|
||||||
|
|
||||||
@ -31,6 +33,20 @@ namespace Life.ViewModel
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public string Rule
|
||||||
|
{
|
||||||
|
get => _rule;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_rule = value;
|
||||||
|
|
||||||
|
var split = value.Split("/");
|
||||||
|
|
||||||
|
Automaton.Rule = new GameOfLife.StandardRule(split[0], split[1] ?? "23");
|
||||||
|
OnPropertyChanged(nameof(Rule));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int Size
|
public int Size
|
||||||
{
|
{
|
||||||
get => _size;
|
get => _size;
|
||||||
@ -79,6 +95,7 @@ namespace Life.ViewModel
|
|||||||
_automaton = value;
|
_automaton = value;
|
||||||
OnPropertyChanged(nameof(Field));
|
OnPropertyChanged(nameof(Field));
|
||||||
OnPropertyChanged(nameof(Iteration));
|
OnPropertyChanged(nameof(Iteration));
|
||||||
|
Rule = Automaton.Rule.ToString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user