Example #1
0
        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);
        }
Example #2
0
        /// <summary>
        /// Create UI mock to communicate with the backend.
        /// </summary>
        ///
        /// <returns>
        /// New <see cref="BackendInstance"/> instance with related objects in a tuple.
        /// </returns>
        public (BackendInstance, IEnumerable <SpeciesClass>, MockUI ui) CreateBackend()
        {
            MockUI          ui      = new MockUI();
            BackendInstance backEnd = BackendInstance.GetInstance(ui, rng);

            IList <Species> loadedSpecies
                = backEnd.GetLoadedSpecies().ToList();

            Assert.NotEmpty(loadedSpecies);

            IEnumerable <SpeciesClass> allClasses
                = SpeciesUtils.GetSpeciesClasses(loadedSpecies);

            Assert.NotEmpty(allClasses);

            return(backEnd, allClasses, ui);
        }