mardi 21 avril 2015

In python, how do I call a class multiple times and have randint be random?

In Python, I was trying to make a character using a class with a random integer as a health value, but the result is the same every time.

class Player():
    life = randint(25,30)
    maxhealth = life
    attack = 5
    name = ""
    ......

The method I create the players with is like this:

playernum = -1
while playernum < 1:
    playernum = int(input("How many players? "))
players = []
for x in range(playernum):
    print("Player " + str(x+1))
    players.append(Player())

How do I change it so that the health value is different for each player I create?




Aucun commentaire:

Enregistrer un commentaire