00001
00002
00003
00004
00005
00006 namespace MontyHallGame
00007 {
00008 using System;
00009 using Microsoft.Xna.Framework;
00010 using Microsoft.Xna.Framework.Graphics;
00011 using NewGamePhysics.StateManager;
00012 using NewGamePhysics.Physics;
00013 using NewGamePhysics.GraphicalElements;
00014 using NewGamePhysics.Utilities;
00015 using NewGamePhysics.Networking;
00016 using NewGamePhysics.PhysicalElements;
00017
00021 class MontyHallMainMenuScreen : MenuScreen
00022 {
00026 private ScrollingText scrollingInfoText;
00027
00031 public MontyHallMainMenuScreen()
00032 : base("Monty Hall Game")
00033 {
00034
00035 MenuEntry hrngMenuEntry = new MenuEntry("Play with Physical Entropy");
00036 MenuEntry prngMenuEntry = new MenuEntry("Play with Simulated Entropy");
00037 MenuEntry optionsMenuEntry = new MenuEntry("Options and Settings");
00038 MenuEntry helpMenuEntry = new MenuEntry("Game Controls Help");
00039 MenuEntry infoMenuEntry = new MenuEntry("Game Information");
00040 MenuEntry exitMenuEntry = new MenuEntry("Exit Game");
00041
00042
00043 hrngMenuEntry.Selected += HrngMenuEntrySelected;
00044 prngMenuEntry.Selected += PrngMenuEntrySelected;
00045 optionsMenuEntry.Selected += OptionsMenuEntrySelected;
00046 infoMenuEntry.Selected += InfoMenuEntrySelected;
00047 helpMenuEntry.Selected += HelpMenuEntrySelected;
00048 exitMenuEntry.Selected += OnCancel;
00049
00050
00051
00052
00053 Random random = new Random();
00054 if (random.Next(0, 2) == 0)
00055 {
00056 MenuEntries.Add(hrngMenuEntry);
00057 MenuEntries.Add(prngMenuEntry);
00058 }
00059 else
00060 {
00061 MenuEntries.Add(prngMenuEntry);
00062 MenuEntries.Add(hrngMenuEntry);
00063 }
00064
00065
00066 MenuEntries.Add(optionsMenuEntry);
00067 MenuEntries.Add(infoMenuEntry);
00068 MenuEntries.Add(helpMenuEntry);
00069 MenuEntries.Add(exitMenuEntry);
00070 }
00071
00072 public override void LoadContent()
00073 {
00074
00075 SpriteFont font = ScreenManager.Fonts["retro"];
00076 MontyHallGame game = (MontyHallGame)ScreenManager.Game;
00077 int width = game.GraphicsDevice.Viewport.Width;
00078 scrollingInfoText = new ScrollingText("", font, width, 420);
00079 scrollingInfoText.ScrollerSpeed = 125.0f;
00080
00081 base.LoadContent();
00082 }
00083
00084
00095 public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
00096 {
00097 if (WaitForUncover)
00098 {
00099 if ((!coveredByOtherScreen) || (!otherScreenHasFocus))
00100 {
00101
00102 UpdateAllTexts();
00103
00104
00105 ScreenManager.Sounds["intro"].Play();
00106
00107
00108 WaitForUncover = false;
00109 }
00110 }
00111
00112
00113 scrollingInfoText.Update(gameTime);
00114
00115 base.Update(gameTime, otherScreenHasFocus, coveredByOtherScreen);
00116 }
00117
00122 public override void Draw(GameTime gameTime)
00123 {
00124 base.Draw(gameTime);
00125
00126
00127 SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
00128 scrollingInfoText.Draw(gameTime, spriteBatch);
00129 }
00130
00131 #region Handle Input
00132
00138 void HrngMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00139 {
00140
00141 MontyHallGame.state.Rng.EntropySource = EntropySourceType.PlayTrulyRandom;
00142
00143
00144 MontyHallLoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
00145 new MontyHallGameplayScreen());
00146
00147
00148 WaitForUncover = true;
00149 }
00150
00156 void PrngMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00157 {
00158
00159 MontyHallGame.state.Rng.EntropySource = EntropySourceType.Pseudo;
00160
00161
00162 MontyHallLoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
00163 new MontyHallGameplayScreen());
00164
00165
00166 WaitForUncover = true;
00167 }
00168
00174 void OptionsMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00175 {
00176 ScreenManager.AddScreen(new MontyHallOptionsMenuScreen(), e.PlayerIndex);
00177
00178
00179 this.SelectedEntry = 0;
00180
00181
00182 WaitForUncover = true;
00183 }
00184
00190 void InfoMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00191 {
00192
00193 string[] messages = {
00194 "Information on The Monty Game",
00195 "",
00196 "The Monty Game is a game of chance which originated from the show",
00197 "\"Let's Make a Deal\" hosted by host Monty Hall (hence the name).",
00198 "",
00199 "A contestant is presented with 3 doors behind one of which a prize.",
00200 "In the 1st phase of the game, the contestant preselects one door.",
00201 "This door is not opened, but the game show host will reveal a",
00202 "loosing pick in the 2nd phase by opening one of the remaining doors.",
00203 "In the 3rd and last phase of the game, the contestant can choose",
00204 "to open the original door or switch to to claim the prize.",
00205 "",
00206 "So, what is the winning strategy? Stay with the preselected door,",
00207 "switch doors or does it actually matter ... play to find out.",
00208 };
00209
00210 ScreenManager.AddScreen(new MontyHallHelpScreen(messages), e.PlayerIndex);
00211
00212
00213 this.SelectedEntry = 0;
00214
00215
00216 WaitForUncover = true;
00217 }
00218
00224 void HelpMenuEntrySelected(object sender, PlayerIndexEventArgs e)
00225 {
00226
00227 string[] messages = {
00228 "Controls for The Monty Game",
00229 "",
00230 " [Up]/[Down] cursor/pad",
00231 " select menu item",
00232 " [Left]/[Right] cursor/pad",
00233 " select available door to the left/right",
00234 " [Space] or (A)",
00235 " continue in menu, game or help screens",
00236 " Phase 1: pre-select a door",
00237 " Phase 2: let Monty open a loosing door",
00238 " Phase 3: open door to claim a prize",
00239 " [Escape] or (Back)",
00240 " pause game or quit to main menu",
00241 };
00242
00243 ScreenManager.AddScreen(new MontyHallHelpScreen(messages), e.PlayerIndex);
00244
00245
00246 this.SelectedEntry = 0;
00247
00248
00249 WaitForUncover = true;
00250 }
00251
00257 protected override void OnCancel(PlayerIndex playerIndex)
00258 {
00259 const string message = "Are you sure you want to exit?";
00260
00261 MontyHallMessageBoxScreen confirmExitMessageBox = new MontyHallMessageBoxScreen(message);
00262
00263 confirmExitMessageBox.Accepted += ConfirmExitMessageBoxAccepted;
00264
00265 ScreenManager.AddScreen(confirmExitMessageBox, playerIndex);
00266 }
00267
00274 void ConfirmExitMessageBoxAccepted(object sender, PlayerIndexEventArgs e)
00275 {
00276 ScreenManager.Game.Exit();
00277 }
00278
00279 #endregion
00280
00284 private void UpdateAllTexts()
00285 {
00286
00287 if (null != scrollingInfoText)
00288 {
00289 scrollingInfoText.Text =
00290 "The Monty Hall Game (C) A. Schiffler 2009-2011, aschiffler@ferzkopp.net - source code is available upon request." +
00291 " * " +
00292 "This game tracks some anonymous usage statistics as part of the authors PhD research into 'New Game Physics'. If you don't agree to this, please quit now." +
00293 " * " +
00294 "Physical entropy is provided by the playtrulyrandom.com webservice. Please navigate to the website for more technical and scientific information." +
00295 " * " +
00296 "Simulated entropy provided by the internal C# System.Random class. Please check the Microsoft MSDN website for more information.";
00297 }
00298 }
00299 }
00300 }