Filling in details

After I created my Item class and began using it, I soon realized that there are moments when I do not want item details to be printed separately because its description is already part of the room description itself and properly covered there.

But what if the player takes the item?, I can hear you wonder. In that case, my room description changes. Let me give you an example from my project. This is the description from one of the rooms.

This chamber has been abandoned for a long time, from the looks of it. Everything appears old and covered in dust motes. The air is redolent with the staleness of things past.
The chamber appears to have been a girl's bedroom. While the furniture is sparse and simple, unmoving eyes from a number of dolls are fixated on you wherever you move.
A simple bed has been positioned against one of the walls, but it is covered with a large white sheet.

In this description, the part…

A simple bed has been positioned against one of the walls, but it is covered with a large white sheet.

…is not part of the actual room description itself and if the player removes the sheet, it will change to this…

A simple bed has been positioned against one of the walls. A faded dress is lying on it.

To me, this simply looks and reads nicer than having the game print “There is a linen sheet here.”

To do this, I decided to change the Describe() function the Room class itself by allowing a text injection. Sorry, I couldn’t think of a better word.

As you can see, I achieve this with an additional parameter in the Describe() call. Because 90% of the rooms won’t need this—I am just guessing here—I am giving it a default value so I don’t have to worry about it in all these standard cases.

If I want to take advantage of the feature, in the class for that particular room I will then simply do this.

It’s pretty simple but a nice feature, I think, that will allow me to create more customized room description very easily. Naturally, I will also have to tell the linen sheet object itself that it should not be printed in the item listing of the room. To do that, I have added a new parameter to the Item class as well.

This allows me to check for the Mention flag when I prepare my item list of all the room’s items, and ignore all those where the flag is False. Again, because 90% of all items in the game should be printed, I am giving this parameter a default value of True so that in most cases, I do not have to do anything.

There are a few things I am noticing as my project is growing. For example, I am writing globals.theVerb and globals.theNoun a lot. I mean, A LOT!

It made me think about a way to simplify this and I am considering passing theVerb and theNoun into all Evaluate() functions so I can access them by a shorter name. I’ve also been told that doing that would improve performance. Not that I have any performance issues at this point, but if a program can run faster, why not pursue it?

I haven’t fully made up my mind yet because it would require me to change all the calls and implementations of Evaluate, but we’ll see. I’ll try and figure out how much PyCharm’s Refactoring tools can help me automate this. I will keep you posted.

Leave a Reply

Your email address will not be published. Required fields are marked *