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..33a6a17 100644 --- a/ConwaysLife/LifeForm.cs +++ b/ConwaysLife/LifeForm.cs @@ -111,6 +111,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 +207,11 @@ private void DrawDisplay() } private void timer_Tick(object sender, EventArgs e) + { + StepGeneration(); + } + + private void StepGeneration() { life.Step(); Draw(); @@ -239,7 +245,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")}"; + } } }