2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Content;
7 using Microsoft.Xna.Framework.Graphics;
8 using Microsoft.Xna.Framework.Input;
12 //code from Prof Jensen's TestHarness
13 // This class encapsulates inputs from the players.
14 public class NextInputs
16 public List<Keys>[] keysPressed;
17 public List<Keys>[] keysReleased;
18 public int[] mouseLocationX;
19 public int[] mouseLocationY;
20 public bool[] mouseLocationChanged;
21 public bool[] mousePressed;
22 public bool[] mousePressedChanged;
26 keysPressed = new List<Keys>[4];
27 keysReleased = new List<Keys>[4];
28 mouseLocationX = new int[4];
29 mouseLocationY = new int[4];
30 mouseLocationChanged = new bool[4];
31 mousePressed = new bool[4];
32 mousePressedChanged = new bool[4];
33 for (int i = 0; i < 4; i++)
34 keysPressed[i] = new List<Keys>();
35 for (int i = 0; i < 4; i++)
36 keysReleased[i] = new List<Keys>();
40 public class Game : IDeterministicGame
42 #region IDeterministicGame Members
43 List<IPlayer> mPlayers;
45 Object[] playerIdentifiers;
51 mDisplay = new Display();
52 mPlayers = new List<IPlayer>();
54 public void LoadContent(ContentManager contentManager)
56 //Texture2D everything = contentManager.Load<Texture2D>("default");
57 mDisplay.LoadContent(contentManager);
58 int currentCenterX = 5; //Creates a map like the one in Display
59 int currentCenterY = 5;
60 mMap = contentManager.Load<Map>("Maps/stable");
61 Map.DefaultTile = contentManager.Load<Texture2D>("default");
62 mMap.CenterCell = new Vector2(currentCenterX, currentCenterY);
64 Human player = new Human(mMap, "");
65 player.LoadContent(contentManager);
67 mDisplay.AddCharacters(player);
70 public void UnloadContent()
74 private int idPlayer(Object playerIdentifier)
76 for (int i = 0; i < playerIdentifiers.Length; i++)
77 if (playerIdentifiers[i] == playerIdentifier)
79 throw new Exception("Illegal player identifier" + playerIdentifier);
82 public Vector2 PreferredScreenSize
84 get { return new Vector2(800, 600); }
87 public int MinimumSupportedPlayers
92 public int MaximumSupportedPlayers
97 public void ResetGame(object[] playerIdentifiers, object thisPlayer)
99 foreach (IPlayer player in mPlayers)
101 player.Spawn(mMap.CenterCell);
105 public long CurrentFrameNumber
110 public long CurrentChecksum
115 public void ApplyKeyInput(object playerIdentifier, Keys key, bool isKeyPressed)
117 //code from Prof Jensen's TestHarness
118 int player = idPlayer(playerIdentifier);
120 if (isKeyPressed && !inputs.keysPressed[player].Contains(key))
121 inputs.keysPressed[player].Add(key);
123 if (!isKeyPressed && !inputs.keysReleased[player].Contains(key))
124 inputs.keysReleased[player].Add(key);
127 public void ApplyMouseLocationInput(object playerIdentifier, int x, int y)
131 public void ApplyMouseButtonInput(object playerIdentifier, bool isButtonPressed)
135 public bool IsGameOver(object playerIdentifier)
140 public bool IsTerminated(object playerIdentifier)
145 public long Update(TimeSpan timespan)
147 mDisplay.Update(timespan);
148 return CurrentFrameNumber;
151 public long Draw(SpriteBatch spriteBatch)
153 mDisplay.Draw(spriteBatch);
154 return CurrentFrameNumber;