private void runSimulationButton_Click(object sender, EventArgs e) { battleResultTextBox.Clear(); try { ValidateFileInput(fleet1TextBox, "fleet 1"); ValidateFileInput(fleet2TextBox, "fleet 2"); int seed = ValidateSeed(); Random random = new Random(seed); Fleet fleet1 = CreateFleet(random, fleet1TextBox.Text); Fleet fleet2 = CreateFleet(random, fleet2TextBox.Text); SpaceBattle battle = new SpaceBattle(fleet1, fleet2); IBattleObserver observer = new BattleObserverImpl(battleResultTextBox); // add observer battle.Subscribe(observer); battle.CommenceBattle(); battle.ReportBattleResults(); // clean up, remove observer battle.UnSubscribe(observer); } catch (Exception ex) { MessageBox.Show("Program failed with the following error" + Environment.NewLine + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private static void Main(string[] args) { Console.WriteLine("TrekBattle by Jeremy Yuille"); int seed; if (!ValidInputArguments(args, out seed)) { return; } Random randomGenerator = new Random(seed); FleetLoader fleetLoader = new FleetLoader(args[1], randomGenerator); Fleet firstFleet = fleetLoader.LoadFleet(); Fleet secondFleet = null; if (firstFleet != null) { fleetLoader = new FleetLoader(args[ThirdArgument], randomGenerator); secondFleet = fleetLoader.LoadFleet(); } if (secondFleet == null) { return; } SpaceBattle battle = new SpaceBattle(firstFleet, secondFleet); battle.CommenceBattle(); battle.ReportBattleResults(); }