Input-/Output Window
From SemanticLab
Requirements
- mud like text interface
- does not influence the game flow (no freezing of GameObjects etc.)
- integrates commands to interact with the game
tell <person> <msg> - tells the given message to the specified person inventory - opens the game character's inventory
Examples
tell magician buy tell guard let me pass
Implementation
The following UML diagram outlines the implementation of the message framework.
- every GameObject processing messages implements the
IsMessageRecipientInterface and registers itself with theManagerusing the registerMessageRecipient method. - tell calls the
sendMessagemethod and- determines all MessageRecipients matching the given person, and
- relays the message to their
sendMessagemethods - which saves the message (and its sender) in the recipient's
GameObjectMessageQueue
- every GameCharacter is expected to call
processMessagesin itsactmethod to process all messages it has received. - note: the default
processMessagesimplementation callsaskwhich responds to the message based on a question/answer mapping.addVocabularyandremoveVocabularyallows you to modify that mapping and therefore the vocabulary to which your GameCharacter will respond.
The code snippet below illustrates an example ask method:
public String ask(String question) { if (vocabulary.containsKey( question.toLowerCase())) return vocabulary.get( question.toLowerCase()); else return VOCABULARY_DEFAULT_ANSWER; }
Overwriting ask allows your character to perform actions based on messages it receives.
public String ask(String question) { if (vocabulary.equalsIgnoreCase("myAction")) { myAction(); } }
Use cases / Problems
- A magician buys a potion and asks for the potion's price
- Characters only disclosing some information after a riddle has been solved
- ...


