Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Lab 7
- # 7.1: This game will be a text adventure game
- # Directions include: north, east, south, or west
- # 7.2 Sample Run:
- # You are in a dusty castle room.
- # Passages lead to the north and south.
- # What direction? n
- # You are in the armory.
- # There is a room off to the south.
- # What direction? s
- # You are in a dusty castle room.
- # Passages lead to the north and south.
- # What direction? s
- # You are in a torch-lit hallway.
- # There are rooms to the east and west.
- # What direction? e
- # You are in a bedroom. A window overlooks the castle courtyard.
- # A hallway is to the west.
- # What direction? w
- # You are in a torch-lit hallway.
- # There are rooms to the east and west.
- # What direction? w
- # You are in the kitchen. It looks like a roast is being made for supper.
- # A hallway is to the east.
- # What direction? w
- # Can't go that way.
- # You are in the kitchen. It looks like a roast is being made for supper.
- # A hallway is to the east.
- # What direction?
- # 7.3 Step-by-step Instructions
- # 1. Create an empty array called room_list
- # 2. Create a variable called room. Set it equal to an array with five elements.
- # For the first element, create a string with description of your first room.
- # The last four elements will be the number of the next room if the user goes
- # north, east, south, or west. Use None if no room hooks up to it.
- # (Do not put None in quotes. It is a special value that represents no value.)
- # ^ I think he's talking about NoneType or zero, one of the two
- # 3. Append tis room the room_list
- # 4. Repeat the prior two steps for each room you want to create.
- # Just re-use the room variable.
- # 5. Create a variable called current_room. Set it to zero.
- # 6. Using current_room and room_list, print the current room the user is in.
- # Run the program and confirm you get output similar to:
- # ['You are in a room. There is a passage to the north.', 1, None, None, None]
- # 7. Change the print statement so that you only print the description of the
- # room, and not the rooms that hook up to it: You are in a room.
- # There is a passage to the north.
- # 8. Create a variable called done and set it to False.
- # Then put the printing of the room description in a while loop that repeats
- # until done is set to True.
- # 9. After printing the room description, add a line of code that asks the
- # user what direction they wish to go.
- # 10. Add an if statement to see if the user wants to go north.
- # 11. If the user wants to go north, create a variable called next_room
- # and get it equal to room_list[current_room][1], which should be the number
- # for what room is to the north.
- # 12. Add another if statement to see if the next room is equal to None.
- # If it is, print "You can't go that way."
- # Otherwise set current_room equal to next_room.
- # 13. Test your program. Can you go north to another room?
- # SIDE NOTE, Redesign the path of these rooms later on to fit the layout
- # that the author wants on paper with a paper grid map
- room_list = []
- room = [0, 1, 2, 3, 4]
- # COURTYARD
- room[0] = "You have entered the castle courtyard. \n\nBirds bounce upon the stony courtyard and fly off into the distant blue sky"
- # Directions: North, East, South, or West
- # NORTH (Throne Room aka Room 1)
- room[1] = 1
- # EAST
- room[2] = None
- # SOUTH
- room[3] = None
- # WEST
- room[4] = None
- room_list.append(room)
- # Golden throne room with silver chalice spewing crimson blood:
- room = [0, 1, 2, 3, 4]
- room[0] = "You have entered what appears to be a throne room, caressed in gold in every direction.\n\nRubies, sapphires, and emeralds sparkle on the throne, while a silver chalice keeps overflowing crimson blood from some unknown source on a pedestal."
- # Directions: North, East, South, or West
- # NORTH (Armory aka Room 4)
- room[1] = 4
- # EAST (Dining Room aka Room 3)
- room[2] = 3
- # SOUTH (Courtyard aka Room 0)
- room[3] = 0
- # WEST (Electric Billiard Room aka Room 2)
- room[4] = 2
- room_list.append(room)
- # Create an electric billiard room with lightning spokes at each corner of the table
- room = [0, 1, 2, 3, 4]
- room[0] = "You have entered an electric billiard room. \n\nLightning spokes are at each end of the table and spark blue waves of electricity every five seconds. \n\nThe room is dimly lit but covered in a blue aura."
- # NORTH
- room[1] = None
- # EAST (Throne Room aka Room 1)
- room[2] = 1
- # SOUTH
- room[3] = None
- # WEST
- room[4] = None
- room_list.append(room)
- # Green Dining Hall:
- room = [0, 1, 2, 3, 4]
- room[0] = "You have opened a huge brown door and walked down marble steps into what appears to be a dining hall. \n\nGreen garland and banners circle the ceiling with matching Bat crests. \n\nThe plates and dining ware are impeccable sterile, and shinking due to the white light cascading through the ceiling's circular window."
- # NORTH
- room[1] = None
- # EAST
- room[2] = None
- # SOUTH
- room[3] = None
- # WEST (Throne Room aka Room 1)
- room[4] = 1
- room_list.append(room)
- # Armory:
- room = [0, 1, 2, 3, 4]
- room[0] = "You have opened a silver door to enter the armory. \n\nEach delicately crafted piece of armor gives off a green glow, and claymores the size of the tallest man on earth hang on racks on the wall. \n\nEach sword glows red upon your approach to the center of the room and trembles violently, clashing against the wall."
- # NORTH
- room[1] = None
- # EAST
- room[2] = None
- # SOUTH (Throne Room aka Room 1)
- room[3] = 1
- # WEST
- room[4] = None
- room_list.append(room)
- current_room = 0
- next_room = 0
- # Create a boolean variable for a loop condition:
- done = False
- while done == False:
- print("**************************")
- print("Welcome to Vampire Castle!")
- print("**************************")
- print("\n", room_list[next_room][0])
- direction = str(input("What direction would you like to go?\nOptions To Type: North, East, South, West.\nPress 'q' to quit."))
- direction = direction.lower()
- # User Selects North:
- if direction == "north":
- next_room = room_list[current_room][1]
- # User Selects East:
- elif direction == "east":
- next_room = room_list[current_room][2]
- # User Selects South:
- elif direction == "south":
- next_room = room_list[current_room][3]
- # User Selects West:
- elif direction == "west":
- next_room = room_list[current_room][4]
- # User Decides To Quit:
- elif direction == "q":
- done = True
- if direction is None:
- print("You can't go that way.")
- else:
- current_room = next_room
- # Continue with Step 12
- # Chapter 7 Lab Link:
- # http://programarcadegames.com/index.php?chapter=lab_adventure
- # Chapter 7 Chapter Link;
- # http://programarcadegames.com/index.php?chapter=introduction_to_lists&lang=en#section_7
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement