This function is meant to organize all the combatants based on the initiative number they rolled in rollIntiative().
Local variables
def combatantOrganizer(self):
organizedOrder = []
theStringOrder = []
NumOrder = []
organizedOrder is where the updated list will be stored and this will late be used to update the old order. theStringOrder is where the names will be stored once the numbers have been organized. NumOrder is where the numbers will be stored and sorted from least to greatest.
The rundown
for fighter in self.order:
NumOrder.append(fighter[1])
NumOrder.sort()
First, I take all the numbers from the order and put them in NumOrder. Then I used .sort to organize all the numbers.
for Num in NumOrder:
for item in self.order:
if Num == item[1]:
theStringOrder.append(item[0])
Then I take the order and the NumOrder and match
up the numbers with their owner’s names and store the owner’s names in theStringOrder
in the same order that the numbers are in.
This is accomplished by taking one number from the NumOrder list and checking it with the pairings in the order. Then when I get a match I add the name of that match to theStringOrder, and move on to the next number in NumOrder.
counter = 0
while counter < len(NumOrder):
organizedOrder.append([theStringOrder[counter], NumOrder[counter]])
counter += 1
self.order = organizedOrder
I then set up organizedOrder by taking the NumOrder and theStringOrder and putting them in the organizedOrder together (name first then the number). I used a counter to make sure the two values are being pulled from the same index in the lists which they came from. Finally, I take the order and replace it with the organizedOrder.
With the initiative, monsters, and everything in place, combat is set up and all set to get going with
turn().
Comments
Post a Comment