Mar-01-2017, 04:35 PM
Alright, so I am a total beginner at Python and I'm working on a project that should look something like this (with italic text being user input):
You realize you left your phone at home.
Look around the different rooms to find phone
You enter room Entry Way.
You see in this room: car keys.
Where do you want to go? (N, S, W, E) E
You enter room Living Room.
You see in this room: paintings, DVDs, nice couches.
Where do you want to go? (N, S, W, E) E
You enter room Kitchen.
You see in this room: a group of people talking.
Where do you want to go? (N, S, W, E) E
You can't go in that direction. Try another
direction (N, S, W, E): W
You enter room Living Room.
You see in this room: paintings, DVDs, nice couches.
Where do you want to go? (N, S, W, E) W
You enter room Entry Way.
You see in this room: car keys.
Where do you want to go? (N, S, W, E) [i]N
[/i]You enter room Dining Room.
You see this in the room: phone
Congrats, you found it!
Now go back to where you started.
Where do you want to go? (N, S, W, E) S
You enter room Entry Way.
You see this in the room: car keys.
Now you can go about the rest of your day!
So far I've got something like this with some notes explaining what I need to accomplish and what questions I have:
You realize you left your phone at home.
Look around the different rooms to find phone
You enter room Entry Way.
You see in this room: car keys.
Where do you want to go? (N, S, W, E) E
You enter room Living Room.
You see in this room: paintings, DVDs, nice couches.
Where do you want to go? (N, S, W, E) E
You enter room Kitchen.
You see in this room: a group of people talking.
Where do you want to go? (N, S, W, E) E
You can't go in that direction. Try another
direction (N, S, W, E): W
You enter room Living Room.
You see in this room: paintings, DVDs, nice couches.
Where do you want to go? (N, S, W, E) W
You enter room Entry Way.
You see in this room: car keys.
Where do you want to go? (N, S, W, E) [i]N
[/i]You enter room Dining Room.
You see this in the room: phone
Congrats, you found it!
Now go back to where you started.
Where do you want to go? (N, S, W, E) S
You enter room Entry Way.
You see this in the room: car keys.
Now you can go about the rest of your day!
So far I've got something like this with some notes explaining what I need to accomplish and what questions I have:
special_item = "phone" #configuration looks like this: # dining_room # || # entry_room = living_room = kitchen entry_way = ["Entry Way", ["car keys"], []] living_room = ["Living Room", ["paintings", "DVDs", "nice couches"], []] dining_room = ["Dining Room", [special_item], []] kitchen = ["Kitchen", ["a group of people talking"], []] # connect rooms based on their relationship to # North, South, West, East entry_way[2] = [dining_room, 0, 0, living_room] living_room[2] = [0, 0, entry_way, kitchen] dining_room[2] = [0, entry_way, 0, 0] kitchen[2] = [0, 0, living_room, 0] # print_message takes in a room and based on what's # inside the room, will print out the appropriate # message to describe the room def print_message(room): print("You enter " + room + ".") # How would I print the next line ("You see in this room: car keys)? # Get the player's choice. # Validate the choice by making sure it's a room they can go to # The parameter "rooms" is the list of possible connections for a room. # Return a room based on the player's choice # For example, rooms of entry_way would be: # rooms = [dining_room, 0, 0, living_room] # If the player chooses 'N', get_player_choice should return # dining_room. # def get_player_choice(rooms): # get the players choice of what direction they want to go choice = input("Where do you want to go? (N, S, W, E) ") print(" ") # we're going to translate the string input to a # number that means a particular direction # -1 is an invalid direction # 0 is north # 1 is south # 2 is west # 3 is east direction = -1 while direction == -1: if choice == "N" or choice == "n": direction = 0 elif choice == "S" or choice == "s": direction = 1 elif choice == "W" or choice == "w": direction = 2 elif choice == "E" or choice == "e": direction = 3 if direction == -1: choice = input("Please enter N, S, W, E to move. ") elif rooms[direction] == 0: choice = input("You can't go in that direction. Try another direction (N, S, W, E): ") direction = -1 return rooms[direction] def main(): # start the adventure # and let the player know what they're looking for print("You realize you left your " + special_item + " at home.") print("Look around the different rooms to find " + special_item) # initialize the current_room to be the starting room # initialize the item_found boolean variable to False current_room = entry_way item_found = False # While the special item is being searched for, # print a description of the current_room and # check if the special item is in the current_room. # Otherwise ask the player to make a choice. # will need to use the functions print_message() and get_player_choice() # and think about when you're in the room with the item or when you're not # while not item_found: if current_room != dining_room: #print_message(?) #get_player_choice(?) #Do I have to write the code above for each room individually? print("Congrats you found it!") print("Now go back to where you started.") # After finding special item, player goes back to the room where they started. # use a while loop? # call the main() function to start the program main()Any help from some of you Python wizards would be immensely appreciated. I'm not quite used to this kind of thinking just yet.