Ex45 Result - Cave of Wonders


#1

After about a week of working on this, I’ve completed my ex45 game.

I used the game engine and map from the previous game excercise. But I made a player class, and a player object, that made it easier to not retype certain types of code.

I was racking my brain on how to add all the things a player can do into the class, but then it was conceptually very difficult for me to think about it.

For example, each class for each room like : Class CaveOfWonders(scene):

contains many of the similar if and elif statements about movement. Hopefully I will be able to learn more python and be able to do it in the future.

Meaning:

Player Class, should be able to contain the code that allows a player to move.

Class Rooms(Scene): should just contain the code for the room itself, e.g. Display description. Display items. Display enemies.

Player Object should interact with those elements.


#2

So this is a general problem when you have to share a piece of data between a lot of objects. In your case you’ve got two things that are probably making this harder:

  1. You have inventory = [] right after player class, but then you use self.inventory to get at it. That works but it’s unclear if you understand what self.inventory is. You see, you should either put self.inventory = [] in the ```init`` method, OR, refer to this inventory variable as Player.inventory. The reason is the way you have it, the inventory is a class variable that is a single variable on all instances of class Player. If you made 1000 players, they’d have 1 inventory.

  2. You might be trying to put too much in your player class. You should basically think about what each room can do to a player. You can hit them, add things to their inventory, remove them, etc. Don’t try to put Room things into Player.

Personally I would ditch the inventory. That’s a much more complicated concept and seems to really mess people up on this exercise. Try just, hitpoints and their name.