]> Dogcows Code - chaz/carfire/blob - CarFire/CarFire/CarFire/IDeterministicGame.cs
git-svn-id: https://bd85.net/svn/cs3505_group@114 92bb83a3-7c8f-8a45-bc97-515c4e399668
[chaz/carfire] / CarFire / CarFire / CarFire / IDeterministicGame.cs
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using Microsoft.Xna.Framework;
6 using Microsoft.Xna.Framework.Graphics;
7 using Microsoft.Xna.Framework.Input;
8 using Microsoft.Xna.Framework.Content;
9
10 namespace CarFire
11 {
12 /// <summary>
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.
16 ///
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.
20 ///
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.
30 /// </summary>
31 public interface IDeterministicGame
32 {
33 /// <summary>
34 /// Call this method to give the game a chance to load its content.
35 /// </summary>
36 /// <param name="contentManager">A valid content manager pointing to the root of the content tree</param>
37 void LoadContent (ContentManager contentManager);
38
39 /// <summary>
40 /// Call this method to give the game a chance to unload its content.
41 /// </summary>
42 void UnloadContent();
43
44 /// <summary>
45 /// Returns the preferred screen size for this game.
46 /// </summary>
47 /// <returns></returns>
48 Vector2 PreferredScreenSize { get; }
49
50 /// <summary>
51 /// Returns the minimum number of players this game can support.
52 /// </summary>
53 /// <returns>the minimum player count</returns>
54 int MinimumSupportedPlayers { get; }
55
56 /// <summary>
57 /// Returns the maximum number of players this game can support.
58 /// </summary>
59 /// <returns>the maximum player count</returns>
60 int MaximumSupportedPlayers { get; }
61
62 /// <summary>
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.)
68 ///
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.
71 /// </summary>
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);
75
76 /// <summary>
77 /// Returns the current frame number. This corresponds to the current state
78 /// of the game world.
79 /// </summary>
80 /// <returns>the current frame number</returns>
81 long CurrentFrameNumber { get; }
82
83 /// <summary>
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.
87 /// </summary>
88 /// <returns>the current game state checksum</returns>
89 long CurrentChecksum { get; }
90
91 /// <summary>
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).
95 /// </summary>
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);
100
101 /// <summary>
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).
105 /// </summary>
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);
110
111 /// <summary>
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).
116 /// </summary>
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);
120
121 /// <summary>
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.)
125 /// </summary>
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);
129
130 /// <summary>
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.)
134 /// </summary>
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);
138
139 /// <summary>
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.
144 /// </summary>
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);
148
149 /// <summary>
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.
152 /// </summary>
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);
156 }
157 }
This page took 0.065688 seconds and 4 git commands to generate.