From: brady Date: Sat, 20 Mar 2010 07:03:39 +0000 (+0000) Subject: Added to functionality of gui. Also added 2 methods I needed in NetworkGame, comments... X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=fda045bce6b1a1ad4dc9b7ccbb33fc1c536a5957;p=chaz%2Fcarfire Added to functionality of gui. Also added 2 methods I needed in NetworkGame, comments were added to explain git-svn-id: https://bd85.net/svn/cs3505_group@15 92bb83a3-7c8f-8a45-bc97-515c4e399668 --- 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 2d8fb75..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 @@ -40,6 +40,7 @@ namespace CS_3505_Project_06 lobby = new lobbyGUI(); deterministicGame = new TestHarness(); networkGame = new NetworkGame(lobby, deterministicGame); + Components.Add(new GamerServicesComponent(this)); } /// 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 index b902822..0fe4ad1 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/LobbyGUI.cs @@ -2,10 +2,13 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using Microsoft.Xna.Framework.Content; -using Microsoft.Xna.Framework.Input; -using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Net; +using System.Diagnostics; +using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Graphics; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Input; +using Microsoft.Xna.Framework.Content; namespace CS_3505_Project_06 { @@ -51,6 +54,9 @@ namespace CS_3505_Project_06 KeyboardState previousKeyboardState; KeyboardState currentKeyboardState; + GamerCollection players; + + private enum lobbyState { Welcome, @@ -63,7 +69,7 @@ namespace CS_3505_Project_06 public lobbyGUI() { - currentState = lobbyState.Welcome; + currentState = lobbyState.Welcome; } public void LoadContent(ContentManager contentManager, GraphicsDeviceManager graphics) @@ -116,8 +122,10 @@ namespace CS_3505_Project_06 public long Update(GameTime gameTime, NetworkGame networkGame) { + UpdateSpotLight(gameTime); currentKeyboardState = Keyboard.GetState(); + //check inputs switch (currentState) { @@ -142,9 +150,14 @@ namespace CS_3505_Project_06 { currentState = lobbyState.Welcome; ready = false; + networkGame.LeaveSession(); } - if (currentKeyboardState.IsKeyDown(Keys.R) && previousKeyboardState.IsKeyUp(Keys.R)) - ready = true; + if (currentKeyboardState.IsKeyDown(Keys.Y) && previousKeyboardState.IsKeyUp(Keys.Y)) + { + currentState = lobbyState.Connected; + networkGame.CreateSession(4); + players = networkGame.LocalGamers; + } break; case lobbyState.FindGame: if (currentKeyboardState.IsKeyDown(Keys.X) && previousKeyboardState.IsKeyUp(Keys.X)) @@ -175,6 +188,7 @@ namespace CS_3505_Project_06 spriteBatch.Draw(background, backgroundPos, null, Color.White, 0, zero, scale, SpriteEffects.None, 0); spriteBatch.Draw(cs, csPos, null, Color.White, 0, zero, 0.5f, SpriteEffects.None, 0); spriteBatch.Draw(spotLight, spotLightPos, null, Color.White, 0, spotLightCenter, 1f, SpriteEffects.None, 0); + switch (currentState) { case lobbyState.Welcome: @@ -191,6 +205,9 @@ namespace CS_3505_Project_06 case lobbyState.CreateGame: DrawPlayerList(spriteBatch); + spriteBatch.DrawString(menuFont, "You are now the Host!", new Vector2(MaxX / 2, MaxY / 3), Color.White, 0f, zero, .7f, SpriteEffects.None, 0.5f); + spriteBatch.DrawString(menuFont, "press: Y to continue", new Vector2(MaxX /2, (MaxY / 3) + menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f); + spriteBatch.DrawString(menuFont, "X to return to main menu", new Vector2(MaxX /2 + 40, (MaxY / 3) + 2 * menuFont.LineSpacing), Color.White, 0f, zero, .6f, SpriteEffects.None, 0.5f); break; case lobbyState.FindGame: @@ -226,12 +243,22 @@ namespace CS_3505_Project_06 private void DrawPlayerList(SpriteBatch spriteBatch) { + //reference point Vector2 topOfList = new Vector2(MaxX / 8, MaxY / 4); + + //command info spriteBatch.DrawString(menuFont, "Current Players", new Vector2(topOfList.X + 15, topOfList.Y - 25), Color.White); + spriteBatch.DrawString(menuFont, "Command Options: to mark your self as ready", new Vector2(20, 20), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "type players # to toggle chat", new Vector2(175, 40), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "return to main menu", new Vector2(175, 60), Color.Gray, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "R", new Vector2(145, 20), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "#", new Vector2(145, 40), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f); + spriteBatch.DrawString(menuFont, "X", new Vector2(145, 60), Color.DarkGreen, 0f, zero, .6f, SpriteEffects.None, 1f); + - //top player spriteBatch.Draw(menuItem, topOfList, null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 10), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); + + //player 1 spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 45), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if(!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 35), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -247,7 +274,6 @@ namespace CS_3505_Project_06 //player 2 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 65), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 75), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 110), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if (!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 100), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -263,7 +289,6 @@ namespace CS_3505_Project_06 //player 3 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 130), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 140), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 175), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if (!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 165), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -279,7 +304,6 @@ namespace CS_3505_Project_06 //player 4 spriteBatch.Draw(menuItem, new Vector2(topOfList.X, topOfList.Y + 195), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); - spriteBatch.DrawString(menuFont, "****Player 1****", new Vector2(topOfList.X + 10, topOfList.Y + 205), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); spriteBatch.DrawString(menuFont, "Ready", new Vector2(topOfList.X + 5, topOfList.Y + 240), Color.DarkGray, 0f, zero, .6f, SpriteEffects.None, 1f); if (!ready) spriteBatch.Draw(emptySelectBox, new Vector2(topOfList.X - 32, topOfList.Y + 230), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); @@ -292,6 +316,17 @@ namespace CS_3505_Project_06 else spriteBatch.Draw(checkedBox, new Vector2(topOfList.X + 218, topOfList.Y + 225), null, Color.White, 0, zero, scale, SpriteEffects.None, 1f); + + //draw player names + if (players != null) + { + for (int g = 0; g < players.Count; g++) + { + spriteBatch.DrawString(menuFont, players[g].Gamertag, new Vector2(topOfList.X + 10, topOfList.Y + 10 + 65*g), Color.White, 0f, zero, .75f, SpriteEffects.None, 1f); + } + } + + //top player } } } 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 index abe36ba..c8cc60c 100644 --- a/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs +++ b/Project06/CS 3505 Project 06/CS 3505 Project 06/NetworkGame.cs @@ -59,7 +59,7 @@ namespace CS_3505_Project_06 } - LocalNetworkGamer LocalGamer + public LocalNetworkGamer LocalGamer { get { @@ -67,8 +67,18 @@ namespace CS_3505_Project_06 } } + // I added this as I needed a way to display all gamers not just the first gamer + // -Brady + public GamerCollection LocalGamers + { + get + { + return mNetworkSession.LocalGamers; + } + } + - NetworkSession CreateSession() + public NetworkSession CreateSession() { return CreateSession(mGame.MaximumSupportedPlayers); } @@ -84,6 +94,12 @@ namespace CS_3505_Project_06 return mNetworkSession; } + // added so I can test if sessionExists and thus be able to call things on NetworkGame safely + // -Brady + public bool sessionExists() + { + return mNetworkSession == null; + } public AvailableNetworkSessionCollection FindSessions() {