I'm trying to incorporate my random items into my code so that it can run. I will place list below the code. This is my code:
import time
import textwrap
import words
import random
def print_pause(message_to_print, sleep_time):
change delay time according to sleep_time
print(message_to_print)
time.sleep(sleep_time)
def intro(item):
intro of the game
msg = textwrap.dedent('''
================================
-
Welcome to Panic Adventure! *
================================
''')
print_pause(msg, 2)
print_pause("You find yourself driving down a long road to a " + item[3] +
",that is near a " + item[4] + ".", 2)
print_pause("You have heard on the radio that a " + item[0] +
" is near here, and has been "
"frightening the people nearby.", 2)
print_pause("As you come closer to the house.", 2)
print_pause("There is a big storage shed to the left.", 2)
print_pause("In your pocket, you have a (not very helpful) " + item[1] +
".", 3)
def clear():
Gives the screen a clean look
print("\n"*100)
def scene_theme(item):
Generates random monster, weapons, place and a scenario for the game
scene = [words.monster, words.weapon1, words.weapon2,
words.place, words.scene]
for list in scene:
item.append(random.choice(list))
item[0] is monster
item[1] is small weapon
item[2] is final weapon
item[3] is the type of place
item[4] is the scenery of the place
return item
def house(item):
House activity
print_pause("You have arrived at the door of the house.", 2)
print_pause("Before knocking, the door creeks open and there's a " +
item[0] + ".", 2)
print_pause("......", 3)
print_pause("Oh no! It is the house of the " + item[0] + "'s!", 2)
print_pause("The " + item[0] + " begins attack!", 2)
if '1' not in item:
user hasn't got the final weapon
print_pause("You cannot handle it with only having a " + item[1] +
".", 3)
option = ''
while option != '1' or option != '2':
option = input("Would you like to (1) fight or (2) run away?\n")
if option == '1':
if '1' in item:
user has the final weapon
print_pause("The " + item[0] +
" starts to attack, you have taken out the " +
item[2], 2)
print_pause("The " + item[2] +
" is really powerful,"
"as you make ready to attack.", 3)
print_pause("But the " + item[0] +
" look at your powerful weapon "
"and runs off!", 2)
print_pause("You have scared it out of town. "
"You won!", 2)
game_finish()
else:
print_pause("You begin fighting back....", 2)
print_pause("....", 3)
if random.randint(1, 10) % 2 != 0:
random set of events
without final weapon
print_pause("The " + item[1] +
" is not helpful " + item[0] + ".", 2)
print_pause("You lost!", 2)
game_finish()
break
else:
print_pause("You have wounded the " + item[0] +
"'s arm with the help of your " + item[1] +
".", 2)
print_pause("You almost made it back to the car safely.",
2)
choice(item)
elif option == "2":
print_pause("You run back to your where it is safe. "
"No signs of you being followed.", 3)
choice(item)
def shed(item):
print_pause("You walk towards the shed.", 2)
if '1' in item:
Came into the shed before
print_pause("You have been here already and taken everything. "
"This shed is empty.", 1)
else:
walks into the shed the first time
print_pause("You look around and something caught you eye.", 2)
print_pause("You saw a silver " + item[2] + "!", 2)
print_pause("You threw away your " + item[1] +
" and grab the " + item[2] + " with you.", 2)
item.append('1')
print_pause("You walk towards the " + item[3] + ".", 2)
choice(item)
def choice(item):
print_pause("Enter 1 to knock on the door of the house.", 1)
print_pause("Enter 2 to walk into the shed.", 1)
area = input("What is your decision?\n(please enter 1 or 2.)\n")
if area == '1':
house(item)
elif area == '2':
shed(item)
else:
if the user puts in anything except
1 or 2 the function keeps repeating itself
choice(item)
def game_finish():
print_pause("Game Over!", 1)
play_again = input("Would you like to play again? (y/n)\n").lower()
if play_again == 'y':
play_game()
elif play_again == 'n':
print_pause("Thanks for playing! Goodbye!", 5)
else:
game_finish()
def play_game():
item = []
clear()
scene_theme(item)
intro(item)
choice(item)
play_game()
This is the list of items:
monster = ['zombie', 'bear', 'elf', 'dragon',
'prisoner']
weapon1 = ['dagger', 'rock', 'hand gun', 'pocket knife']
weapon2 = ['longsword', 'mjolnir', 'rifle', 'machete axe']
scene = ['cabin', 'beach house',
'manison']
place = ['forest', 'beach', 'city', 'woods']
https://stackoverflow.com/questions/65911525/how-can-i-fit-my-random-choice-into-my-code January 27, 2021 at 09:07AM
没有评论:
发表评论