]> Dogcows Code - chaz/carfire/blobdiff - Project06/CS 3505 Project 06/CS 3505 Project 06/Game06.cs
Added to functionality of gui. Also added 2 methods I needed in NetworkGame, comments...
[chaz/carfire] / Project06 / CS 3505 Project 06 / CS 3505 Project 06 / Game06.cs
index 0a4a228aa3ce6e063e55e014343403e5c02520f1..c6f21f66ea14396d518c0abcdad00476bfa1789a 100644 (file)
@@ -21,19 +21,12 @@ namespace CS_3505_Project_06
     {\r
         GraphicsDeviceManager graphics;\r
         SpriteBatch spriteBatch;\r
-        SpriteFont font;\r
-        \r
-        IDeterministicGame deterministicGame;\r
-        TimeSpan targetTimeSpan;\r
-        Object[] playerIdentifiers = { "One", "Two", "Three", "Four" };  // Any objects will do, strings are easy to debug.\r
 \r
-        // For debugging\r
+        NetworkGame networkGame;\r
+\r
+        ILobby lobby;\r
+        IDeterministicGame deterministicGame;\r
 \r
-        List<Keys> lastPressedKeys;\r
-        bool lastButtonPressed;\r
-        Object activePlayer;\r
-        bool paused;\r
-        long lastAutoPause;\r
 \r
         // Constructor\r
 \r
@@ -44,13 +37,10 @@ namespace CS_3505_Project_06
 \r
             // Make the game object.  The game is currently called 'testHarness'.\r
 \r
+            lobby = new lobbyGUI();\r
             deterministicGame = new TestHarness();\r
-            \r
-            // Debugging setup\r
-\r
-            lastPressedKeys = new List<Keys>();\r
-            activePlayer = playerIdentifiers[0];\r
-            paused = false;\r
+            networkGame = new NetworkGame(lobby, deterministicGame);\r
+            Components.Add(new GamerServicesComponent(this));\r
         }\r
 \r
         /// <summary>\r
@@ -63,13 +53,8 @@ namespace CS_3505_Project_06
         {\r
             // Set a fixed time span of 1/60th of a second.\r
 \r
-            targetTimeSpan = new TimeSpan(166666); // In 100 nanosecond units = 16 666 600 nanoseconds\r
             IsFixedTimeStep = true;\r
-            TargetElapsedTime = targetTimeSpan;\r
-\r
-            // Reset the game - indicate that player #1 (player 0) owns this instance of the game.\r
-\r
-            deterministicGame.ResetGame(playerIdentifiers, playerIdentifiers[0]);\r
+            TargetElapsedTime = networkGame.TargetTimeSpan;\r
 \r
             // For debugging - reset the mouse position to the center of the window.\r
 \r
@@ -90,10 +75,9 @@ namespace CS_3505_Project_06
 \r
             spriteBatch = new SpriteBatch(GraphicsDevice);\r
 \r
-            // Let the game load its content.\r
-\r
-            font = Content.Load<SpriteFont>("InstructionFont");\r
+            networkGame.font = Content.Load<SpriteFont>("InstructionFont");\r
 \r
+            lobby.LoadContent(Content, graphics);\r
             deterministicGame.LoadContent(Content);\r
         }\r
 \r
@@ -103,6 +87,7 @@ namespace CS_3505_Project_06
         /// </summary>\r
         protected override void UnloadContent()\r
         {\r
+            lobby.UnloadContent();\r
             deterministicGame.UnloadContent();\r
         }\r
 \r
