GameScreen.cs 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // GameScreen.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. // #define TutorialVersion //Uncomment this line to play the tutorial version
  10. #region Using Statements
  11. using System;
  12. using Microsoft.Xna.Framework;
  13. using Microsoft.Xna.Framework.Graphics;
  14. #endregion
  15. namespace Marblets
  16. {
  17. /// <summary>
  18. /// GameScreen is the screen that is loaded to play Marblets
  19. /// </summary>
  20. class GameScreen : Screen
  21. {
  22. private GameBoard board;
  23. private Texture2D gameOver;
  24. public GameScreen(Game game, string backgroundImage, SoundEntry backgroundMusic)
  25. : base(game, backgroundImage, backgroundMusic)
  26. {
  27. //Remove the define at the top of the file to play the tutorial version
  28. bool tutorialVersion = false;
  29. #if TutorialVersion
  30. tutorialVersion = true;
  31. #endif
  32. if(tutorialVersion)
  33. {
  34. board = new TutorialGameBoard(this.Game);
  35. }
  36. else
  37. {
  38. board = new GameBoard(this.Game);
  39. }
  40. }
  41. public override void Initialize()
  42. {
  43. base.Initialize();
  44. board.Initialize();
  45. }
  46. public override void Update(GameTime gameTime)
  47. {
  48. base.Update(gameTime);
  49. board.Update(gameTime);
  50. if(board.GameOver && (InputHelper.GamePads[PlayerIndex.One].APressed || Clicked))
  51. {
  52. MarbletsGame.NextGameState = GameState.Started;
  53. }
  54. }
  55. protected override void LoadContent()
  56. {
  57. gameOver = MarbletsGame.Content.Load<Texture2D>("Textures/game_over_frame");
  58. base.LoadContent();
  59. }
  60. public override void Draw(GameTime gameTime)
  61. {
  62. base.Draw(gameTime);
  63. SpriteBatch.Begin();
  64. board.Draw(SpriteBatch);
  65. //Draw Score
  66. Font.Draw(SpriteBatch, FontStyle.Small, 20, 440,
  67. String.Format("{0:###,##0}", MarbletsGame.Score));
  68. if(board.GameOver)
  69. {
  70. SpriteBatch.Draw(gameOver, new Vector2(0, 60), Color.White);
  71. }
  72. SpriteBatch.End();
  73. }
  74. public void NewGame()
  75. {
  76. board.NewGame();
  77. }
  78. }
  79. }