Home

HW06: Text adventure

Create a “text adventure” game, e.g., like Zork.

Because each person may create his/her own unique game, there is no test script. Just upload to bitbucket as usual.

Design

Game UML

Logic

main function:
- create rooms, players, items, etc.
- create gamemap object
- establish game map
- create parser object
- game loop: while(1)
  - for each player:
    - call readInput() from parser (see below)
  - for each monster:
    - call act() on monster

Parser:
- readInput(player):
  - show room info first, and item info
  - show a prompt, get input string
    - examples:
      - "help"
      - "go north", i.e., "go [direction]"
        - find room linked in that direction
          from player's current room
          (container), and then change the
          player's current container to
          that room, if there is one
          (if not, give a message)
      - "get lamp", i.e., "get [thing]"
        - find thing by name; search through
          the thingsInContainer in player's
          current container (which is the room)
          to find the pointer to the object,
          add it to player's inventory container,
          and remove from the room's container
      - "drop lamp"
      - "look"
        - show room info again
      - "look at [thing name]"
        - find thing with that name in room
        - if lifeform, show hit points, weapon, etc.
        - otherwise just show thing info
      - "hit [lifeform name]"
        - find thing with lifeform type in
          player's room, then cast pointer
          to LifeForm*, call player's own
          attack() method with target pointer
          - note, attack() method uses whatever
            weapon is currently equipped
      - "equip [thing name]"
        - check inventory for that thing,
          if weapon type, change current weapon
      - "put [thing] in [thing]"
        - find second thing in inventory, must
          be container (i.e., Bag)
        - find first thing in inventory
        - change container of first thing
          to bag
      - "take [thing] out of [thing]"

Monster's act() method:
- if lifeform exists in room, and weapon is
  equipped, choose random number,
  attack lifeform with 10% chance
- if weapon thing exists in room,
  pick up and equip (replacing prior weapon)
- if exits available, randomly pick one
  with 50% chance of moving
- random numbers:
  - rand() % 2 == 0 for 50% chance
  - rand() % 10 == 0 for 10% chance
  - etc.

Requirements

CSCI 221 material by Joshua Eckroth is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Source code for this website available at GitHub.