OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

getting a response, dont understand where its coming from

  • Thread starter Thread starter Joshua Mantooth
  • Start date Start date
J

Joshua Mantooth

Guest
I am doing a text based game for a school project in my scripting class. The code is working fine with all my test. However, there is one thing happening I cannot figure out why. I have added on option for the user to input "map" and it displays a layout of the rooms. When you perform this input it also outputs "None" and I cannot understand why its doing this.. ive included the entire code as its a small code and maybe its somewhere in the code thats causing this however i commented the piece that calls for it to print the map.. but I dont understand.

Code:
def intro():
    print('Welcome to the Hungry Karen game!!!'),
    print('Karen is Hungry, she ordered food for pickup. However she forgot to complete the online order.'),
    print('She is very upset with the restaurant that her order is not ready, she wants answers!'),
    print('Collect your items before dealing with her or she will ruin your day.'),
    print('You will need: \n - A cigarette in the Outside Alley \n - Pencil from the Office'
          ' \n - A beer from the Walk-in Cooler', ' \n - Cupcake from the Kitchen'
          '\n - Your notepad from the Dining Room \n - An espresso from the Barista Parlor'),
    print('You wont need any supplies from the bathroom, but feel free to take a few minutes to yourself here.'),
    print('See a floorplan of the restaurant by typing "map"')

intro()

rooms = {
    'Host Stand': {'west': 'Barista Parlor'},
    'Barista Parlor': {'east': 'Host Stand', 'south': 'Dining Room', 'item': 'espresso'},
    'Dining Room': {'west': 'Bathroom', 'north': 'Barista Parlor', 'east': 'Office', 'south': 'Kitchen',
                    'item': 'notepad'},
    'Bathroom': {'east': 'Dining Room'},
    'Kitchen': {'east': 'Walk-in Cooler', 'north': 'Dining Room', 'item': 'cupcake'},
    'Office': {'north': 'Outside Alley', 'west': 'Dining Room', 'item': 'pencil'},
    'Outside Alley': {'south': 'Office', 'item': 'cigarette'},
    'Walk-in Cooler': {'west': 'Kitchen', 'item': 'beer'}
}
# Player begins game in the Bathroom
starting_room = 'Bathroom'
# setting room up
current_room = starting_room
# define inventory dictionary
inventory = []

# Function to display player's status and possible commands
def display_status():
    print(' ')
    print('You are in the', current_room)
    print('Inventory:', inventory)
    if 'item' in rooms[current_room]:
        print('You see a', rooms[current_room]['item'])
    print("\nEnter your move:")

def map():
    print(
'\n         Barista Parlor ----- Host Stand'
'\n              | '
'\n              |        Outside Alley '
'\n              |              |  '
'\n Bathroom - Dining Room ----Office'
'\n              |'
'\n          Kitchen -- Walk-in Cooler')


while True:
        # Show current status
        display_status()

        # Get the player's next move
        move = input('>').strip().split()
        if len(move) < 1:
            print('Invalid input. Try Again')
        command = move[0].lower()

        if command == "go":
            if len(move) < 2:
                print("Invalid input. Try again.")
                continue
            direction = move[1]
            if direction in rooms[current_room]:
                current_room = rooms[current_room][direction]
            else:
                print("You can't go that way!")
        elif command == "get":
            if len(move) < 2:
                print("Invalid input. Try again.")
                continue
            item = " ".join(move[1:])
            if 'item' in rooms[current_room] and rooms[current_room]['item'] == item:
                inventory.append(item)
                del rooms[current_room]['item']
                print(f"you got the {item}")
            else:
                print("Can't get that item!")
        elif command == "quit":
            print('Thanks for playing!')
            break
# Map print out feature !!!!!!!!!!!
        elif command == "map":
            print(map())
            continue
        else:
            print("Invalid command. Try again.")
# Check win/lose conditions
        if current_room == 'Host Stand':
            if len(inventory) == 6:
                print('You kept your cool while Karen expressed how upset this made her. She left happy!')
                print('You even got tipped extra on top! Good Job!')
                break
            else:
                print("Karen made you cry and rethink your career choices. Game Over. You lose")
                break

