Score.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using Microsoft.Xna.Framework;
  2. using Microsoft.Xna.Framework.Graphics;
  3. namespace Tetris
  4. {
  5. /// <summary>
  6. /// This is a game component that implements IUpdateable.
  7. /// </summary>
  8. public class Score : Microsoft.Xna.Framework.DrawableGameComponent
  9. {
  10. // Graphic
  11. protected SpriteBatch sBatch;
  12. protected SpriteFont font;
  13. // Counters
  14. protected int value;
  15. protected int level;
  16. protected int recordScore = 0;
  17. protected string recordPlayer = "Player 1";
  18. public Score (Game game,SpriteFont font)
  19. : base(game) {
  20. sBatch = (SpriteBatch)Game.Services.GetService (typeof(SpriteBatch));
  21. this.font = font;
  22. }
  23. /// <summary>
  24. /// Allows the game component to perform any initialization it needs to before starting
  25. /// to run. This is where it can query for any required services and load content.
  26. /// </summary>
  27. public override void Initialize ()
  28. {
  29. value = 0;
  30. level = 1;
  31. base.Initialize ();
  32. }
  33. public int Value {
  34. set { this.value = value; }
  35. get { return value; }
  36. }
  37. public int Level {
  38. set { level = value; }
  39. get { return level; }
  40. }
  41. public int RecordScore {
  42. set { recordScore = value; }
  43. get { return recordScore; }
  44. }
  45. public string RecordPlayer {
  46. set { recordPlayer = value; }
  47. get { return recordPlayer; }
  48. }
  49. /// <summary>
  50. /// This is called when the game should draw itself.
  51. /// </summary>
  52. /// <param name="gameTime">Provides a snapshot of timing values.</param>
  53. public override void Draw (GameTime gameTime)
  54. {
  55. sBatch.DrawString (font, "Score:\n" + value + "\nLevel: " + level, new Vector2 (1.5f * 24, 3 * 24), Color.Green);
  56. sBatch.DrawString (font, "Record:\n" + recordPlayer + "\n" + recordScore, new Vector2 (1.5f * 24, 13 * 24), Color.Orange);
  57. base.Draw (gameTime);
  58. }
  59. }
  60. }