首页 > 解决方案 > IT140 项目。在基于 Dragon 文本的游戏的房间中移动

问题描述

我对编码很陌生,而且我很难弄清楚。接听在线电话对我来说不是一件很聪明的事情。话虽如此,我昨天有一个项目,要求我在收集物品时从一个房间移动到另一个房间。这是我到目前为止所拥有的。我的老师告诉我使用 while 语句,但我在使用时遇到问题。

import time

delay = 0.5

def intro():
    print('Welcome President Trump!')
    print('Please proceed through the Capital Building so you can pass your Border Wall Bill. ')

print('In this story you are playing the role of President Trump.')
time.sleep(delay)
print('You must guide President Trump through the rooms of the U.S. Capital Building.')
time.sleep(delay)
print('In your travels through the Capital Building, you must collect items to help defeat the evil Nancy Pelosi!')
time.sleep(delay)
print('Nancy Pelosi is here to stop you from passing any bill she does not like!')
time.sleep(delay)
print('You must find Items to stop her evil reign on the House of Representatives.')
time.sleep(delay)
print('These items are:')
time.sleep(delay)
print('The Mighty Pen')
time.sleep(delay)
print('The Council of Rudy Giuliani')
time.sleep(delay)
print('Hair gel')
time.sleep(delay)
print('A Twitter Account')
time.sleep(delay)
print('every member of the Republican seats in the House of Representatives')
time.sleep(delay)
print('and The Fox News Channel.')
time.sleep(delay)
print('You will have to navigate through eight rooms to collect the items needed to defeat the Evil Nancy Pelosi.')
time.sleep(delay)
print('These rooms are:')
time.sleep(delay)
print('The Capitol Plaza, this is the starting point.')
time.sleep(delay)
print('The Great Rotunda, The Fox News Reporters are there to boost your story to the American People.')
time.sleep(delay)
print('The Senate Chambers, where you will collect the members of the Republican Seats.')
time.sleep(delay)
print('The President’s Room, where you will find your hair gel to fix your comb over.')
time.sleep(delay)
print('The basement, where Rudy Giuliani is waiting for your praise.')
time.sleep(delay)
print('The Library of Congress, where you will find your Twitter Account.')
time.sleep(delay)
print('The Hallway, where you will find the mighty pen.')
time.sleep(delay)
print('Then you will travel to The House Chambers, where the evil Nancy Pelosi sleeps in here nest.')
time.sleep(delay)
print('Be aware to not enter this room without all your items, for Nancy will destroy you without your support!')

new_game = input('Do you want to play a game? (Yes or No): ')

if new_game == 'n' or new_game == 'N':
    print('Have a good day!')
elif new_game == 'y' or new_game == 'Y':
    intro()

direction = input('Please choose a direction: (North, South, East, West):')


def room1():
    print('You are in the Capitol Plaza:')
    print('To the North is the Great Rotunda.')
    print('To the East is the basement.')
    print('To the West is a wall')
    print('To the South is a wall.')

def room2():
    print('You are in the basement:')
    print('To the North is a wall')
    print('To the East is a wall.')
    print('To the South is a Wall.')
    print('To the West is the Capital Plaza.')

#if direction == 'North':
#    print('You can not go that way!')
#elif direction == 'South':
#    print('You can not go that way!')
#elif direction == 'East':
#    print('You can not go that way!')
#elif direction == 'West':
#    print('You are now in the Capital Plaza.')

def room3():
    print('You are in the Hallway:')
    print('To the North is the Senate Chambers')
    print('To the East is a Wall.')
    print('To the South a wall.')
    print('To the West is the Great Rotunda.')

#if direction == 'North':
#    print('You are now in the Senate Chambers!')
#elif direction == 'South':
#    print('You can not go that way!')
#elif direction == 'East':
#    print('You can not go that way!')
#elif direction == 'West':
    print('You are now in The Great Rotunda')

def room4():
    print('You are in the Senate Chambers:')
    print('To the North is a wall')
    print('To the East is a wall.')
    print('To the South is the Hallway.')
    print('To the West is a window looking at The Great Rotunda.')

