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