private void _NewFile(object sender, EventArgs e) { Universe = new UniverseHandler(Settings.UniverseHeight, Settings.UniverseWidth); GenCount.Text = "Generations = " + Universe.generations.ToString(); _CellCount.Text = "Count = " + Universe.liveCells.ToString(); timer.Stop(); graphicsPanel1.Invalidate(); }
public Game() { InitializeComponent(); //Set all the settings if old settings are found Universe = new UniverseHandler(Settings.UniverseHeight, Settings.UniverseWidth); BootUpsets = Settings.Copy(); // Setup the timer timer.Interval = Settings.TickSpeed; // milliseconds timer.Tick += Timer_Tick; timer.Enabled = false; // stop timer running }
private void GetSeedSelection(object sender, EventArgs e) { SeedSelection dlg = new SeedSelection(); dlg.Seed = Settings.Seed; if (DialogResult.OK == dlg.ShowDialog()) { Universe = new UniverseHandler(Settings.UniverseHeight, Settings.UniverseWidth); Settings.Seed = dlg.Seed; Universe.GenerateWorldSeed(dlg.Seed, Settings.torofinite); } graphicsPanel1.Invalidate(); }
private void SettingsMenu(object sender, EventArgs e) { Settings dlg = new Settings(); dlg.Real = Settings; int HoldHeight = Settings.UniverseHeight; int HoldWidth = Settings.UniverseWidth; dlg.ShowDialog(); if (DialogResult.OK == dlg.DialogResult) { Settings = dlg.Temp; timer.Interval = Settings.TickSpeed; } else if (DialogResult.Yes == dlg.DialogResult) { Settings = BootUpsets; } if (Settings.UniverseHeight != HoldHeight || Settings.UniverseWidth != HoldWidth) { Universe = new UniverseHandler(Settings.UniverseHeight, Settings.UniverseWidth); } graphicsPanel1.Invalidate(); }
private void importToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "All Files|*.*|Cells|*.cells"; dlg.FilterIndex = 2; if (DialogResult.OK == dlg.ShowDialog()) { StreamReader reader = new StreamReader(dlg.FileName); int maxWidth = 0; int maxHeight = 0; // Iterate through the file once to get its size. while (!reader.EndOfStream) { // Read one row at a time. string row = reader.ReadLine(); // Ignores ! if (row[0] == '!') { continue; } // If the row is not a comment then it is a row of cells. // Increment the maxHeight variable for each row read. else { maxHeight++; // Get the length of the current row string // and adjust the maxWidth variable if necessary. if (row.Length > maxWidth) { maxWidth = row.Length; } } } // Resize the current universe and scratchPad // to the width and height of the file calculated above. int StartHeight = 0; int StartWidth = 0; if (maxWidth > Universe.CellVerse.GetLength(0) || maxHeight > Universe.CellVerse.GetLength(1)) { Universe = new UniverseHandler(maxWidth, maxHeight); Settings.UniverseHeight = maxHeight; Settings.UniverseWidth = maxWidth; } else { if ((Universe.CellVerse.GetLength(0) - maxWidth) / 2 < 1) { StartWidth = 0; } else { StartWidth = (Universe.CellVerse.GetLength(0) - maxWidth) / 2; } if ((Universe.CellVerse.GetLength(1) - maxHeight) / 2 < 1) { StartHeight = 0; } else { StartHeight = (Universe.CellVerse.GetLength(1) - maxHeight) / 2; } } // Reset the file pointer back to the beginning of the file. reader.BaseStream.Seek(0, SeekOrigin.Begin); // Iterate through the file again, this time reading in the cells. while (!reader.EndOfStream) { // Read one row at a time. string row = reader.ReadLine(); // If the row begins with '!' then // it is a comment and should be ignored. if (row[0] == '!') { continue; } // Not a comment then add them cells else { for (int xPos = 0; xPos < row.Length; xPos++) { // O = Alive if (row[xPos] == 'O') { Universe.CellVerse[xPos + StartWidth, StartHeight] = true; } // . = Dead else { Universe.CellVerse[xPos + StartWidth, StartHeight] = false; } } StartHeight++; } } // ALWAYS CLOSE THE FILE reader.Close(); } Universe.CellCount(Settings.torofinite); graphicsPanel1.Invalidate(); }