// Create a random by time method. private void fromTimeToolStripMenuItem_Click(object sender, EventArgs e) { timer.Enabled = false; // First turn off all cells. for (var indexY = 0; indexY < universe.GetLength(1); indexY++) { for (var indexX = 0; indexX < universe.GetLength(0); indexX++) { universe[indexX, indexY] = false; scratchPad[indexX, indexY] = false; } } generations = 0; // Update status strip generations BottomStripDisplay(); // Create an instance of FromSeedDialog. FromSeedDialog seedDialog = new FromSeedDialog(); Random random = new Random(); seedDialog.FromSeedDialogRandomize = random.Next(); // Go through universe and assign true based on some additions. for (int y = 0; y < universe.GetLength(1); y++) { for (int x = 0; x < universe.GetLength(0); x++) { if (random.Next(0, 2) == 0) { universe[x, y] = true; } } } // Tell Windows you need to repaint graphicsPanel1.Invalidate(); }
// User provides input for the random seed. private void fromSeedToolStripMenuItem_Click(object sender, EventArgs e) { // Pause timer ticks. timer.Enabled = false; // turn off all cells. for (var indexY = 0; indexY < universe.GetLength(1); indexY++) { for (var indexX = 0; indexX < universe.GetLength(0); indexX++) { universe[indexX, indexY] = false; scratchPad[indexX, indexY] = false; } } // Re-set generation count. generations = 0; // Update status strip generations. BottomStripDisplay(); // Tell Windows you need to repaint graphicsPanel1.Invalidate(); // Create an instance of FromSeedDialog. FromSeedDialog seedDialog = new FromSeedDialog(); seedDialog.FromSeedDialogRandomize = Properties.Settings.Default.Seed; // Show dialog. if (DialogResult.OK == seedDialog.ShowDialog()) { // Get chosen seed info and apply. Properties.Settings.Default.Seed = (int)seedDialog.FromSeedDialogRandomize; seedDialog.FromSeedDialogRandomize = Properties.Settings.Default.Seed; seed = Properties.Settings.Default.Seed; Random random = new Random(seed); // Loop through and turn corresponding cells on. for (int y = 0; y < universe.GetLength(1); y++) { for (int x = 0; x < universe.GetLength(0); x++) { if (random.Next(0, 2) == 0) { universe[x, y] = true; } } } // Tell Windows you need to repaint graphicsPanel1.Invalidate(); } }