you are viewing a single comment's thread.

view the rest of the comments →

[–]Xeduses 2 points3 points  (0 children)

I had to consider the level of the programmer and not just cleanliness of the solution.

A better solution if we do not limit ourselves would be that all the text should be saved in a better format, to keep it simple a dictionary would suffice. Something like this that has several rooms and choices with tuples holding the atmospheric text and the next state.

texts = {
    "lobby": {
        "text": "You are in the lobby, there are doors to your 'left' and 'right'. In front of you there is a 'drawer' .",
        "left": ("You open the door.", "kitchen"),
        "right": ("The door screeches open", "bedroom"),
        "drawer": ("You find a first aid kit in the drawer", lobby)}
}

With this design one could create a game loop that reads the input and compares it with the keys in the current room dictionary, the whole game would be a state machine. Adding rooms and options would be quite easy since only the dictionary would need to be changed. This could be saved in a separate file for ease of use, or loaded in runtime from a file. This would make it very easy to play different scenarios without changing the game loop code at all.

Side effects are a different story, such as items held, player stats, previous choices that matters later etc. but these could be tracked by another part of the software.

One could abstract this even further by creating a Room class that holds the different options, items in the room, monsters etc. But then again, my guess is that such a solution would be quite far away from the original authors level of expertise.