\r
namespace CarFire\r
{\r
+ //code from Prof Jensen's TestHarness\r
+ // This class encapsulates inputs from the players.\r
+ public class NextInputs\r
+ {\r
+ public List<Keys>[] keysPressed;\r
+ public List<Keys>[] keysReleased;\r
+ public int[] mouseLocationX;\r
+ public int[] mouseLocationY;\r
+ public bool[] mouseLocationChanged;\r
+ public bool[] mousePressed;\r
+ public bool[] mousePressedChanged;\r
+\r
+ public NextInputs()\r
+ {\r
+ keysPressed = new List<Keys>[4];\r
+ keysReleased = new List<Keys>[4];\r
+ mouseLocationX = new int[4];\r
+ mouseLocationY = new int[4];\r
+ mouseLocationChanged = new bool[4];\r
+ mousePressed = new bool[4];\r
+ mousePressedChanged = new bool[4];\r
+ for (int i = 0; i < 4; i++)\r
+ keysPressed[i] = new List<Keys>();\r
+ for (int i = 0; i < 4; i++)\r
+ keysReleased[i] = new List<Keys>();\r
+ }\r
+ }\r
+\r
public class Game : IDeterministicGame\r
{\r
#region IDeterministicGame Members\r
+ List<IPlayer> mPlayers;\r
+ NextInputs inputs;\r
+ Object[] playerIdentifiers;\r
+ Display mDisplay;\r
+ Map mMap;\r
\r
+ public Game()\r
+ {\r
+ mDisplay = new Display();\r
+ mPlayers = new List<IPlayer>();\r
+ }\r
public void LoadContent(ContentManager contentManager)\r
{\r
+ //Texture2D everything = contentManager.Load<Texture2D>("default");\r
+ mDisplay.LoadContent(contentManager);\r
+ int currentCenterX = 5; //Creates a map like the one in Display\r
+ int currentCenterY = 5;\r
+ mMap = contentManager.Load<Map>("Maps/stable");\r
+ Map.DefaultTile = contentManager.Load<Texture2D>("default");\r
+ mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);\r
+\r
+ Human player = new Human(mMap, "");\r
+ player.LoadContent(contentManager);\r
+ mPlayers.Add(player);\r
+ mDisplay.AddCharacters(player);\r
}\r
\r
public void UnloadContent()\r
{\r
}\r
\r
+ private int idPlayer(Object playerIdentifier)\r
+ {\r
+ for (int i = 0; i < playerIdentifiers.Length; i++)\r
+ if (playerIdentifiers[i] == playerIdentifier)\r
+ return i;\r
+ throw new Exception("Illegal player identifier" + playerIdentifier);\r
+ }\r
+\r
public Vector2 PreferredScreenSize\r
{\r
get { return new Vector2(800, 600); }\r
\r
public void ResetGame(object[] playerIdentifiers, object thisPlayer)\r
{\r
+ foreach (IPlayer player in mPlayers)\r
+ {\r
+ player.Spawn(mMap.CenterCell);\r
+ }\r
}\r
\r
public long CurrentFrameNumber\r
\r
public void ApplyKeyInput(object playerIdentifier, Keys key, bool isKeyPressed)\r
{\r
+ //code from Prof Jensen's TestHarness\r
+ int player = idPlayer(playerIdentifier);\r
+\r
+ if (isKeyPressed && !inputs.keysPressed[player].Contains(key))\r
+ inputs.keysPressed[player].Add(key);\r
+\r
+ if (!isKeyPressed && !inputs.keysReleased[player].Contains(key))\r
+ inputs.keysReleased[player].Add(key);\r
}\r
\r
public void ApplyMouseLocationInput(object playerIdentifier, int x, int y)\r
\r
public bool IsGameOver(object playerIdentifier)\r
{\r
- return true;\r
+ return false;\r
}\r
\r
public bool IsTerminated(object playerIdentifier)\r
{\r
- return true;\r
+ return false;\r
}\r
\r
public long Update(TimeSpan timespan)\r
{\r
+ mDisplay.Update(timespan);\r
return CurrentFrameNumber;\r
}\r
\r
public long Draw(SpriteBatch spriteBatch)\r
{\r
+ mDisplay.Draw(spriteBatch);\r
return CurrentFrameNumber;\r
}\r
\r