Graphics Reference
In-Depth Information
As the race is just beginning, not ending, the raceFinished state of this player is
defaulted to false:
// default finished state
raceFinished[currentID]=false;
We may as well keep a count of how many players there are here, since all new players
will have to be fed through this function. It will save having to count any array later to
find out how many players there are, as the integer numberOfRacers will hold the count:
// increment our racer counter so that we don't have to do
// any counting or lookup whenever we need it
numberOfRacers++;
The currentID is returned to the RaceController calling this function, and the race
controller will use it for its unique ID number throughout the game:
// pass this id back out for the race controller to use
return currentID;
}
GetRacePosition() takes an ID as a parameter and returns the race position of that
player, as stored in the racePositions Hashtable. Accessing data from the Hashtable is a
straightforward exercise of providing the key within square brackets:
public int GetRacePosition(int anID)
{
// just returns the entry for this ID in the racePositions
// hashtable
return (int)racePositions[anID];
}
Just like GetRacePosition(), the GetLapsDone() function takes an ID as a parameter
and returns the current lap count of that player, as stored in the raceLaps Hashtable:
public int GetLapsDone(int anID)
{
// just returns the entry for this ID in the raceLaps
// hashtable
return (int)raceLaps[anID];
}
CompletedLap() is called by a RaceController when the player passes all of the waypoints
and crosses the start/finish line. The parameter it takes is an integer, the player's unique ID:
public void CompletedLap(int anID)
{
The entry for anID in the raceLaps Hashtable is incremented by adding 1 to its cur-
rent value:
// if should already have an entry in race laps, let's just
// increment it
raceLaps[anID]= (int)raceLaps[anID] + 1;
Search WWH ::




Custom Search