Coding Your Game1 Class
The first thing you'll need to do in your Game1
class is add an enum that you'll use to represent
game states. We've discussed game states in previous chapters, but they're never
more important than in networked games. Beyond the typical states in a game (a start
state where you display instructions or splash screens, an in-game state, and an
end-game state), in a networked game you'll usually also have a sign-in state where
the player signs into Xbox LIVE or Games for Windows LIVE, a state where you find
sessions of your game, and a state where you create sessions.
You'll actually want to add the following enum
outside of the Game1 class, between the Catch namespace declaration and the class declaration.
This will allow any other classes you may add later to access the game states more
easily:
namespace Catch
{
// Represents different states of the game
public enum GameState { SignIn, FindSession,
CreateSession, Start, InGame, GameOver }
public class Game1 : Microsoft.Xna.Framework.Game
{
...In addition, you'll need to add another enum
that represents different types of messages that are sent across the network. Why?
You need this because, as you'll see shortly, when your game reads data from the
network, it needs to know in advance what type of data is coming in (an int, a string, a
Vector2, etc.). You'll also need to know how
much data is coming (two ints? three ints? one int and
two strings?). That's not a problem if you're always sending the exact same ...