Agent Mission Game

docx

School

Southern New Hampshire University *

*We aren’t endorsed by this school

Course

140 - X625

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

3

Uploaded by CorporalSardine2367

Report
# Nick Nguyen # Start game # Output to print instructions and intro def game_instructions (): print ( "Agent Mission Game" ) print ( "Collect 6 items to win the game, or be captured by The Big Boss!!!" ) print ( 'Move commands: North , South , East , West' ) print ( "Add to inventory: Get 'item name'" ) print ( "Quit game: Exit" ) print ( "*" * 50 ) # Define dictionary # List rooms and items game_instructions() rooms = { 'Banquet Room' : { 'North' : 'Storage Room' , 'South' : 'Office' , 'East' : 'Stairway Access to Roof' , 'West' : 'Security Room' , 'item' : 'Map With Instructions' } , 'Storage Room' : { 'South' : 'Banquet Room' , 'East' : 'Master Bedroom' , 'item' : 'Knockout Gas Grenade' } , 'Master Bedroom' : { 'West' : 'Storage Room' , 'item' : 'The Big Boss' } , 'Security Room' : { 'East' : 'Banquet Room' , 'item' : 'Keys To Helicopter' } , 'Office' : { 'North' : 'Banquet Room' , 'East' : 'Computer Room' , 'item' : 'Flashlight' } , 'Computer Room' : { 'West' : 'Office' , 'item' : 'Usb Drive' } , 'Stairway Access to Roof' : { 'North' : 'Roof' , 'West' : 'Banquet Room' , 'item' : 'Bolt Cutters' } , 'Roof' : { 'South' : 'Stairway Access to Roof' } } if __name__ == "__main__" : current_room = 'Banquet Room' # Player starts at the Banquet Room inventory = [] # List for storing player inventory # Function for getting location def get_new_room (current_room , direction): new_room = current_room # New room as current room for i in rooms: # Start loop if i == current_room: # If statement if direction in rooms[i]: # If statement new_room = rooms[i][direction] # Assign new room return new_room # Return new room # Function for getting items def get_item (current_room): # Get items if 'item' in rooms[current_room]: # If statement return rooms[current_room][ 'item' ] # Return statement if 'item' not in rooms[current_room]: # If statement return 'This room has no item!' # Return statement
# Game play loop # Starts an infinite while loop while True : print ( 'You are in the' , current_room) # States current room print ( 'Inventory:' , inventory) # Lists inventory direction = input ( 'Enter direction you would like to move >> ' ) # Prompt player to enter direction direction = direction.capitalize() # Capitalize first letter if direction == 'Exit' : # If player quits or exit game print ( 'Goodbye!' ) break # Initialize loop to check for valid movement between rooms if direction == 'North' or direction == 'South' or direction == 'East' or direction == 'West' : # if statement new_room = get_new_room(current_room , direction) if new_room == current_room: # If invalid direction, prompt player for new direction print ( 'You can \' t go that way.' ) else : # If valid direction, change room current_room = new_room item = get_item(current_room) # Define item as get_item print (item) if item == 'The Big Boss' : # If player enters the Master Bedroom print ( 'You are caught by The Big Boss' ) print ( 'Thank you for playing!' ) break if item != 'The Big Boss' : if current_room != 'Roof' : if item in inventory: # If statement print ( 'You have already collected this item. Move to another room!' ) else : print ( 'You found the' , item , 'you should pick it up!' ) pickup = input () pickup = pickup.title() if pickup == str ( 'Get ' + item): # Input to get item inventory.append(item) # Add item to inventory print ( "You got the " + item + "!" ) if pickup == 'Exit' : print ( 'Goodbye!' ) break if current_room == 'Roof' : # If statement if len (inventory) == 6 : # Win, if player collects all the items print ( 'Success! You have collected all of the items.' ) print ( 'Congratulations, mission accomplished!' ) print ( 'Thank you for playing!' ) break if len (inventory) != 6 : # Lose, if player does not collect all the items
print ( 'Oh NO! You did not collect all of the items!' ) print ( 'Mission Failed!' ) print ( 'Thank you for playing!' ) break else : # If invalid command, prompt user to enter new direction print ( 'Invalid input, move or item' ) # End game
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help