protected override void OnStartup(StartupEventArgs startupEventArgs) { base.OnStartup(startupEventArgs); var mainWindow = new MainWindow(); Thread.CurrentThread.Name = "main"; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; try { var assemblyLocation = Assembly.GetExecutingAssembly().Location; var settingsLocation = Path.Combine(Directory.GetParent(assemblyLocation) !.Parent !.FullName, "settings.json"); var interactionService = new InteractionService(mainWindow); var dispatcher = new SimpleDispatcher(Dispatcher.CurrentDispatcher); var core = new Core.Core(new FileInfo(settingsLocation), interactionService, dispatcher); var vm = core.GetViewModel(); void ShowUpdateNotification(string message) { dispatcher.ExecuteSynchronized(() => { vm.AddNotification(new NotificationEvent(message)); }); } UpdateHelper.Update(ShowUpdateNotification); mainWindow.DataContext = vm; mainWindow.Show(); core.Dispose(); } catch (Exception e) { _logger.Error(e); throw; } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { // Allows the game to exit if (Keyboard.GetState().IsKeyDown(Keys.Escape)) { if (core != null) { core.Dispose(); } core = null; Menu.Return.Message = "OK"; GameState.setState("Menu"); } MouseHandler.Update(gameTime); KeyboardHandler.Update(gameTime); if (GameState.getState() == "Menu") { if (menu == null) { menu = new Menu.Menu(); } else { var msg = menu.Update(gameTime); switch (msg) { case "OK": break; case "Exit": Exit(); break; default: var ctor = typeof(Song).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(string), typeof(string), typeof(int) }, null); Song song = (Song)ctor.Invoke(new object[] { "name", msg, 0 }); core = new Core.Core(song); menu = null; GameState.setState("Game"); break; } } } else { if (core != null) { var msg = core.Update(gameTime); switch (msg) { case "DEAD": break; default: break; } } } // TODO: Add your update logic here base.Update(gameTime); }