vendredi 27 mars 2015

Generating Random Numbers for a Combat Simulator

I am attempting to create a very basic Combat Simulator. Here is my code:



import random
#from random import * I had, at one time, created a D20 generator that used the * function. I have since removed it in favor of using randint()
sword = 0
D20 = 0

class Hero:

def swing_and_hit(sword, D20):

sword = D20
print(D20)
if sword >= 10:
print("You have defeated the Villian!")

elif sword < 10:
print("You have died!")

D20 = randint(1,20)
Adventurer = Hero
#Adventurer.D20_Func() Ignore this...aborted effort to try something
Adventurer.swing_and_hit(sword, D20)


Every time I run this at http://ift.tt/XeHtMf, the random number generator outputs 13. I cannot figure out why it does this...any thoughts? I have tried nesting the random number generation inside the function swing_and_hit, and it still generates the same number every time I run the program.





Aucun commentaire:

Enregistrer un commentaire