samedi 19 février 2022

Python - My while loop not generating random numbers in a function called inside the while loop

I'm trying to get the while loop to randomize a monster stats and its name on a function called inside the loop, it creates it onces but it's not randomieze everytime the while completes a loop.

Everytime I run the Mobs() outside the loop, the mobs are randomize, yet somehow it doesn't work on inside the loop.

import random
import time

mobs = ['rat', 'snake', 'bat', 'spider', 'mole', 'hawk', 'fox', 'vulture', 'beetle']

mobs_names = random.choice(mobs)
mob_hp = random.randint(45, 60)
mob_damage = random.randint(8, 13)
mob_exp = random.randint(20, 23)

class Mobs:
    def __init__(self, hp=mob_hp, damage=mob_damage, name=mobs_names, exp=mob_exp):

        self.hp = hp
        self.damage = damage
        self.name = name
        self.exp = exp

        print("Monster is a " + self.name.title() + ' and it\'s stats are...')
        print('HP: ' + str(self.hp))
        print('Attack Damage: ' + str(self.damage))

gameloop = True

#spawn_mobs = Mobs()
world_level = 0
battlebegun = print("Battle has started")

while gameloop == True:
    while world_level < 10:
        world_level += 1
        print(world_level)
        if world_level <= 10:
            spawn_mobs = Mobs()
            battlebegun
            time.sleep(1)
            continue

    break #gameloop = False


print("Game over")




Aucun commentaire:

Enregistrer un commentaire