I am new to python, about 3 days, and I am not sure if I have worded the question properly.
I have a class:
class blue_slime:
nom = "BLUE SLIME"
img = " /\ \n( o o)"
str = 10
int = 5
dex = 5
con = 10
spd = 10
hp = ((con + str) / 2)
mp_bonus = 1
and I want to use the variables from this class in another function.
def encounter(nom, hp, img):
print(char_name + " encountered a " + nom + "!!!")
wait()
while hp > 0:
battle(hp, img)
else:
stats()
now I know that I could call this by using
encounter(blue_slime.nom, blue_slime.hp, blue_slime.img)
but I would much rather (and think it may be necessary for my program down the line) be able to just use the class name as the function argument and then in the function I can just utilize all variables without having to write them in each time. While this may sound like laziness, I am thinking about making the encounter be random, so 10% chance to encounter(blue_slime) 10% chance to encounter(green_slime).
I feel the easiest way to implement this would be to somehow condense all the variables in "class blue_slime" into one name.
please let me know if there is a way to do this, perhaps I have just not learned it yet.
encounter(some_monster_object_with_a_name_hp_and_an_image)-- seems OK. While a class is an object, the code will likely be more successful if creating and using instances. Maybe there are TWO big blue slime monsters!