Game Development Reference
In-Depth Information
See Listing 8-14. In order to save space, the listing has been shortened. For the full code for this
chapter, please see the Source Code/Download area located on apress.com .
Listing 8-14. Saving the Vehicle Command
void SaveState(String Handle)
{
SharedPreferences settings = m_Context.getSharedPreferences(Handle, 0);
SharedPreferences.Editor editor = settings.edit();
// Command
String CommandHandle = Handle + "Command";
String CommandStr = m_Command + "";
editor.putString(CommandHandle, CommandStr);
// Code to save reset of class member variables
// Commit the edits!
editor.commit();
}
The MatchCommand() function converts a string value to a AIVehicleCommand enumeration and returns
it. This function is used in the LoadState() function to load a saved VehicleCommand object.
(See Listing 8-15.)
Listing 8-15. Matching a String Command to an Enumeration
static AIVehicleCommand MatchCommand(String CommandStr)
{
AIVehicleCommand Command = AIVehicleCommand.None;
if (CommandStr.equalsIgnoreCase("None"))
{
Command = AIVehicleCommand.None;
}
else
if (CommandStr.equalsIgnoreCase("Patrol"))
{
Command = AIVehicleCommand.Patrol;
}
return Command;
}
The MatchObjectsAffected() function converts a string to a AIVehicleObjectsAffected
enumeration. This function is used in the LoadState() function to load a VehicleCommand object.
(See Listing 8-16.)
 
Search WWH ::




Custom Search