Represents the currently logged in minecraft user.
 /// <summary>
 /// Initializes a new instance of Sharpcraft.
 /// </summary>
 public Sharpcraft(User user)
 {
     _log = LogManager.GetLogger(this);
     _settings = new GameSettings(Constants.GameSettings);
     _user = user;
     if (File.Exists(Constants.GameSettings))
     {
         _log.Info("Loading game settings from file...");
         var reader = new StreamReader(Constants.GameSettings);
         _settings = new JsonSerializer().Deserialize<GameSettings>(new JsonTextReader(reader));
         _log.Info("Game settings loaded successfully!");
         reader.Close();
     }
     else
     {
         _settings = new GameSettings(Constants.GameSettings) {Size = new Point(1280, 720)};
     }
     _log.Debug("Initializing graphics device.");
     _graphics = new GraphicsDeviceManager(this);
     if (_settings.Fullscreen)
     {
         _graphics.IsFullScreen = true;
         _settings.Size = new Point(SystemInformation.PrimaryMonitorSize.Width, SystemInformation.PrimaryMonitorSize.Height);
     }
     _graphics.PreferredBackBufferWidth = _settings.Size.X;
     _graphics.PreferredBackBufferHeight = _settings.Size.Y;
     _log.Debug("Setting content directory.");
     Content.RootDirectory = Constants.ContentDirectory;
     _log.Debug("Creating DebugDisplay...");
     Components.Add(new DebugDisplay(this, _graphics));
     #if DEBUG
     _gameMenuOpen = true;
     #endif
 }
Exemple #2
0
 /// <summary>
 /// Handler for when user presses the login button.
 /// </summary>
 /// <param name="sender">N/A (Not Used) (See MSDN)</param>
 /// <param name="e">N/A (Not Used) (See MSDN)</param>
 private void LoginButtonClick(object sender, EventArgs e)
 {
     _log.Debug("Login button clicked.");
     if (!ValidLogin() || _gameRunning)
         return;
     Enabled = false;
     _user = new User(UserBox.Text);
     _settings.Username = _user.GetName();
     _settings.Remember = RememberCheckbox.Checked;
     if (_settings.Remember)
         _settings.SetPassword(PassBox.Text);
     _settings.WriteToFile();
     _loginThread = new Thread(() => _auth.Login(_user.GetName(), PassBox.Text)) {Name = "Login"};
     _loginThread.Start();
 }