private void BtnRandomize_Click(object sender, EventArgs e) { btnRandomize.Text = "Randomizing..."; btnRandomize.Enabled = false; this.UseWaitCursor = true; // Store all information about items and areas from the game if (mem.HookProcess()) { textBoxInfo.Text = ""; /* Generate a new seed if blank */ if (string.IsNullOrWhiteSpace(textSeed.Text)) { SetSeedBasedOnDifficulty(); } StringBuilder sb = new StringBuilder(); string difficulty = GetRandomizerDifficulty(); sb.Append("Selecting difficulty is ").AppendLine(difficulty); textBoxInfo.Text = sb.ToString(); string seed = GetSeed(); if (string.IsNullOrWhiteSpace(seed)) { btnRandomize.Text = "Randomize"; btnRandomize.Enabled = false; this.UseWaitCursor = false; return; } int parsedSeed; if (!int.TryParse(seed, out parsedSeed)) { MessageBox.Show("Seed must be numeric or blank.", "Seed Error", MessageBoxButtons.OK, MessageBoxIcon.Error); sb.AppendLine("Seed must be numeric or blank."); textBoxInfo.Text = sb.ToString(); btnRandomize.Text = "Randomize"; btnRandomize.Enabled = false; this.UseWaitCursor = false; return; } sb.Append("Seed is ").AppendLine(seed); textBoxInfo.Text = sb.ToString(); sb.AppendLine("Collecting upgrades..."); textBoxInfo.Text = sb.ToString(); textBoxInfo.Update(); mem.SaveAllUpgrades(); sb.Append("Found: ").AppendLine(mem.PrintAllUpgrades()); sb.AppendLine("Collecting cave entries..."); textBoxInfo.Text = sb.ToString(); textBoxInfo.Update(); mem.SaveAllAreaEntries(); sb.Append("Found: ").AppendLine(mem.PrintAllAreaEntries()); sb.AppendLine("Collecting cave exits..."); textBoxInfo.Text = sb.ToString(); textBoxInfo.Update(); mem.SaveAllAreaExits(); sb.Append("Found: ").AppendLine(mem.PrintAllAreaExits()); textBoxInfo.Text = sb.ToString(); textBoxInfo.Update(); List <Location> locations; if (difficulty == "Speedrunner") { locations = new LocationsSpeedrunner().Locations; } else { locations = new LocationsCasual().Locations; } SteamWorldRandomizer randomizer = new SteamWorldRandomizer(mem, parsedSeed, locations); sb.Append("Starting building a randomizer"); textBoxInfo.Text = sb.ToString(); textBoxInfo.Update(); int ret = 0; for (int i = 0; i < 1000; i++) { ret = randomizer.Randomize(); if (ret == -1) { sb.AppendLine("").AppendLine("Error occured: mismatch number of upgrades"); textBoxInfo.Text = sb.ToString(); break; } if (ret == -2) { sb.AppendLine("").AppendLine("Error occured: mismatch number of areas"); textBoxInfo.Text = sb.ToString(); break; } if (ret == 1) { sb.AppendLine("").AppendLine("Successfully found a correct case!"); textBoxInfo.Text = sb.ToString(); break; } sb.Append("."); textBoxInfo.Text = sb.ToString(); textBoxInfo.Update(); } if (ret == 0) { sb.AppendLine("").AppendLine("Could not find any correct case..."); textBoxInfo.Text = sb.ToString(); } } btnRandomize.Text = "Randomize"; btnRandomize.Enabled = false; this.UseWaitCursor = false; }