Graphics Reference
In-Depth Information
// now set up some default data for this new player
// this player will be on its first lap
raceLaps.Add(currentID, 1);
// this player will be in last position
racePositions.Add(currentID, racePositions.Count + 1);
// store a reference to the race controller, to talk to later
raceControllers.Add ( currentID, theRaceController );
// default finished state
raceFinished[currentID]=false;
// increment our racer counter so that we don't have to do
// any counting or lookup whenever we need it
numberOfRacers++;
// pass this id back out for the race controller to use
return currentID;
}
public int GetRacePosition(int anID)
{
// just returns the entry for this ID in the racePositions
// hashtable
return (int)racePositions[anID];
}
public int GetLapsDone(int anID)
{
// just returns the entry for this ID in the raceLaps
// hashtable
return (int)raceLaps[anID];
}
public void CompletedLap(int anID)
{
// if should already have an entry in race laps, let's just
// increment it
raceLaps[anID]= (int)raceLaps[anID] + 1;
// here, we check to see if this player has finished the
// race or not (by checking its entry in
// raceLaps against our totalLaps var) and if it has
// finished, we set its entry in raceFinished hashtable
// to true. Note that we always have to declare the object's
// type when we get it from the hashtable, since
// hashtables store objects of any type and the system
// doesn't know what they are unless we tell it!
if((int)raceLaps[anID]==totalLaps)
{
raceFinished[anID]= true;
// tell the race controller for this ID that it is
// finished racing
tempRC = (RaceController) raceControllers [anID];
tempRC.RaceFinished();
}
Search WWH ::




Custom Search