]> Dogcows Code - chaz/carfire/commitdiff
initial network code with partial lobby integration
authorCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Sat, 20 Mar 2010 04:45:48 +0000 (04:45 +0000)
committerCharles <Charles@92bb83a3-7c8f-8a45-bc97-515c4e399668>
Sat, 20 Mar 2010 04:45:48 +0000 (04:45 +0000)
git-svn-id: https://bd85.net/svn/cs3505_group@13 92bb83a3-7c8f-8a45-bc97-515c4e399668

15 files changed:
Project06/CS 3505 Project 06/CS 3505 Project 06/CS 3505 Project 06.csproj
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/Content.contentproj
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/background.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/checkedBox.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/cs.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/deselectBox.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/emptySelectBox.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuFont.spritefont [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuItem.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/selectGameScreen.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Content/spotlight.png [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/Game06.cs
Project06/CS 3505 Project 06/CS 3505 Project 06/ILobby.cs [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs [new file with mode: 0644]
Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs [new file with mode: 0644]

index 41013cd13f7fa27e34c0adcc73fef55e807aa503..d0949deea0c859af0c4d2e28539eecdeddbdd4f1 100644 (file)
@@ -86,6 +86,9 @@
   <ItemGroup>\r
     <Compile Include="CS 3505\IDeterministicGame.cs" />\r
     <Compile Include="CS 3505\TestHarness.cs" />\r
+    <Compile Include="ILobby.cs" />\r
+    <Compile Include="LobbyGUI.cs" />\r
+    <Compile Include="NetworkGame.cs" />\r
     <Compile Include="Properties\AssemblyInfo.cs" />\r
     <Compile Include="Program.cs" />\r
     <Compile Include="Game06.cs" />\r
index 04a7389da49af26e7fc504431c3bd57ea0676344..e766d8f684a637dbdf3f7752edd2401caa7082e3 100644 (file)
       <Processor>FontDescriptionProcessor</Processor>\r
     </Compile>\r
   </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="background.png">\r
+      <Name>background</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="checkedBox.png">\r
+      <Name>checkedBox</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="cs.png">\r
+      <Name>cs</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="deselectBox.png">\r
+      <Name>deselectBox</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="emptySelectBox.png">\r
+      <Name>emptySelectBox</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="menuItem.png">\r
+      <Name>menuItem</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="selectGameScreen.png">\r
+      <Name>selectGameScreen</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+    <Compile Include="spotlight.png">\r
+      <Name>spotlight</Name>\r
+      <Importer>TextureImporter</Importer>\r
+      <Processor>TextureProcessor</Processor>\r
+    </Compile>\r
+  </ItemGroup>\r
+  <ItemGroup>\r
+    <Compile Include="menuFont.spritefont">\r
+      <Name>menuFont</Name>\r
+      <Importer>FontDescriptionImporter</Importer>\r
+      <Processor>FontDescriptionProcessor</Processor>\r
+    </Compile>\r
+  </ItemGroup>\r
   <Import Project="$(MSBuildExtensionsPath)\Microsoft\XNA Game Studio\v3.0\Microsoft.Xna.GameStudio.ContentPipeline.targets" />\r
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. \r
        Other similar extension points exist, see Microsoft.Common.targets.\r
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/background.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/background.png
new file mode 100644 (file)
index 0000000..b90a658
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/background.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/checkedBox.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/checkedBox.png
new file mode 100644 (file)
index 0000000..3462dc3
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/checkedBox.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/cs.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/cs.png
new file mode 100644 (file)
index 0000000..f7d6ebd
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/cs.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/deselectBox.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/deselectBox.png
new file mode 100644 (file)
index 0000000..cb4d2d0
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/deselectBox.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/emptySelectBox.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/emptySelectBox.png
new file mode 100644 (file)
index 0000000..5373a1b
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/emptySelectBox.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuFont.spritefont b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuFont.spritefont
new file mode 100644 (file)
index 0000000..72495a3
--- /dev/null
@@ -0,0 +1,60 @@
+<?xml version="1.0" encoding="utf-8"?>\r
+<!--\r
+This file contains an xml description of a font, and will be read by the XNA\r
+Framework Content Pipeline. Follow the comments to customize the appearance\r
+of the font in your game, and to change the characters which are available to draw\r
+with.\r
+-->\r
+<XnaContent xmlns:Graphics="Microsoft.Xna.Framework.Content.Pipeline.Graphics">\r
+  <Asset Type="Graphics:FontDescription">\r
+\r
+    <!--\r
+    Modify this string to change the font that will be imported.\r
+    -->\r
+    <FontName>Times New Roman</FontName>\r
+\r
+    <!--\r
+    Size is a float value, measured in points. Modify this value to change\r
+    the size of the font.\r
+    -->\r
+    <Size>18</Size>\r
+\r
+    <!--\r
+    Spacing is a float value, measured in pixels. Modify this value to change\r
+    the amount of spacing in between characters.\r
+    -->\r
+    <Spacing>0</Spacing>\r
+\r
+    <!--\r
+    UseKerning controls the layout of the font. If this value is true, kerning information\r
+    will be used when placing characters.\r
+    -->\r
+    <UseKerning>true</UseKerning>\r
+\r
+    <!--\r
+    Style controls the style of the font. Valid entries are "Regular", "Bold", "Italic",\r
+    and "Bold, Italic", and are case sensitive.\r
+    -->\r
+    <Style>Bold</Style>\r
+\r
+    <!--\r
+    If you uncomment this line, the default character will be substituted if you draw\r
+    or measure text that contains characters which were not included in the font.\r
+    -->\r
+    <!-- <DefaultCharacter>*</DefaultCharacter> -->\r
+\r
+    <!--\r
+    CharacterRegions control what letters are available in the font. Every\r
+    character from Start to End will be built and made available for drawing. The\r
+    default range is from 32, (ASCII space), to 126, ('~'), covering the basic Latin\r
+    character set. The characters are ordered according to the Unicode standard.\r
+    See the documentation for more information.\r
+    -->\r
+    <CharacterRegions>\r
+      <CharacterRegion>\r
+        <Start>&#32;</Start>\r
+        <End>&#126;</End>\r
+      </CharacterRegion>\r
+    </CharacterRegions>\r
+  </Asset>\r
+</XnaContent>\r
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuItem.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuItem.png
new file mode 100644 (file)
index 0000000..cf45ebd
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/menuItem.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/selectGameScreen.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/selectGameScreen.png
new file mode 100644 (file)
index 0000000..af04c0c
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/selectGameScreen.png differ
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/spotlight.png b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/spotlight.png
new file mode 100644 (file)
index 0000000..d8c3381
Binary files /dev/null and b/Project06/CS 3505 Project 06/CS 3505 Project 06/Content/spotlight.png differ
index 0a4a228aa3ce6e063e55e014343403e5c02520f1..2d8fb75b25043d3592a3a3b25ecaa7ab81e423e9 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,9 @@ 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
         }\r
 \r
         /// <summary>\r
@@ -63,13 +52,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 +74,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 +86,7 @@ namespace CS_3505_Project_06
         /// </summary>\r
         protected override void UnloadContent()\r
         {\r
+            lobby.UnloadContent();\r
             deterministicGame.UnloadContent();\r
         }\r
 \r
@@ -113,89 +97,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 +113,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
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/ILobby.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/ILobby.cs
new file mode 100644 (file)
index 0000000..3b0f6c6
--- /dev/null
@@ -0,0 +1,19 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework.Input;\r
+using Microsoft.Xna.Framework.Content;\r
+\r
+namespace CS_3505_Project_06\r
+{\r
+    public interface ILobby\r
+    {\r
+        void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics);\r
+        void UnloadContent();\r
+        long Update(GameTime gameTime, NetworkGame networkGame);\r
+        long Draw(SpriteBatch spriteBatch);\r
+    }\r
+}\r
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs
new file mode 100644 (file)
index 0000000..b902822
--- /dev/null
@@ -0,0 +1,297 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework.Content;\r
+using Microsoft.Xna.Framework.Input;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Graphics;\r
+\r
+namespace CS_3505_Project_06\r
+{\r
+    public class lobbyGUI : ILobby\r
+    {\r
+        float scale;\r
+\r
+        Texture2D background;\r
+        Texture2D spotLight;\r
+        Texture2D cs;\r
+        Texture2D selectGameScreen;\r
+\r
+        Vector2 backgroundPos;\r
+        Vector2 spotLightPos;\r
+        Vector2 spotLightCenter;\r
+        Vector2 csPos;\r
+\r
+        Vector2 zero;\r
+        Vector2 spotLightVelocity;\r
+\r
+        int MaxX;\r
+        int MinX;\r
+        int MaxY;\r
+        int MinY;\r
+\r
+        Texture2D checkedBox;\r
+        Texture2D deselectBox;\r
+        Texture2D emptySelectBox;\r
+        Texture2D menuItem;\r
+\r
+        Boolean ready;\r
+\r
+        SpriteFont menuFont;\r
+        string selected;\r
+        Vector2 createGamePos;\r
+        string createGameText;\r
+        Vector2 findGamePos;\r
+        string findGameText;\r
+\r
+        Vector2 returnToMainPos;\r
+        string returnToMainText;\r
+\r
+        KeyboardState previousKeyboardState;\r
+        KeyboardState currentKeyboardState;\r
+\r
+        private enum lobbyState\r
+        {\r
+            Welcome,\r
+            CreateGame,\r
+            FindGame,\r
+            Connected\r
+        }\r
+\r
+        lobbyState currentState;\r
+\r
+        public lobbyGUI()\r
+        {\r
+            currentState = lobbyState.Welcome;\r
+        }\r
+\r
+        public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics)\r
+        {\r
+            background = contentManager.Load<Texture2D>("background");\r
+            spotLight = contentManager.Load<Texture2D>("spotlight");\r
+            cs = contentManager.Load<Texture2D>("cs");\r
+            selectGameScreen = contentManager.Load<Texture2D>("selectGameScreen");\r
+            backgroundPos = new Vector2(0f, 0f);\r
+            spotLightPos = new Vector2(100f, graphics.GraphicsDevice.Viewport.Height - 98);\r
+            spotLightCenter = new Vector2(800f, 800f);\r
+            spotLightVelocity = new Vector2(-100, 33);\r
+            csPos = new Vector2(10f, graphics.GraphicsDevice.Viewport.Height - 98);\r
+\r
+            zero = new Vector2(0, 0);\r
+\r
+            MaxX = graphics.GraphicsDevice.Viewport.Width;\r
+            MinX = 0;\r
+            MaxY = graphics.GraphicsDevice.Viewport.Height;\r
+            MinY = 100;\r
+\r
+            scale = MaxX / 1600f;\r
+            //playerlist stuff\r
+            checkedBox = contentManager.Load<Texture2D>("checkedBox");\r
+            deselectBox = contentManager.Load<Texture2D>("deselectBox");\r
+            emptySelectBox = contentManager.Load<Texture2D>("emptySelectBox");\r
+            menuItem = contentManager.Load<Texture2D>("menuItem");\r
+\r
+            ready = false;\r
+\r
+            //menu fonts\r
+            menuFont = contentManager.Load<SpriteFont>("menuFont");\r
+            createGamePos = new Vector2(100f, MaxY / 3);\r
+            createGameText = "Create Game";\r
+            selected = createGameText;\r
+\r
+            findGamePos = new Vector2(100f, (MaxY / 3) + 60);\r
+            findGameText = "Find Game";\r
+\r
+            returnToMainPos = new Vector2(MaxX / 2, MaxY - 120);\r
+            returnToMainText = "press [ X ] to return to main menu";\r
+\r
+\r
+        }\r
+\r
+        public void UnloadContent()\r
+        {\r
+            \r
+        }\r
+\r
+        public long Update(GameTime gameTime, NetworkGame networkGame)\r
+        {\r
+            UpdateSpotLight(gameTime);\r
+            currentKeyboardState = Keyboard.GetState();\r
+            //check inputs\r
+            switch (currentState)\r
+            {\r
+                case lobbyState.Welcome:\r
+                    if (selected == createGameText)\r
+                    {\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))\r
+                            currentState = lobbyState.CreateGame;\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Down))\r
+                            selected = findGameText;\r
+                    }\r
+                    else\r
+                    {\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Enter) && previousKeyboardState.IsKeyUp(Keys.Enter))\r
+                            currentState = lobbyState.FindGame;\r
+                        if (currentKeyboardState.IsKeyDown(Keys.Up))\r
+                            selected = createGameText;\r
+                    }\r
+                    break;\r
+                case lobbyState.CreateGame:\r
+                    if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
+                    {\r
+                        currentState = lobbyState.Welcome;\r
+                        ready = false;\r
+                    }\r
+                    if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))\r
+                        ready = true;\r
+                    break;\r
+                case lobbyState.FindGame:\r
+                    if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
+                    {\r
+                        currentState = lobbyState.Welcome;\r
+                        ready = false;\r
+                    }\r
+\r
+                    break;\r
+                case lobbyState.Connected:\r
+                    if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X))\r
+                        currentState = lobbyState.Welcome;\r
+                    if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R))\r
+                        ready = true;\r
+                    break;\r
+\r
+            }\r
+            previousKeyboardState = Keyboard.GetState();\r
+\r
+            return 1;\r
+        }\r
+\r
+        /// <summary>\r
+        /// Draws the lobby GUI. Has different states for difference menu configurations\r
+        /// </summary>\r
+        public long Draw(SpriteBatch spriteBatch)\r
+        {\r
+            spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);\r
+            spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0);\r
+            spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0);\r
+            switch (currentState)\r
+            {\r
+                case lobbyState.Welcome:\r
+                    spriteBatch.DrawString(menuFont, "press [ Home ] to login", new Vector2(350, 20), Color.LightGray, 0f, zero, .6f, SpriteEffects.None, 0.5f);\r
+                    if (selected == createGameText)\r
+                        spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+                    else\r
+                        spriteBatch.DrawString(menuFont, createGameText, createGamePos, Color.Gray, 0, zero, 1f,SpriteEffects.None, 0.5f);\r
+                    if (selected == findGameText)\r
+                        spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Red, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+                    else\r
+                        spriteBatch.DrawString(menuFont, findGameText, findGamePos, Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+                    break;\r
+                \r
+                case lobbyState.CreateGame:\r
+                    DrawPlayerList(spriteBatch);\r
+\r
+                    break;\r
+                case lobbyState.FindGame:\r
+                    spriteBatch.Draw(selectGameScreen, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0);\r
+                    //spriteBatch.DrawString(menuFont, "Select Game", new Vector2(100, 100), Color.Gray, 0, zero, 1f, SpriteEffects.None, 0.5f);\r
+\r
+                    //spriteBatch.DrawString(menuFont, returnToMainText, returnToMainPos, Color.Gray, 0, new Vector2(180 , 0), .6f, SpriteEffects.None, 0.5f);\r
+                    break;\r
+                case lobbyState.Connected:\r
+                    DrawPlayerList(spriteBatch);\r
+                    break;\r
+            }\r
+\r
+            return 1;\r
+        }\r
+\r
+        private void UpdateSpotLight(GameTime gameTime)\r
+        {\r
+            spotLightPos = new Vector2(spotLightPos.X + spotLightVelocity.X * (float)gameTime.ElapsedGameTime.TotalSeconds,\r
+                                        spotLightPos.Y + spotLightVelocity.Y * (float)gameTime.ElapsedGameTime.TotalSeconds);\r
+\r
+            if (spotLightPos.X > MaxX || spotLightPos.X < MinX) //right or left wall\r
+            {\r
+                spotLightVelocity = new Vector2(spotLightVelocity.X * -1, spotLightVelocity.Y);\r
+            }\r
+            else if (spotLightPos.Y > MaxY || spotLightPos.Y < MinY) //top or bottom wall\r
+            {\r
+                spotLightVelocity = new Vector2(spotLightVelocity.X, spotLightVelocity.Y * -1);\r
+            }\r
+        }\r
+\r
+\r
+        private void DrawPlayerList(SpriteBatch spriteBatch)\r
+        {\r
+            \r
+            Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4);\r
+            spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White);\r
+            \r
+            //top player\r
+            spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 10), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            if(!ready)\r
+                spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            \r
+            spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            Boolean chatwith = false;  // change to reflect info from network, move to update and create one for each player\r
+            if (!chatwith)\r
+                spriteBatch.Draw(deselectBox, new Vector2(topOfList.X +218, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 30), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+\r
+            //player 2\r
+            spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 75), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            if (!ready)\r
+                spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+\r
+            spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            // change to reflect info from network\r
+            if (!chatwith)\r
+                spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 95), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            \r
+            //player 3\r
+            spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 140), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            if (!ready)\r
+                spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+\r
+            spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            \r
+            if (!chatwith)\r
+                spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 160), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            \r
+            //player 4\r
+            spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 205), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f);\r
+            spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            if (!ready)\r
+                spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X - 32, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+\r
+            spriteBatch.DrawString(menuFont, "Chat with", new Vector2(topOfList.X + 152, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f);\r
+            if (!chatwith)\r
+                spriteBatch.Draw(deselectBox, new Vector2(topOfList.X + 218, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            else\r
+                spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f);\r
+            \r
+        }\r
+    }\r
+}\r
diff --git a/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs b/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs
new file mode 100644 (file)
index 0000000..abe36ba
--- /dev/null
@@ -0,0 +1,258 @@
+using System;\r
+using System.Collections.Generic;\r
+using System.Linq;\r
+using System.Text;\r
+using Microsoft.Xna.Framework.Net;\r
+using System.Diagnostics;\r
+using Microsoft.Xna.Framework.GamerServices;\r
+using Microsoft.Xna.Framework.Graphics;\r
+using Microsoft.Xna.Framework;\r
+using Microsoft.Xna.Framework.Input;\r
+\r
+namespace CS_3505_Project_06\r
+{\r
+    public class NetworkGame\r
+    {\r
+        NetworkSession mNetworkSession;\r
+\r
+        ILobby mLobby;\r
+        IDeterministicGame mGame;\r
+\r
+        TimeSpan mTargetTimeSpan = new TimeSpan(166666);\r
+        public TimeSpan TargetTimeSpan\r
+        {\r
+            get\r
+            {\r
+                return mTargetTimeSpan;\r
+            }\r
+        }\r
+\r
+        List<Keys> lastPressedKeys;\r
+        bool lastButtonPressed;\r
+\r
+        Object[] playerIdentifiers = { "One", "Two", "Three", "Four" };  // Any objects will do, strings are easy to debug.\r
+\r
+        // For debugging\r
+\r
+        Object activePlayer;\r
+        bool paused;\r
+        long lastAutoPause;\r
+\r
+        public SpriteFont font;\r
+\r
+\r
+        public NetworkGame(ILobby lobby, IDeterministicGame game)\r
+        {\r
+            Debug.Assert(lobby != null && game != null);\r
+\r
+            mLobby = lobby;\r
+            mGame = game;\r
+\r
+            // Begin: Test harness stuff\r
+            lastPressedKeys = new List<Keys>();\r
+            activePlayer = playerIdentifiers[0];\r
+            paused = false;\r
+\r
+            // Reset the game - indicate that player #1 (player 0) owns this instance of the game.\r
+\r
+            mGame.ResetGame(playerIdentifiers, playerIdentifiers[0]);\r
+        }\r
+\r
+\r
+        LocalNetworkGamer LocalGamer\r
+        {\r
+            get\r
+            {\r
+                return mNetworkSession.LocalGamers[0];\r
+            }\r
+        }\r
+\r
+\r
+        NetworkSession CreateSession()\r
+        {\r
+            return CreateSession(mGame.MaximumSupportedPlayers);\r
+        }\r
+\r
+        public NetworkSession CreateSession(int maxGamers)\r
+        {\r
+            Debug.Assert(mNetworkSession == null); \r
+\r
+            mNetworkSession = NetworkSession.Create(NetworkSessionType.SystemLink, 1, maxGamers);\r
+            mNetworkSession.AllowHostMigration = true;\r
+            mNetworkSession.AllowJoinInProgress = false;\r
+\r
+            return mNetworkSession;\r
+        }\r
+\r
+\r
+        public AvailableNetworkSessionCollection FindSessions()\r
+        {\r
+            return NetworkSession.Find(NetworkSessionType.SystemLink, 1, new NetworkSessionProperties());\r
+        }\r
+\r
+        public NetworkSession JoinSession(AvailableNetworkSession availableSession)\r
+        {\r
+            Debug.Assert(mNetworkSession == null);\r
+\r
+            mNetworkSession = NetworkSession.Join(availableSession);\r
+\r
+            return mNetworkSession;\r
+        }\r
+\r
+\r
+        public void LeaveSession()\r
+        {\r
+            Debug.Assert(mNetworkSession != null);\r
+\r
+            mNetworkSession.Dispose();\r
+            mNetworkSession = null;\r
+        }\r
+\r
+\r
+        public void SimulateBadNetwork()\r
+        {\r
+            Debug.Assert(mNetworkSession != null);\r
+\r
+            mNetworkSession.SimulatedLatency = new TimeSpan(0, 0, 0, 0, 200);\r
+            mNetworkSession.SimulatedPacketLoss = 0.1f;\r
+        }\r
+\r
+\r
+        public void Update(GameTime gameTime)\r
+        {\r
+            if (mNetworkSession == null)\r
+            {\r
+                mLobby.Update(gameTime, this);\r
+            }\r
+            else\r
+            {\r
+                mNetworkSession.Update();\r
+\r
+                if (mNetworkSession.SessionState == NetworkSessionState.Lobby)\r
+                {\r
+                    if (mNetworkSession.IsHost &&\r
+                        mNetworkSession.AllGamers.Count >= mGame.MinimumSupportedPlayers &&\r
+                        mNetworkSession.IsEveryoneReady)\r
+                    {\r
+                        mNetworkSession.StartGame();\r
+                        mNetworkSession.ResetReady();\r
+                    }\r
+                    else\r
+                    {\r
+                        mLobby.Update(gameTime, this);\r
+                    }\r
+                }\r
+                else if (mNetworkSession.SessionState == NetworkSessionState.Playing)\r
+                {\r
+                    // TODO: in-game update stuff\r
+                    UpdateTestHarness(gameTime);\r
+\r
+                    mGame.Update(mTargetTimeSpan);\r
+                }\r
+            }\r
+        }\r
+\r
+        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)\r
+        {\r
+            mLobby.Draw(spriteBatch);\r
+            DrawTestHarness(gameTime, spriteBatch);\r
+        }\r
+\r
+\r
+\r
+\r
+        void UpdateTestHarness(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 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 (mGame.CurrentFrameNumber % 1000 == 0 && mGame.CurrentFrameNumber != lastAutoPause)\r
+            {\r
+                paused = true;\r
+                lastAutoPause = mGame.CurrentFrameNumber;\r
+            }\r
+\r
+\r
+            //if (pressedKeys.Contains(Keys.Escape))\r
+              //  this.Exit();\r
+\r
+            // Game update\r
+\r
+            // Direct inputs to the game engine - only report changes.\r
+\r
+            foreach (Keys k in pressedKeys)\r
+                mGame.ApplyKeyInput(activePlayer, k, true);\r
+\r
+            foreach (Keys k in releasedKeys)\r
+                mGame.ApplyKeyInput(activePlayer, k, false);\r
+\r
+            mGame.ApplyMouseLocationInput(activePlayer, mouseState.X, mouseState.Y);\r
+\r
+            if (lastButtonPressed != buttonPressed)\r
+                mGame.ApplyMouseButtonInput(activePlayer, buttonPressed);\r
+\r
+            lastButtonPressed = buttonPressed;\r
+\r
+            if (!paused)\r
+            {\r
+                // Advance the game engine.\r
+\r
+                mGame.Update(mTargetTimeSpan);\r
+            }\r
+        }\r
+\r
+        void DrawTestHarness(GameTime gameTime, SpriteBatch spriteBatch)\r
+        {\r
+\r
+            // BEGIN: Test harness stuff.\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
+            //END: Test harness stuff.\r
+\r
+        }\r
+    }\r
+}\r
This page took 0.05796 seconds and 4 git commands to generate.