BatteryStatusGame.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using Microsoft.Xna.Framework;
  3. using Microsoft.Xna.Framework.Graphics;
  4. using Microsoft.Xna.Framework.Input;
  5. namespace BatteryStatus
  6. {
  7. public class BatteryStatusGame : Game, IDisposable
  8. {
  9. GraphicsDeviceManager graphics;
  10. SpriteBatch spriteBatch = null!;
  11. SpriteFont font = null!;
  12. private readonly IPowerStatus powerStatus;
  13. public BatteryStatusGame(IPowerStatus powerStatus)
  14. {
  15. this.powerStatus = powerStatus ?? throw new ArgumentNullException(nameof(powerStatus));
  16. graphics = new GraphicsDeviceManager(this);
  17. Content.RootDirectory = "Content";
  18. IsMouseVisible = true;
  19. }
  20. protected override void Initialize()
  21. {
  22. base.Initialize();
  23. }
  24. protected override void LoadContent()
  25. {
  26. spriteBatch = new SpriteBatch(GraphicsDevice);
  27. font = Content.Load<SpriteFont>("SpriteFont1");
  28. }
  29. protected override void Update(GameTime gameTime)
  30. {
  31. base.Update(gameTime);
  32. // Exit the game if the back button is pressed or Escape key is pressed
  33. if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
  34. Exit();
  35. }
  36. protected override void Draw(GameTime gameTime)
  37. {
  38. graphics.GraphicsDevice.Clear(Color.MonoGameOrange);
  39. spriteBatch.Begin();
  40. spriteBatch.DrawString(font, "[Battery Status]\n" + powerStatus.BatteryChargeStatus, new Vector2(10, 100), Color.Black);
  41. spriteBatch.DrawString(font, "[PowerLine Status]\n" + powerStatus.PowerLineStatus, new Vector2(10, 200), Color.Black);
  42. spriteBatch.DrawString(font, "[Charge]\n" + powerStatus.BatteryLifePercent + "%", new Vector2(10, 300), Color.Black);
  43. spriteBatch.End();
  44. base.Draw(gameTime);
  45. }
  46. public new void Dispose()
  47. {
  48. base.Dispose();
  49. }
  50. }
  51. }