#if direction == 'North':
#    print('You can not go that way!')
#elif direction == 'South':
#    print('You are now in the Hallway!')
#elif direction == 'East':
#    print('You can not go that way!')
#elif direction == 'West':
#    print('You Gasp at the beauty of the Great Rotunda. You can not go that way!')

def room5():
    print('You are in the Great Rotunda:')
    print('To the North is the Library of Congress')
    print('To the East is the hallway.')
    print('To the South is the Capital Plaza.')
    print('To the West is the Presidents Room.')

#if direction == 'North':
#    print('You are now in the Library of Congress!')
#elif direction == 'South':
#    print('You are now in the Capital Plaza!')
#elif direction == 'East':
#    print('You are now in the Hallway!')
#elif direction == 'West':
#    print('You are now in the Presidents Room!')

def room6():
    print('You are in the Presidents Room:')
    print('To the North is a wall')
    print('To the East is the Great Rotunda.')
    print('To the South is a wall.')
    print('To the West is a window over looking all the protesters.')

#if direction == 'North':
#    print('You can not go that way!')
#elif direction == 'South':
#    print('You can not go that way!')
#elif direction == 'East':
#    print('You are now in the Great Rotunda!')
#elif direction == 'West':
#    print('You are looking at all the haters outside!')

def room7():
    print('You are in the Library of Congress:')
    print('To the North is a wall')
    print('To the East is the House Chambers.')
    print('To the South is the Great Rotunda.')
    print('To the West is a wall.')

#if direction == 'North':
#    print('You can not go that way!')
#elif direction == 'South':
#    print('You are now in the Great Rotunda!')
#elif direction == 'East':
#    print('You are now in the House Chambers!')
#elif direction == 'West':
#    print('You can not go that way!.')

def room8():
    print('You are in the House Chambers:')
    print('The evil Nancy blew fire out of her mouth and burned you down to ashes!')


room1 = input('You are in the Capital Plaza: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    room5()
    print('You are now in the Great Rotunda!')
elif direction == 'South':
    print('Wrong Way')
elif direction == 'East':
    room2()
    print('You are now in the basement!')

room2 = input('You are in the Basement: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    print('You can not go that way!')
elif direction == 'South':
    print('You can not go that way!')
elif direction == 'East':
    print('You can not go that way!')
elif direction == 'West':
    room1()
    print('You are in the Capital Plaza!')

room3 = input('You are in the Hallway: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    room4()
    print('You are now in the Senate Chambers!')
elif direction == 'South':
    room3()
    print('You are now in the Hallway!')
elif direction == 'East':
    print('You can not go that way!')
elif direction == 'West':
    room5()
    print('You are now in the Great Rotunda!')

room4 = input('You are in the Senate Chambers: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    print('You can not go that way!')
elif direction == 'South':
    room3()
    print('You are in the Hallway!')
elif direction == 'East':
    print('You can not go that way!')
elif direction == 'West':
    print('You can not go that way!')

room5 = input('You are in the Great Rotunda: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    room7()
    print('You are now in the Library of Congress!')
elif direction == 'South':
    room1()
    print('You are now in the Capital Plaza!')
elif direction == 'East':
    room3()
    print('You are now in the Hallway!')
elif direction == 'West':
    room6()
    print('You are now in the Presidents Room!')

room6 = input('You are in the Presidents Room: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    print('You can not go that way!')
elif direction == 'South':
    print('You can not go that way!')
elif direction == 'East':
    room5()
    print('You are now in the Great Rotunda!')
elif direction == 'West':
    print('You can not go that way!')


room7 = input('You are in the Library of Congress: What direction do you want to go? (North, East, South, West): ')

if direction == 'North':
    print('You can not go that way!')
elif direction == 'South':
    room5()
    print('You are now in the Great Rotunda!')
elif direction == 'East':
    room8()
    print('You are now in the House Chambers!')
elif direction == 'West':
    print('You can not go that way!')


room8 = input()
print('End')


#if direction == 'North':
#    print()
#    room1()
#elif direction == 'South':
#    print('Wrong Way')
#elif direction == 'East':
#    print()
#    room3()

标签: pythonpython-3.xxcodeif-statementwhile-loop

解决方案


推荐阅读