- Main Page
- Classes
- Files

- File List

# C:/Users/Andreas Schiffler/Desktop/SVN/NewGamePhysics/MontyHallGame/Screens/MontyHallGameOverScreen.cs

    00001 ﻿//-----------------------------------------------------------------------------
    00002 // MontyHallGameOverScreen.cs
    00003 // (C) A. Schiffler, 2009-2011
    00004 //-----------------------------------------------------------------------------
    00005
    00006 namespace MontyHallGame
    00007 {
    00008     using System;
    00009     using System.Threading;
    00010     using Microsoft.Xna.Framework;
    00011     using Microsoft.Xna.Framework.Content;
    00012     using Microsoft.Xna.Framework.Graphics;
    00013     using NewGamePhysics.StateManager;
    00014
    00018     class MontyHallGameOverScreen : MenuScreen
    00019     {
    00020         #region Initialization
    00021
    00025         public MontyHallGameOverScreen(string title)
    00026             : base(title)
    00027         {
    00028             // Flag that there is no need for the game to transition
    00029             // off when the pause menu is on top of it.
    00030             IsPopup = true;
    00031
    00032             // Create our menu entries.
    00033             MenuEntry continueMenuEntry = new MenuEntry("Continue and Play Again");
    00034             MenuEntry returnMenuEntry = new MenuEntry("Return to Main Menu");
    00035
    00036             // Hook up menu event handlers.
    00037             continueMenuEntry.Selected += OnContinue;
    00038             returnMenuEntry.Selected += OnReturn;
    00039
    00040             // Add entries to the menu.
    00041             MenuEntries.Add(continueMenuEntry);
    00042             MenuEntries.Add(returnMenuEntry);
    00043         }
    00044
    00045         #endregion
    00046
    00047         #region Handle Input
    00048
    00052         void OnContinue(object sender, PlayerIndexEventArgs e)
    00053         {
    00054             MontyHallLoadingScreen.Load(ScreenManager, true, e.PlayerIndex,
    00055                                new MontyHallGameplayScreen());
    00056         }
    00057
    00061         void OnReturn(object sender, PlayerIndexEventArgs e)
    00062         {
    00063             // Submit play time
    00064             SubmitUsage(Convert.ToInt32(MontyHallGame.state.playTime));
    00065
    00066             MontyHallLoadingScreen.Load(ScreenManager, false, null, new MontyHallBackgroundScreen(),
    00067                                                            new MontyHallMainMenuScreen());
    00068         }
    00069
    00070         #endregion
    00071
    00072         #region Draw
    00073
    00078         public override void Draw(GameTime gameTime)
    00079         {
    00080             ScreenManager.FadeBackBufferToBlack(TransitionAlpha * 4 / 5);
    00081
    00082             // Messages
    00083             string[] messages = new string[4];
    00084             messages[0] = "Statistics:";
    00085             messages[1] = "  Games Won: " + MontyHallGame.state.Wins;
    00086             messages[2] = "  Games Lost: " + MontyHallGame.state.Losses;
    00087             messages[3] = "  Switched Doors: " + MontyHallGame.state.Switches + " times";
    00088
    00089             int totalGames = MontyHallGame.state.Wins + MontyHallGame.state.Losses;
    00090             if (totalGames > 0)
    00091             {
    00092                 if (MontyHallGame.state.Wins > 0)
    00093                 {
    00094                     messages[1] += "    (" +
    00095                         string.Format("{0:.%}", (double)MontyHallGame.state.Wins / (double)totalGames) +
    00096                         " of games)";
    00097                 }
    00098
    00099                 if (MontyHallGame.state.Losses > 0)
    00100                 {
    00101                     messages[2] += "    (" +
    00102                         string.Format("{0:.%}", (double)MontyHallGame.state.Losses / (double)totalGames) +
    00103                         " of games)";
    00104                 }
    00105
    00106
    00107                 if (MontyHallGame.state.Switches > 0)
    00108                 {
    00109                     messages[3] += "    (" +
    00110                         string.Format("{0:.%}", (double)MontyHallGame.state.Switches / (double)totalGames) +
    00111                         " of games)";
    00112                 }
    00113             }
    00114
    00115             // Draw score summary
    00116             SpriteBatch spriteBatch = ScreenManager.SpriteBatch;
    00117             SpriteFont font = ScreenManager.Fonts["retro"];
    00118             Viewport viewport = ScreenManager.GraphicsDevice.Viewport;
    00119             Color color = Color.White;
    00120             Vector2 origin = new Vector2(0, 0);
    00121             Vector2 position = new Vector2(viewport.Width * 0.25f, viewport.Height * 0.55f);
    00122             spriteBatch.Begin();
    00123             foreach (string message in messages)
    00124             {
    00125                 spriteBatch.DrawString(
    00126                     font,
    00127                     message,
    00128                     position,
    00129                     color,
    00130                     0,
    00131                     origin,
    00132                     1.0f,
    00133                     SpriteEffects.None,
    00134                     0);
    00135                 position.Y += (viewport.Height * 0.05f);
    00136             }
    00137             spriteBatch.End();
    00138
    00139             base.Draw(gameTime);
    00140         }
    00141
    00142         #endregion
    00143
    00150         private void SubmitUsage(int usageSeconds)
    00151         {
    00152             // Maybe submit
    00153             Thread t;
    00154             if (usageSeconds > 0)
    00155             {
    00156                 t = new System.Threading.Thread(MontyHallGame.state.Rng.PlayTrulyRandom.OnlineUsage);
    00157                 t.Start(usageSeconds);
    00158             }
    00159         }
    00160
    00161     }
    00162 }
    00163
    00164