2
0

Game1.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using Microsoft.Xna;
  3. using Microsoft.Xna.Framework;
  4. using Microsoft.Xna.Framework.Graphics;
  5. using Microsoft.Xna.Samples;
  6. using Microsoft.Xna.Samples.BatteryStatus;
  7. namespace Microsoft.Xna.Samples.BatteryStatus
  8. {
  9. /// <summary>
  10. /// This is the main type for your game
  11. /// </summary>
  12. public class Game1 : Microsoft.Xna.Framework.Game
  13. {
  14. GraphicsDeviceManager graphics;
  15. SpriteBatch spriteBatch;
  16. SpriteFont font;
  17. public Game1()
  18. {
  19. graphics = new GraphicsDeviceManager(this);
  20. Content.RootDirectory = "Content";
  21. graphics.IsFullScreen = true;
  22. }
  23. /// <summary>
  24. /// Allows the game to perform any initialization it needs to before starting to run.
  25. /// This is where it can query for any required services and load any non-graphic
  26. /// related content. Calling base.Initialize will enumerate through any components
  27. /// and initialize them as well.
  28. /// </summary>
  29. protected override void Initialize()
  30. {
  31. // TODO: Add your initialization logic here
  32. base.Initialize();
  33. }
  34. /// <summary>
  35. /// LoadContent will be called once per game and is the place to load
  36. /// all of your content.
  37. /// </summary>
  38. protected override void LoadContent()
  39. {
  40. // Create a new SpriteBatch, which can be used to draw textures.
  41. spriteBatch = new SpriteBatch(GraphicsDevice);
  42. font = Content.Load<SpriteFont>("SpriteFont1");
  43. }
  44. /// <summary>
  45. /// Allows the game to run logic such as updating the world,
  46. /// checking for collisions, gathering input, and playing audio.
  47. /// </summary>
  48. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  49. protected override void Update(GameTime gameTime)
  50. {
  51. // TODO: Add your update logic here
  52. base.Update(gameTime);
  53. }
  54. /// <summary>
  55. /// This is called when the game should draw itself.
  56. /// </summary>
  57. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  58. protected override void Draw(GameTime gameTime)
  59. {
  60. graphics.GraphicsDevice.Clear(Color.CornflowerBlue);
  61. spriteBatch.Begin();
  62. spriteBatch.DrawString(font,"[Battery Status]\n" + PowerStatus.BatteryChargeStatus,new Vector2(10,100),Color.Black);
  63. spriteBatch.DrawString(font,"[PowerLine Status]\n" + PowerStatus.PowerLineStatus,new Vector2(10,200),Color.Black);
  64. spriteBatch.DrawString(font,"Charge: " + PowerStatus.BatteryLifePercent+"%",new Vector2(10,300),Color.Black);
  65. spriteBatch.End();
  66. base.Draw(gameTime);
  67. }
  68. }
  69. }