def find_items(): """Finds items in rooms.""" check50.exists("item.py") # Check initial description try: check = check50.run(run_command).stdin("in") check.stdout(room_3_description, regex=False) for item in room_3_items: check.stdout(item, regex=False) except check50.Failure as error: raise check50.Failure("Could not find items upon first entering room.\n" " Remember to seperate multiple items by a " "single newline.\n" f" {error}") # Check for look command try: check = check50.run(run_command) moves = ["IN", "OUT", "IN", "LOOK"] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) for item in room_3_items: check.stdout(item, regex=False) except check50.Failure as error: raise check50.Failure("Could not find items when using LOOK.\n" f" {error}")
def helper_commands(): """Testing helper commands; HELP, LOOK, QUIT.""" # Test HELP try: check = check50.run(run_command).stdin("HELP") for help in help_statement: check.stdout(help) except check50.Failure as error: raise check50.Failure(f"HELP did not print the expected message.\n" " {error}") # Test LOOK command try: check50.run(run_command).stdin("LOOK").stdout(room_1_description, regex=False) check50.run(run_command).stdin("look").stdout(room_1_description, regex=False) except check50.Failure as error: raise check50.Failure(f"LOOK/look did not print the expected room" "description.\n {error}") # Test QUIT try: check50.run(run_command).stdin("QUIT").stdout("Thanks for playing!", regex=False).exit(0) except check50.Failure as error: raise check50.Failure(f"QUIT did not function as expected.\n" " {error}")
def move_once(): """Starting Adventure then moving once to the WEST.""" try: check50.run(run_command).stdout(room_1_description, regex=False) except check50.Failure as error: raise check50.Failure(f"Expected the description of initial " f"room when Adventure starts.\n {error}") check50.run(run_command).stdin("WEST").stdout(room_2_description, regex=False)
def conditional_move(): """Check if holding an item affects conditional movement.""" check = check50.run(run_command) moves = ["DOWN", "DOWN", "DOWN", "DOWN"] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) check.stdout("The grate is locked and you don't have any keys.", regex=False) check = check50.run(run_command) moves = ["IN", "TAKE keys", "OUT", "DOWN", "DOWN", "DOWN", "DOWN"] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) check.stdout(room_8_description, regex=False) for item in room_8_items: check.stdout(item, regex=False) # Check for move with multiple conditions. try: check = check50.run(run_command) moves = [ "IN", "TAKE KEYS", "OUT", "DOWN", "DOWN", "DOWN", "DOWN", "TAKE LAMP", "IN", "WEST", "WEST", "WEST", "TAKE BIRD", "WEST", "DOWN", "SOUTH", "TAKE NUGGET", "OUT", "DROP NUGGET", "UP", "EAST", "EAST", "EAST", "TAKE ROD", "WEST", "WEST", "LOOK" ] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) check.stdout(room_14_description, regex=False) moves = ["EAST", "DROP BIRD", "WEST", "LOOK"] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) check.stdout(room_15_description, regex=False) except check50.Failure as error: raise check50.Failure("Did not find correct room description when " "going WEST from room 13 holding either BIRD & " "ROD or just ROD.\n" f" {error}")
def special_move(): """Performing special moves such as JUMP or XYZZY.""" try: check = check50.run(run_command) moves = ["IN", "XYZZY"] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) check.stdout( "It is now pitch dark. If you proceed you will " "likely fall into a pit.", regex=False) except check50.Failure as error: raise check50.Failure("Could not perform XYZZY. Check " "CrowtherRooms.txt for all the different" "connections.")
def inventory(): """Using the INVENTORY command.""" # Check empty inventory. try: check = check50.run(run_command).stdin("INVENTORY") check.stdout("Your inventory is empty", regex=False) except check50.Failure as error: raise check50.Failure(f"Let the player know they have no items.\n" f" {error}") # Check having keys. check = check50.run(run_command) moves = ["IN", "TAKE keys", "INVENTORY"] for move in moves: check.stdout("> ") check.stdin(move, prompt=False) check.stdout("KEYS", regex=False) check.stdout("a set of keys", regex=False)