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.
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.
- Create at least 10 “rooms” with descriptions and various exits
- Support at least two players, who switch turns; create only one Player class to represent a single player, and create two objects for two players
- Create a simple parser that interprets text commands like “go north” or “get lamp”
- Some rooms must have items, which may be picked up by the player
- Create containers, e.g. bags, chests, etc., which can contain items, and possibly also contain monsters and/or players
- Keep track of the player’s inventory (items the player has picked up) and support a command “inventory” which shows this inventory
- Create another class representing non-player characters (e.g., monsters) that move around the rooms autonomously
- Somehow list the monsters that are in the same room as the player (perhaps the player has to type a command to see this list)
- Support basic combat, e.g., use an item to attack a monster and reduce hit points