I'm currently creating a simple console-based game in which the player can move between different rooms, pick up and use items, and eat food. In the game's current state that's about it.
What I need help with is:
Creating a good "Event" class for my game. The way I'd like it to work is that every item and room should be able to be associated with an Event.
As I'm new to this I'd appreciate any reading material related to this kind of procedure, or suggestions as to how it would be best to set up my class(es) considering the points below, or simply how to attack this kind of problem (that is having trouble deciding how to set up classes).
I want to be able to create different kinds of events, for example:
Output some text, and then ask the player a question. If the player gives the correct answer, do something.
Output some text, then remove an item from the player's inventory, and then move the player to another room.
What I'm trying to avoid:
The entire point of the game is to practice good class design, so things such as responsibility-driven design, cohesion and coupling are important aspects. Thus I want it to be as simple, reusable and independent as possible.
Having to hard-code every event so that an item or room simply calls a specific method in the Event class.
What I'm thinking at the moment:
Creating a few sub-classes so that I could for example create new events (and associate them) using: itemObject.setEvent(new Event(new Question("introText", "outroText", "correctAnswer")));
Please let me know if more info is needed! Thanks!
The Game Programming Gems books are great... though a bit pricey.
You can probably find a relevant article or two over on GameDev's Article list, and there's probably some good stuff buried in their forums
As for an Event class, you almost certainly want a base class with some number of subclasses (MoveEvent, InventoryEvent, etc). And if you really want to avoid hardcoding things, you should define your game in data files. Rooms, items, and events... plus anything else you tack on later. The format you use to define things is entirely up to you. I recommend something that will give you practical experience as this is a learning exercise: an XML parser you haven't used for example. Not the most efficient format to parse, but this is a console game, so that's not such an issue.
One suggestion I have for an Event subclass would be one that can chain other events together. The interface doesn't change, and it allows you to do things like "add this to the player's inventory, take that away, AND move them over here".