00001
00002
00003
00004
00005
00006 namespace MontyHallGame
00007 {
00008 using System;
00009 using System.Threading;
00010 using System.Collections.Generic;
00011
00012 using Microsoft.Xna.Framework;
00013 using Microsoft.Xna.Framework.Content;
00014 using Microsoft.Xna.Framework.Graphics;
00015 using Microsoft.Xna.Framework.Input;
00016
00017 using NewGamePhysics.StateManager;
00018 using NewGamePhysics.Utilities;
00019 using NewGamePhysics.GraphicalElements;
00020 using NewGamePhysics.PhysicalElements;
00021
00025 class MontyHallHelpScreen : GameScreen
00026 {
00027
00031 private ContentManager contentManager;
00032
00033
00034 private List<string> messages;
00035
00039 private int numRows;
00040
00044 private int currentRow;
00045
00049 private float fadeSpeed = 0.1f;
00050
00054 private float[] textAlpha;
00055
00056 #region Initialization
00057
00062 public MontyHallHelpScreen(string[] screenMessage)
00063 {
00064
00065 this.messages = new List<string>();
00066
00067
00068 this.messages.AddRange(screenMessage);
00069
00070
00071 string[] exitMessage = {"", "", "[Key] or (Button) to return to Main Menu"};
00072 this.messages.AddRange(exitMessage);
00073
00074 TransitionOnTime = TimeSpan.FromSeconds(0.5);
00075 TransitionOffTime = TimeSpan.FromSeconds(0.5);
00076 }
00077
00081 public override void LoadContent()
00082 {
00083 if (this.contentManager == null)
00084 {
00085 this.contentManager = new ContentManager(ScreenManager.Game.Services, "Content");
00086 }
00087
00088
00089 numRows = messages.Count;
00090 currentRow = 0;
00091 textAlpha = new float[numRows];
00092 for (int i = 0; i < numRows; i++)
00093 {
00094 textAlpha[i] = 0.0f;
00095 }
00096
00097
00098 ScreenManager.Game.ResetElapsedTime();
00099 }
00100
00104 public override void UnloadContent()
00105 {
00106 this.contentManager.Unload();
00107 }
00108
00109 #endregion
00110
00111 #region Update and Draw
00112
00116 public override void Update(GameTime gameTime, bool otherScreenHasFocus,
00117 bool coveredByOtherScreen)
00118 {
00119 base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
00120
00121 if (IsActive)
00122 {
00123
00124 if (currentRow < numRows)
00125 {
00126 textAlpha[currentRow] += fadeSpeed;
00127 if (string.IsNullOrEmpty(messages[currentRow]) ||
00128 (textAlpha[currentRow] >= 1.0f))
00129 {
00130 textAlpha[currentRow] = 1.0f;
00131 currentRow++;
00132 }
00133 }
00134 }
00135 }
00136
00141 public override void HandleInput(InputState input)
00142 {
00143 if (input == null)
00144 {
00145 throw new ArgumentNullException("input");
00146 }
00147
00148
00149 PlayerIndex playerIndex = ControllingPlayer.Value;
00150
00151 KeyboardState keyboardState = input.CurrentKeyboardStates[(int)playerIndex];
00152 GamePadState gamePadState = input.CurrentGamePadStates[(int)playerIndex];
00153
00154
00155
00156
00157
00158 bool gamePadDisconnected = !gamePadState.IsConnected &&
00159 input.GamePadWasConnected[(int)playerIndex];
00160
00161
00162 if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
00163 {
00164 MontyHallLoadingScreen.Load(ScreenManager, false, null, new MontyHallBackgroundScreen(),
00165 new MontyHallMainMenuScreen());
00166 }
00167 }
00168
00172 public override void Draw(GameTime gameTime)
00173 {
00174
00175 PrimitiveBatch primitiveBatch = ScreenManager.PrimitiveBatch;
00176 SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
00177 Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
00178 SpriteFont font = ScreenManager.Fonts["game"];
00179
00180
00181 Color color = Color.White;
00182 Vector2 origin = new Vector2(0, 0);
00183 Vector2 position = new Vector2(viewport.Width * 0.05f, viewport.Height * 0.05f);
00184 float scale = 0.5f;
00185 spriteBatch.Begin();
00186 for (int i=0; i<numRows; i++)
00187 {
00188 string message = messages[i];
00189 if (textAlpha[i] > 0.0f)
00190 {
00191 if (string.IsNullOrEmpty(message))
00192 {
00193
00194 position.Y += ((float)font.LineSpacing * 0.5f * scale);
00195 }
00196 else
00197 {
00198 color = new Color(Color.White, MathHelper.SmoothStep(0.0f, 1.0f, textAlpha[i]));
00199 spriteBatch.DrawString(
00200 font,
00201 message,
00202 position,
00203 color,
00204 0,
00205 origin,
00206 scale,
00207 SpriteEffects.None,
00208 0);
00209 position.Y += ((float)font.LineSpacing * 1.2f * scale);
00210 }
00211 }
00212 }
00213 spriteBatch.End();
00214
00215
00216 if (TransitionPosition > 0)
00217 {
00218 ScreenManager.FadeBackBufferToBlack(255 - TransitionAlpha);
00219 }
00220
00221 base.Draw(gameTime);
00222 }
00223
00224 #endregion
00225 }
00226 }