So lets modify the Game State Management sample a bit to make it more suitable for a Network game.
- Open the project you downloaded earlier (see previous post)
- Edit the MainMenuScreen.cs file (under Screens)
/// <summary>
/// Constructor fills in the menu contents.
/// </summary>
public MainMenuScreen()
{
MenuEntries.Add("Single Player");
MenuEntries.Add("Multiplayer");
MenuEntries.Add("Options");
MenuEntries.Add("Exit");
}MenuEntries.Add("Multiplayer");
MenuEntries.Add("Options");
MenuEntries.Add("Exit");
Modify the OnSelectEntry(int entryIndex) to look like this:
/// <summary>
/// Responds to user menu selections.
/// </summary>
protected override void OnSelectEntry(int entryIndex)
{
switch (entryIndex)
{
}{
case 0:
// Play the game in single player mode
LoadingScreen.Load(ScreenManager, LoadGameplayScreen, true);
break;
case 1:
// Go to multiplayer selection screen
// On this screen you will select either on Local or Live
ScreenManager.AddScreen(new LiveOptionsMenuScreen());
break;
case 2:
// Go to the options screen.
ScreenManager.AddScreen(new OptionsMenuScreen());
break;
case 3:
// Exit the sample.
OnCancel();
break;
}// Play the game in single player mode
LoadingScreen.Load(ScreenManager, LoadGameplayScreen, true);
break;
// Go to multiplayer selection screen
// On this screen you will select either on Local or Live
ScreenManager.AddScreen(new LiveOptionsMenuScreen());
break;
// Go to the options screen.
ScreenManager.AddScreen(new OptionsMenuScreen());
break;
// Exit the sample.
OnCancel();
break;
3. Create a new class under the Screens subfolder called "LiveOptionsMenuScreen.cs"
4. Edit the LiveOptionsMenuScreen.cs file:
#region Using Statements
using Microsoft.Xna.Framework;
#endregion
namespace GameStateManagement
{
class LiveOptionsMenuScreen : MenuScreen
{
}{
/// <summary>
/// Constructor populates the menu with empty strings: the real values
/// are filled in by the Update method to reflect the changing settings.
/// </summary>
public LiveOptionsMenuScreen()
{
/// <summary>
/// Responds to user menu selections.
/// </summary>
protected override void OnSelectEntry(int entryIndex)
{
/// <summary>
/// When the user cancels the options screen, go back to the main menu.
/// </summary>
protected override void OnCancel()
{
}/// Constructor populates the menu with empty strings: the real values
/// are filled in by the Update method to reflect the changing settings.
/// </summary>
public LiveOptionsMenuScreen()
{
MenuEntries.Add("XBox LIVE");
MenuEntries.Add("Split Screen");
MenuEntries.Add("System Link");
MenuEntries.Add("Back");
}MenuEntries.Add("Split Screen");
MenuEntries.Add("System Link");
MenuEntries.Add("Back");
/// <summary>
/// Responds to user menu selections.
/// </summary>
protected override void OnSelectEntry(int entryIndex)
{
switch (entryIndex)
{
}{
case 0:
} // XBox LIVE
break;
case 1:break;
// Split Screen
break;
case 2:break;
// System Link
break;
case 3:break;
// Back
// Go back to the main menu.
ExitScreen();
break;
// Go back to the main menu.
ExitScreen();
break;
/// <summary>
/// When the user cancels the options screen, go back to the main menu.
/// </summary>
protected override void OnCancel()
{
ExitScreen();
}Now if you press F5 to Build the game you should see something like this:


No comments:
Post a Comment