I'm quite new to Python and programming in general.
I'm making a terminal based game as a practice project. The game will a series of rooms and monsters. My plan was to make monsters and rooms instances of these classes. I'm creating several of these throughout the game and many of them a created on the fly, based on player actions.
When creating new monsters and rooms, i'm currently stuck to knowing their names beforehand. like so:
class Monster(object):
pass
Monster1 = Monster(something)
Having to know the instance name pre runtime seems like a clumsy solution. I was thinking it would be easier to have a variable keep track of the number of monsters, and then dynamically create the instance names. So that the first monster instance created would automaticallt be Monster1, the next would be Monster2 etc.
Something like this:
class Monster(object):
pass
monster_id = 0
def createMonster(monster_id)
monster_instance = "Monster" + str(monster_id)
monster_id += 1
# The following is where i'm stuck. Basically I want to have the instance name be equal to the content of monster_instance
(monster_instance) = Monster()
So the questions is: How can I create instances of a class without knowing the name of the instance pre runtime?
I'm also wondering if I'm having a hard time getting this to work, because I'm doing something stupid and that is a much smarter/elegant way of doing this. All help and input is much appreciated under all circumstances.