@@ -113,89 +98,9 @@ namespace CS_3505_Project_06
         /// <param name="gameTime">Provides a snapshot of timing values.</param>\r
         protected override void Update(GameTime gameTime)\r
         {\r
-            // Get user's input state.\r
-\r
-            KeyboardState keyState = Keyboard.GetState();\r
-            MouseState mouseState = Mouse.GetState();\r
-\r
-            // Make a list of the keys pressed or released this frame.\r
-\r
-            List<Keys> pressedKeys = new List<Keys>();\r
-            List<Keys> releasedKeys = new List<Keys>();\r
-\r
-            Keys[] pressedKeysArray = keyState.GetPressedKeys();\r
-            foreach (Keys k in pressedKeysArray)\r
-                if (!lastPressedKeys.Contains(k))\r
-                    pressedKeys.Add(k);\r
-                else\r
-                    lastPressedKeys.Remove(k);\r
-\r
-            releasedKeys = lastPressedKeys;\r
-            lastPressedKeys = new List<Keys>(pressedKeysArray);\r
-\r
-            // Get mouse button state.\r
-\r
-            bool buttonPressed = mouseState.LeftButton == ButtonState.Pressed;\r
-\r
-            /***** Begining of game logic. *****/\r
-\r
-            // Debug - allow user to exit.\r
-\r
-            if (pressedKeys.Contains(Keys.Escape))\r
-                this.Exit();\r
-\r
-            // Debug - allow user on this machine to direct input to any player's state in the game.\r
-\r
-            if (pressedKeys.Contains(Keys.F1)) activePlayer = playerIdentifiers[0];\r
-            if (pressedKeys.Contains(Keys.F2)) activePlayer = playerIdentifiers[1];\r
-            if (pressedKeys.Contains(Keys.F3)) activePlayer = playerIdentifiers[2];\r
-            if (pressedKeys.Contains(Keys.F4)) activePlayer = playerIdentifiers[3];\r
-\r
-            // Debug - allow user on this machine to pause/resume game state advances.\r
-\r
-            if (pressedKeys.Contains(Keys.F12) ||\r
-                pressedKeys.Contains(Keys.P) && (keyState.IsKeyDown(Keys.LeftControl) || keyState.IsKeyDown(Keys.RightControl)))\r
-            {\r
-                paused = !paused;\r
-                return;  // Don't update on pause start or stop\r
-            }\r
-\r
-            // Debug - automatically pause every 1000 frames.\r
-\r
-            if (deterministicGame.CurrentFrameNumber % 1000 == 0 && deterministicGame.CurrentFrameNumber != lastAutoPause)\r
-            {\r
-                paused = true;\r
-                lastAutoPause = deterministicGame.CurrentFrameNumber;\r
-            }\r
-\r
-            // Game update\r
-\r
-            // Direct inputs to the game engine - only report changes.\r
-\r
-            foreach (Keys k in pressedKeys)\r
-                deterministicGame.ApplyKeyInput(activePlayer, k, true);\r
-\r
-            foreach (Keys k in releasedKeys)\r
-                deterministicGame.ApplyKeyInput(activePlayer, k, false);\r
-\r
-            deterministicGame.ApplyMouseLocationInput(activePlayer, mouseState.X, mouseState.Y);\r
-\r
-            if (lastButtonPressed != buttonPressed)\r
-                deterministicGame.ApplyMouseButtonInput(activePlayer, buttonPressed);\r
-\r
-            lastButtonPressed = buttonPressed;\r
-\r
-            if (!paused)\r
-            {\r
-                // Advance the game engine.\r
-\r
-                deterministicGame.Update(targetTimeSpan);\r
-            }\r
-\r
-            /***** End of game logic. *****/\r
+            networkGame.Update(gameTime);\r
 \r
             // Allow the superclass to do any needed updates (unknown purpose).\r
-\r
             base.Update(gameTime);\r
         }\r
 \r
@@ -209,18 +114,8 @@ namespace CS_3505_Project_06
 \r
             spriteBatch.Begin();\r
 \r
-            // Draw a few instructions.\r
-\r
-            if (paused && gameTime.TotalRealTime.Milliseconds < 500)\r
-                spriteBatch.DrawString(font, "-=> Paused <=-", new Vector2(10, 130), Color.White);\r
-\r
-            spriteBatch.DrawString(font, "Press [F1]...[F4] to simulate input for each player.  Click X's to end game or terminate player.", new Vector2(10, 540), Color.White);\r
-            spriteBatch.DrawString(font, "Press [ESC] to exit and [F12] to pause/unpause.  Game auto-pauses every 1000 frames.", new Vector2(10, 570), Color.White);\r
-\r
             // Let the game draw itself.\r
-\r
-            deterministicGame.Draw(spriteBatch);\r
-            \r
+            networkGame.Draw(gameTime, spriteBatch);\r
 \r
             spriteBatch.End();\r
 \r
This page took 0.026828 seconds and 4 git commands to generate.