2 using System.Collections.Generic;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Input;
8 using Microsoft.Xna.Framework.Content;
13 /// A DeterministicGame object is a full XNA game, except that it does not
14 /// extend the Microsoft.Xna.Framework.Game class. It supports content loading
15 /// and unloading, as well as modified Update and Draw functionality.
17 /// DeterministicGame objects are intented to be incorporated inside of an
18 /// existing game. By simply calling update and draw at the appropriate times,
19 /// and by supplying user inputs, the game will play just like any other game.
21 /// It is intended that a DeterministicGame be a multiplayer game, and support for
22 /// this is listed in the interface below. Each player is identified by a unique object
23 /// reference (of the caller's choice, not a struct). The game supports the notion of a
24 /// current 'frame', or state. The enclosing code supplies the user inputs for the
25 /// next frame by calling methods. The enclosing code then should call the update
26 /// method to advance the game to the next frame. Finally, the enclosing code
27 /// calls the draw method to render the game state. Note that the game state can
28 /// be drawn multiple times without updating the game, thus allowing the game
29 /// to be paused or stalled.
31 public interface IDeterministicGame
34 /// Call this method to give the game a chance to load its content.
36 /// <param name="contentManager">A valid content manager pointing to the root of the content tree</param>
37 void LoadContent (ContentManager contentManager);
40 /// Call this method to give the game a chance to unload its content.
45 /// Returns the preferred screen size for this game.
47 /// <returns></returns>
48 Vector2 PreferredScreenSize { get; }
51 /// Returns the minimum number of players this game can support.
53 /// <returns>the minimum player count</returns>
54 int MinimumSupportedPlayers { get; }
57 /// Returns the maximum number of players this game can support.
59 /// <returns>the maximum player count</returns>
60 int MaximumSupportedPlayers { get; }
63 /// Call this method to reset the game state, to set the current frame at 0, and
64 /// to supply identifiers for each player in the game. Player identifiers should
65 /// be unique object references (not structs) that the caller will use later
66 /// to identify each player. (It is important that these not be 'boxed' object
67 /// references or the reference will not be preserved.)
69 /// Since, in theory, there will be four copies of the game running, a second
70 /// parameter identifies the player that is running this copy of the game.
72 /// <param name="playerIdentifiers">An array of objects (references) that will identify each player</param>
73 /// <param name="playerIdentifiers">An object identifier for the player whose machine is displaying this game</param>
74 void ResetGame(Object[] playerIdentifiers, Object thisPlayer);
77 /// Returns the current frame number. This corresponds to the current state
78 /// of the game world.
80 /// <returns>the current frame number</returns>
81 long CurrentFrameNumber { get; }
84 /// Returns a checksum of all of the game world state. This checksum can be used
85 /// to ensure that multiple players at some frame all share the same state. It is
86 /// guaranteed that identical states will produce identical checksums.
88 /// <returns>the current game state checksum</returns>
89 long CurrentChecksum { get; }
92 /// Call this method to report changes in keypresses to the game. You should call this method
93 /// to report any changes in keyboard state for a player. The keyboard state will be
94 /// applied to the next game state (not the current state).
96 /// <param name="playerIdentifier">An object (reference) that was registered for a player in the game</param>
97 /// <param name="key">A key identifier</param>
98 /// <param name="isKeyPressed">The key state - true means pressed, false means released</param>
99 void ApplyKeyInput (Object playerIdentifier, Keys key, bool isKeyPressed);
102 /// Call this method to report changes in mouse locations to the game. You should call this method
103 /// any time the mouse coordinates for a player changes. The mouse information will
104 /// be applied to the next game state (not the current state).
106 /// <param name="playerIdentifier">an object (reference) that was registered for a player in the game</param>
107 /// <param name="x">the mouse x location</param>
108 /// <param name="y">the mouse y location</param>
109 void ApplyMouseLocationInput (Object playerIdentifier, int x, int y);
112 /// Call this method to report changes in mouse button state to the game. Note that only one
113 /// mouse button is supported in game. You should call this method to report any
114 /// changes in mouse button state for a player. The mouse button state will be
115 /// applied to the next game state (not the current state).
117 /// <param name="playerIdentifier">an object (reference) that was registered for a player in the game</param>
118 /// <param name="isButtonPressed">the mouse button state</param>
119 void ApplyMouseButtonInput (Object playerIdentifier, bool isButtonPressed);
122 /// Returns true if the specified player's game is over. They can be safely disconnected from the game
123 /// when this flag is true, their inputs do not affect game state. (You can continue to report inputs,
124 /// to allow the player to view a game over screen, but no game state action is taken.)
126 /// <param name="playerIdentifier">an object (reference) that was registered for a player in the game</param>
127 /// <returns>true if the game is over</returns>
128 bool IsGameOver(Object playerIdentifier);
131 /// Returns true if the specified player's game is over, and the player has clicked on something indicating
132 /// they wish to leave the game over screen. (This only becomes true if inputs are reported
133 /// even after the game is over.)
135 /// <param name="playerIdentifier">an object (reference) that was registered for a player in the game</param>
136 /// <returns>true if the player has terminated the game</returns>
137 bool IsTerminated(Object playerIdentifier);
140 /// Call this method to advance the game state. Previously sent inputs are applied
141 /// to the game state and the frame number is advanced and returned. Caution should be used when
142 /// supplying the seconds parameter - it can affect game state. All players in a game
143 /// should advance their game time by the same amount.
145 /// <param name="timespan">The elapsed game time</param>
146 /// <returns>the frame number of the new game state (now the current state)</returns>
147 long Update(TimeSpan timespan);
150 /// Draws the current game state. This does not affect the game state - it may be called
151 /// repeatedly to redraw the current game state if needed.
153 /// <param name="spriteBatch">a SpriteBatch object that has begun a batch</param>
154 /// <returns>the current game state frame number</returns>
155 long Draw(SpriteBatch spriteBatch);