-4
私の最初のゲームコードです。もしあなたの誰かが間違いを見つけたら、その修正をコメントしてください。スペースとテキストが無効です。
#Escape the Dungeon
import time
import random #rondom code each game
movesList = 'lookat take use'
inventory = []#Lists Items in inventory
objects = 'vent door bookshelf keypad'#List items in room
gameIsDone = 0
vent = 'closed'
keyPad = 'closed'
code = random.randint(1111,9999)
#Introduction
print('''Welcome to
''')
time.sleep(0.5)
print('ESCAPE THE DUNGEON!')
time.sleep(1)
print('''
If you have NOT played this game before or you
want instructions type "YES". If you don't want instructions
type "NO".
''')
infoA = input("yes or no: ").lower()
#Instructions
def instructions():
print('''
Things in CAPS are inportant.
''')
time.sleep(2)
print('''To interact with obgects you use commands like
"LOOKAT, USE".
''')
time.sleep(3)
print('''After saying what to do to an object you will
be asked to specify the object you wan't to interact with.
An example is "what do you want to 'use'", then you would
input what you want use.
''')
time.sleep(4)
print('''To see what items you already have, use the
command "INVENTORY".
''')
time.sleep(3)
print('''At any time you can use the "HELP" command to
see these instructions again
''')
print('''In this text based game you will need to try
to escape the dungon by interacting with objects.
''')
time.sleep(3)
if infoA.startswith('y'):#If instructions needed at start
instructions()
print('''Warning! Once you enter there you may not be able to
return. Are you sure you want to continue?
''')
if input("yes or no: ").lower().startswith('n'):
print('''
I knew you wern't up to the challenge.
''')
time.sleep(1)
quit()
#Play again?
def playAgain():
print('Do you want to play again?')
return input("yes or no: ").lower().startswith('y')
#Discribe room
time.sleep(2)
print('''
You wake up in a cement room.
''')
time.sleep(2)
print('''You are facing a DOOR. To the top left corner of the
room is a VENT. There is a large BOOKSHELF to the right of you
and the wall behind you is completly blank. On the left wall
with the VENT there is a 4 digit KEYPAD.
''')
#Inputs
while gameIsDone == 0:
if 'brassKey' and 'silverKey' and 'ironKey' in inventory:
gameIsDone = 1
action = input("Enter what you want to do: ").lower()
if action == "help":#Help
instructions()
elif action == "inventory":#Check inventory
if inventory == []:
print('''
You have nothing in your inventory
''')
else:
print('''
These are the items you have in your inventory: '''+ inventory'''
''')
#Interact with onbjects
elif action in movesList:
if action == "lookat" or "look at":
time.sleep(1)
print('What do you want to LOOK AT?')
object = input("Object: ").lower()
if object == "door":#look at door
time.sleep(1)
print('''
The DOOR has three locks,
the first is BRASS, the second is SILVER, and the third is IRON
''')
time.sleep(1)
if 'brassKey' in inventory:
print('You already have the BRASS KEY')
elif 'silverKey' in inventory:
print('You already have the SILVER KEY')
elif 'ironKey' in inventory:
print('You already have the IRON KEY')
else:
print('''You don't have any of the keys yet''')
time.sleep(1)
if object == "vent"#look at vent
time.sleep(1)
if vent == 'closed':
print('The vent is held in by four screws')
if 'screwdriver' in inventory:
time.sleep(1)
print('''Do you wan't to use your SCREWDRIVER on the screws?''')
if input("use or leave: ").lower().startswith('u'):
vent = 'open'
time.sleep(1)
print('Inside you find the SILVER KEY and a NOTE with the code ' + code'.')
inventory.append('silverKey', 'code')
if object == "bookshelf":#look at book shelf
time.sleep(1)
if 'screwdriver' in inventory:
print('The book shelf is completely empty')
else:
print('The book shelf is completely empty besides form a SCREWDRIVER')
time.sleep(1)
print('''
Do you wan't to pick up the SCREWDRIVER?
''')
if input("take or leave: ").lower().starswith('t'):
time.sleep(1)
print('You took the SCREWDRIVER')
inventory.append('screwdriver')
if object == "keypad" or "key pad":#look at book shelf
time.sleep(1)
if keyPad == 'closed':
print('There is a key pad on the wall. It requires a 4 digit code')
time.sleep(1)
if 'code' in inventory:
print('The note you picked up earlyer has the code ' + code'.')
time.sleep(1)
codeTry = input("code input: ")
if codeTry == code:
keyPad = 'open'
time.sleep(1)
print('A hatch opens besides the key pad')
time.sleep(1)
print('Inside you find the BRASS KEY and well as a UV LIGHT')
inventory.append('uvLight, brassKey')
if keyPad == 'open':
print('You have already unlocked the keypad')
if object == "blankwall" or "balnk wall":#look at blank wall
time.sleep(1)
if 'uvLight' in inventory:
print('Do you want to use the uv light on the wall')
time.sleep(1)
if input("yes or no: ").lower.starswith('y'):
time.sleep(1)
print('You see a glowing square on the wall.')
time.sleep(1)
print('You press the button.')
time.sleep(1)
print('A podium arises form the floor with the IRON KEY on top.')
inventory.append('ironKey')
else:
time.sleep(1)
print('''It's a blank wall, what do you expect?''')
else:
print('That is not an object that can be interacted with')
elif action == "use":
time.sleep(1)
print('What do you want to USE?')
item = input("item: ").lower()
if item == "screwdriver":
if 'screwdriver' in inventory:
print('What do you what to use the screwdriver on?')
if input("object: ").lower() == "vent"
if vent == 'closed':
print('The vent is held in by four screws.')
time.sleep(1)
print('You us-screw the screws.')
time.sleep(1)
print('Inside you find the SILVER KEY and a NOTE with the code ' + code'.')
inventory.append('silverKey', 'code')
vent = 'open'
else:
print("You can't do that again.")
else:
print('You dont have that item')
else:
print('That is not an object that can be used.')
else:#if action isn't avalable
time.sleep(1)
print('That action is not in the list of moves (help, use ect.)')
if gameIsDone == 1:
print('You use all three keys on the door')
time.sleep(1)
print('The door slides open to a grassy feild')
time.sleep(1)
print('CONGRATULATIONS')
time.sleep(1)
print ('You have sucessfully escaped')
time.sleep(2)
playAgain()
持ち運びにくいが、単純な愚かなミスかもしれないが、任意の助けが
でなければなりません。 pycharmのような良いエディタをインストールして、悪い構文をマークしてください。 (または単にlinterを使う) – MacHala