i looked over the entire code and dont see why this would print
<p>I am doing a text based game for a school project in my scripting class. The code is working fine with all my test. However, there is one thing happening I cannot figure out why. I have added on option for the user to input "map" and it displays a layout of the rooms. When you perform this input it also outputs "None" and I cannot understand why its doing this.. ive included the entire code as its a small code and maybe its somewhere in the code thats causing this however i commented the piece that calls for it to print the map.. but I dont understand.</p>
<pre><code>
def intro():
print('Welcome to the Hungry Karen game!!!'),
print('Karen is Hungry, she ordered food for pickup. However she forgot to complete the online order.'),
print('She is very upset with the restaurant that her order is not ready, she wants answers!'),
print('Collect your items before dealing with her or she will ruin your day.'),
print('You will need: \n - A cigarette in the Outside Alley \n - Pencil from the Office'
' \n - A beer from the Walk-in Cooler', ' \n - Cupcake from the Kitchen'
'\n - Your notepad from the Dining Room \n - An espresso from the Barista Parlor'),
print('You wont need any supplies from the bathroom, but feel free to take a few minutes to yourself here.'),
print('See a floorplan of the restaurant by typing "map"')

intro()

rooms = {
'Host Stand': {'west': 'Barista Parlor'},
'Barista Parlor': {'east': 'Host Stand', 'south': 'Dining Room', 'item': 'espresso'},
'Dining Room': {'west': 'Bathroom', 'north': 'Barista Parlor', 'east': 'Office', 'south': 'Kitchen',
'item': 'notepad'},
'Bathroom': {'east': 'Dining Room'},
'Kitchen': {'east': 'Walk-in Cooler', 'north': 'Dining Room', 'item': 'cupcake'},
'Office': {'north': 'Outside Alley', 'west': 'Dining Room', 'item': 'pencil'},
'Outside Alley': {'south': 'Office', 'item': 'cigarette'},
'Walk-in Cooler': {'west': 'Kitchen', 'item': 'beer'}
}
# Player begins game in the Bathroom
starting_room = 'Bathroom'
# setting room up
current_room = starting_room
# define inventory dictionary
inventory = []

# Function to display player's status and possible commands
def display_status():
print(' ')
print('You are in the', current_room)
print('Inventory:', inventory)
if 'item' in rooms[current_room]:
print('You see a', rooms[current_room]['item'])
print("\nEnter your move:")

def map():
print(
'\n Barista Parlor ----- Host Stand'
'\n | '
'\n | Outside Alley '
'\n | | '
'\n Bathroom - Dining Room ----Office'
'\n |'
'\n Kitchen -- Walk-in Cooler')


while True:
# Show current status
display_status()

# Get the player's next move
move = input('>').strip().split()
if len(move) < 1:
print('Invalid input. Try Again')
command = move[0].lower()

if command == "go":
if len(move) < 2:
print("Invalid input. Try again.")
continue
direction = move[1]
if direction in rooms[current_room]:
current_room = rooms[current_room][direction]
else:
print("You can't go that way!")
elif command == "get":
if len(move) < 2:
print("Invalid input. Try again.")
continue
item = " ".join(move[1:])
if 'item' in rooms[current_room] and rooms[current_room]['item'] == item:
inventory.append(item)
del rooms[current_room]['item']
print(f"you got the {item}")
else:
print("Can't get that item!")
elif command == "quit":
print('Thanks for playing!')
break
# Map print out feature !!!!!!!!!!!
elif command == "map":
print(map())
continue
else:
print("Invalid command. Try again.")
# Check win/lose conditions
if current_room == 'Host Stand':
if len(inventory) == 6:
print('You kept your cool while Karen expressed how upset this made her. She left happy!')
print('You even got tipped extra on top! Good Job!')
break
else:
print("Karen made you cry and rethink your career choices. Game Over. You lose")
break

</code></pre>
<p>i looked over the entire code and dont see why this would print</p>
 
Top