Graphics Reference
In-Depth Information
The sortedPositions Hashtable is constructed here by looping through all of the play-
ers. Each player's score board position is used as a key in sortedPositions, adding the value
of the player's battleController:
// this function builds a string containing a list of
// players in order of their scoring positions
// now we step through each battler and check their
// positions to determine whether or not
for ( int b = 1; b <= numberOfBattlers; b++ )
{
whichPos= GetPosition( b );
tempRC = (BattleController) battleControllers [b];
sortedPositions[whichPos]= tempRC.GetID();
}
In case something has gone wrong with building the sortedPositions Hashtable, a
quick count check ensures that some kind of string will get returned regardless. If there
has been a problem (which, in theory, should not happen), an empty string is returned:
if(sortedPositions.Count<numberOfBattlers)
return "";
posList="";
We can now access the sortedPositions Hashtable by its score board position key. To
build out the sorted string, the loop b goes through to the value of numberOfBattlers,
each time adding the value of sortedPositions[b] (the player number as per the original
playerPrefabs array on game controller) to posList, as a string with a little extra formatting:
// now we have a populated sortedPositions hash table, let's
// iterate through it and build the string
for ( int b = 1; b <= numberOfBattlers; b++ )
{
whichPos= (int)sortedPositions[b];
posList=posList+b.ToString()+". PLAYER
"+whichPos+"\n";
}
return posList;
}
GetPosition() will look at all of the players and compare scores to find the score board
position of the player identified by the ID passed in as a parameter:
public int GetPosition ( int ofWhichID )
{
The function starts out with a few safety checks to make sure everything is set up cor-
rectly and that the ID passed in is a valid one:
// first, let's make sure that we are ready to go (the
// hashtables may not have been set up yet, so it's
// best to be safe and check this first)
Search WWH ::




Custom Search