/// <summary> /// Runs the game. /// </summary> private void RunGame() { _log.Debug("RunGame();"); _game = new Sharpcraft(_user); _log.Debug("Registering to Game.Exiting event."); _game.Exiting += GameExit; _gameRunning = true; _log.Info("Running game..."); SetState(false); try { _game.Run(); } catch (System.Net.Sockets.SocketException ex) // This should be catched/checked somewhere else. { _log.Warn("Failed to connect to server. " + ex.GetType() + " thrown: " + ex.Message); _log.Warn("Stack Trace:\n" + ex.StackTrace); MessageBox.Show("Failed to connect to server! " + ex.GetType() + " thrown with message: " + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); _game.Exiting -= GameExit; if (_game.IsActive) { _game.Exit(); } _gameRunning = false; _game = null; SetState(true); } _log.Debug("RunGame(); ## END ##"); }
/// <summary> /// Close the game and unload components. /// </summary> private void CloseGame() { _log.Info("Unloading game components..."); _game.Dispose(); if (_game.IsActive) { _game.Exit(); } //_gameThread.Abort(); // Causes application to freeze indefinately. //_gameThread.Join(); if (_game != null) { _game.Exiting -= GameExit; } _game = null; _gameRunning = false; _log.Info("Game components unloaded!"); }
/// <summary> /// Runs the game. /// </summary> private void RunGame() { _log.Debug("RunGame();"); _game = new Sharpcraft(_user); _log.Debug("Registering to Game.Exiting event."); _game.Exiting += GameExit; _gameRunning = true; _log.Info("Running game..."); SetState(false); try { _game.Run(); } catch(System.Net.Sockets.SocketException ex) // This should be catched/checked somewhere else. { _log.Warn("Failed to connect to server. " + ex.GetType() + " thrown: " + ex.Message); _log.Warn("Stack Trace:\n" + ex.StackTrace); MessageBox.Show("Failed to connect to server! " + ex.GetType() + " thrown with message: " + ex.Message, "Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); _game.Exiting -= GameExit; if (_game.IsActive) _game.Exit(); _gameRunning = false; _game = null; SetState(true); } _log.Debug("RunGame(); ## END ##"); }
/// <summary> /// Close the game and unload components. /// </summary> private void CloseGame() { _log.Info("Unloading game components..."); _game.Dispose(); if (_game.IsActive) _game.Exit(); //_gameThread.Abort(); // Causes application to freeze indefinately. //_gameThread.Join(); if (_game != null) _game.Exiting -= GameExit; _game = null; _gameRunning = false; _log.Info("Game components unloaded!"); }