static void Main() { Logger.Info("Starting Win32 frontend."); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); SignalHandler globalSignalHandler = new SignalHandler(); // Initialize UI handler. UIAdapterImplementation winUi = new UIAdapterImplementation(globalSignalHandler); // Initialize rng. Random rng = new Random(); // Create game logic instance. BackendInstance backend = BackendInstance.GetInstance(winUi, rng); IEnumerable <Species> loadedSpecies = backend.GetLoadedSpecies(); IEnumerable <SpeciesClass> loadedSpeciesClasses = SpeciesUtils.GetSpeciesClasses(loadedSpecies); const string soundDirectory = "assets"; SoundTool player = new SoundTool(); player.AddSound(SoundEffect.Correct, Path.Combine(soundDirectory, "correct.wav")); player.AddSound(SoundEffect.Wrong, Path.Combine(soundDirectory, "wrong.wav")); player.AddSound(SoundEffect.Error, Path.Combine(soundDirectory, "error.wav")); player.AddSound(SoundEffect.Done, Path.Combine(soundDirectory, "done.wav")); // Initialize default settings. GameSettings settings = new GameSettings { InputStyle = InputStyle.MultiChoice, NumberOfChoices = 3, GetChoicesFromSameClass = true, NumberOfQuestions = 10, AllowDuplicates = false, TimePerImage = null, SpeciesClasses = loadedSpeciesClasses }; string[] infoText = GetInfoText(loadedSpecies, loadedSpeciesClasses); var startForm = new RiistaTunnistusOhjelma( globalSignalHandler , backend , winUi , player , settings , infoText ); Application.Run(startForm); }
/// <summary> /// Create the main form. /// </summary> /// <param name="signalHandler">Injected signal handler.</param> /// <param name="backend">Injected game logic.</param> /// <param name="uiAdapter">UI Adapter used to communicate with backend.</param> /// <param name="settings">Initial settings.</param> /// <param name="infoText"></param> internal RiistaTunnistusOhjelma( SignalHandler signalHandler , BackendInstance backend , UIAdapterImplementation uiAdapter , SoundTool soundPlayer , GameSettings settings , string[] infoText) { _signalHandler = signalHandler; _backend = backend; _settings = settings; _ui = uiAdapter; _soundPlayer = soundPlayer; _allSpeciesClasses = _settings.SpeciesClasses; signalHandler.FatalError += (sender, s) => Exit(); InitializeComponent(); InitializeControlValues(settings, infoText); }
/// <summary> /// Construct <see cref="Game"/> form. /// </summary> /// <param name="settings">Injected game settings.</param> /// <param name="ui">Injected UI adapter.</param> /// <param name="soundPlayer">Injected sound player.</param> internal Game(GameSettings settings, UIAdapterImplementation ui, SoundTool soundPlayer) { _settings = settings; _ui = ui; _soundPlayer = soundPlayer; _ui.RegisterUserInterface(this); InitializeComponent(); Logger.Debug($"{nameof(Game)} initialized."); if (settings.TimePerImage == null) { progressBar1.Hide(); } else { progressBar1.Minimum = 0; progressBar1.Maximum = ProgressBarMax; } // Signal the logic to start the game with a tiny delay. Task.Delay(500).ContinueWith(t => _ui.InvokeOnStart()); }