RoomTest.py
from room import *
- Constants:
WARRIOR_HP = 50 WARRIOR_STR = 10 WARRIOR_SKILL = 15 WARRIOR_AC = 5 WARRIOR_NAME = "Gnusto Frotz" WARRIOR_TYPE = "valiant warrior" WARRIOR_PRONOUN = "his"
MONSTER_HP = 50 MONSTER_STR = 15 MONSTER_SKILL = 10 MONSTER_AC = 7 MONSTER_NAME = "Schmoo" MONSTER_TYPE = "gruesome ghost" MONSTER_PRONOUN = "its"
GRUE_HP = 100 GRUE_STR = 20 GRUE_SKILL = 15 GRUE_AC = 10 GRUE_NAME = "Grue" GRUE_TYPE = "boss ghost" GRUE_PRONOUN = "his"
CLAWS_DAMAGE_MOD = 3 CLAWS_NAME = "claws" CLAWS_HIT = "slashes" CLAWS_MISS = "swipes at but misses"
SWORD_DAMAGE_MOD = 5 SWORD_NAME = "sword" SWORD_HIT = "stabs" SWORD_MISS = "swings at but misses"
WAND_DAMAGE_MOD = 30 WAND_NAME = "magic wand" WAND_HIT = "blasts a fireball at" WAND_MISS = "aims at but misses"
INTRO = """
Welcome to the game. You control the actions of the valient Gnusto Frotz, a warrior who has stumbled into a spooky haunted house.
You can use commands such as 'north' or simply 'n' to move.
You can use 'attack' to attack a monster with a single blow.
You can also use 'look' to examine the room you are in, and 'get <thing> to pick up an item named <thing>.
Finally, you can type <quit> when you are done playing.
"""
currentRoom = Room()
- create the weapons, creatures, and rooms
claws = Weapon(CLAWS_NAME, CLAWS_DAMAGE_MOD, CLAWS_HIT, CLAWS_MISS) sword = Weapon(SWORD_NAME, SWORD_DAMAGE_MOD, SWORD_HIT, SWORD_MISS) wand = Weapon(WAND_NAME, WAND_DAMAGE_MOD, WAND_HIT, WAND_MISS)
player = Creature(WARRIOR_NAME, WARRIOR_TYPE, WARRIOR_PRONOUN, WARRIOR_HP, WARRIOR_STR, WARRIOR_SKILL, WARRIOR_AC) monster = Creature(MONSTER_NAME, MONSTER_TYPE, MONSTER_PRONOUN, MONSTER_HP, MONSTER_STR, MONSTER_SKILL, MONSTER_AC) monster.weapon = claws
grue = Creature(GRUE_NAME, GRUE_TYPE, GRUE_PRONOUN, GRUE_HP, GRUE_STR, GRUE_SKILL, GRUE_AC)
kitchen = Room("This is the spooky kitchen of the haunted house", None, None) diningRoom = Room("This is the tattered dining hall of the haunted mansion", monster, sword) parlor = Room("This is the decrepit parlor. The once-rich tapesties and mouldering furniture fill you with a sense of foreboding.") pit = Room("Oh no! You've fallen in a pit. There is no way out. You might as well quit.\n") hallway = Room("This is a long creepy hallway from the parlor to the bedrooms.") bedroom = Room("This is the haunted bedroom. A stench of evil pervades the air.", grue, wand)
- connect the rooms together
kitchen.roomToEast = diningRoom diningRoom.roomToWest = kitchen diningRoom.roomToNorth = parlor parlor.roomToSouth = diningRoom parlor.roomToNorth = pit parlor.roomToEast = hallway hallway.roomToWest = parlor hallway.roomToEast = bedroom bedroom.roomToWest = hallway
- place the player and print introduction
currentRoom = kitchen print(INTRO)
- main loop
while True:
newRoom = currentRoom.enterRoom(player) if (newRoom == None): print("Thank you for playing! Goodbye.") break else: currentRoom = newRoom