Input-/Output Window

From SemanticLab

Jump to: navigation, search

Requirements

  1. mud like text interface
  2. does not influence the game flow (no freezing of GameObjects etc.)
  3. 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.

Image:Messaging_framework.png

  1. every GameObject processing messages implements the IsMessageRecipient Interface and registers itself with the Manager using the registerMessageRecipient method.
  2. tell calls the sendMessage method and
    1. determines all MessageRecipients matching the given person, and
    2. relays the message to their sendMessage methods
    3. which saves the message (and its sender) in the recipient's GameObjectMessageQueue
  3. every GameCharacter is expected to call processMessages in its act method to process all messages it has received.
  4. note: the default processMessages implementation calls ask which responds to the message based on a question/answer mapping. addVocabulary and removeVocabulary allows 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

  1. A magician buys a potion and asks for the potion's price
  2. Characters only disclosing some information after a riddle has been solved
  3. ...
Personal tools