From 5c0e26dd6194d423b900c1b38849e7c5be577098 Mon Sep 17 00:00:00 2001 From: Jim Mackenzie Date: Sat, 25 Apr 2020 20:24:26 +0100 Subject: [PATCH 1/2] Added toggle for manual generation stepping --- ConwaysLife/LifeForm.Designer.cs | 1 + ConwaysLife/LifeForm.cs | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/ConwaysLife/LifeForm.Designer.cs b/ConwaysLife/LifeForm.Designer.cs index bf03d09..a22d8cb 100644 --- a/ConwaysLife/LifeForm.Designer.cs +++ b/ConwaysLife/LifeForm.Designer.cs @@ -42,6 +42,7 @@ private void InitializeComponent() this.display.Size = new System.Drawing.Size(560, 437); this.display.TabIndex = 0; this.display.TabStop = false; + this.display.Click += new System.EventHandler(this.display_Click); this.display.MouseEnter += new System.EventHandler(this.display_MouseEnter); // // timer diff --git a/ConwaysLife/LifeForm.cs b/ConwaysLife/LifeForm.cs index bbc0132..a97812e 100644 --- a/ConwaysLife/LifeForm.cs +++ b/ConwaysLife/LifeForm.cs @@ -5,6 +5,8 @@ namespace ConwaysLife { + using System.Security.Cryptography; + public partial class LifeForm : Form { private readonly Color deadColor = Color.LightGray; @@ -111,6 +113,7 @@ public LifeForm() private void LifeForm_Load(object sender, EventArgs e) { + UpdateFormTitle(); Initialize(); Draw(); // The mouse wheel event handler is not automatically generated @@ -206,6 +209,11 @@ private void DrawDisplay() } private void timer_Tick(object sender, EventArgs e) + { + StepGeneration(); + } + + private void StepGeneration() { life.Step(); Draw(); @@ -239,7 +247,27 @@ private void LifeForm_KeyDown(object sender, KeyEventArgs e) case Keys.Space: timer.Enabled = !timer.Enabled; break; + case Keys.G: + if (!timer.Enabled) + StepGeneration(); + break; } } + + private void display_Click(object sender, EventArgs e) + { + ToggleTimer(); + } + + private void ToggleTimer() + { + timer.Enabled = !timer.Enabled; + UpdateFormTitle(); + } + + private void UpdateFormTitle() + { + Text = $"LifeForm - {(timer.Enabled ? "Automatic" : "Manual")}"; + } } } From b508e7817060bb9b70d930423a3cc0d6c11353af Mon Sep 17 00:00:00 2001 From: Jim Mackenzie Date: Sat, 25 Apr 2020 20:26:11 +0100 Subject: [PATCH 2/2] Love resharper except when it eagerly includes namespaces... --- ConwaysLife/LifeForm.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ConwaysLife/LifeForm.cs b/ConwaysLife/LifeForm.cs index a97812e..33a6a17 100644 --- a/ConwaysLife/LifeForm.cs +++ b/ConwaysLife/LifeForm.cs @@ -5,8 +5,6 @@ namespace ConwaysLife { - using System.Security.Cryptography; - public partial class LifeForm : Form { private readonly Color deadColor = Color.LightGray;