//When the user presses enter, start or end the game private void Form1_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == Convert.ToChar(Keys.Enter)) { if (GenerationTimer.Enabled) { CurrentColor = Color.Black; GenerationTimer.Enabled = false; setSpeedToolStripMenuItem.Enabled = true; loopingBoardToolStripMenuItem.Enabled = true; GenerationTimer.Stop(); ReColorAll(); } else { CurrentColor = Color.Blue; GenerationTimer.Enabled = true; setSpeedToolStripMenuItem.Enabled = false; loopingBoardToolStripMenuItem.Enabled = false; GenerationTimer.Start(); ReColorAll(); } } }
//New game strip menu, stops game, sets all squares to not alive and empty private void newGameToolStripMenuItem_Click(object sender, EventArgs e) { for (var i = 0; i < SquareArray.GetLength(0); i++) { for (var j = 0; j < SquareArray.GetLength(1); j++) { if (SquareArray[i, j].IsAlive) { SquareArray[i, j].IsAlive = false; SquareArray[i, j].EmptySquare(); } } } if (GenerationTimer.Enabled) { CurrentColor = Color.Black; GenerationTimer.Enabled = false; setSpeedToolStripMenuItem.Enabled = true; loopingBoardToolStripMenuItem.Enabled = true; GenerationTimer.Stop(); ReColorAll(); } UpdateGraphics(); }