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