python编程复杂文字游戏的代码(无注释)
import random
import time
def print_pause(message_to_print):
print(message_to_print)
time.sleep(2)
def intro():
print_pause("You find yourself standing in an open field, filled with grass and yellow wildflowers.")
print_pause("Rumor has it that a dragon is somewhere around here, and has been terrifying the nearby village.") # 打印游戏剧情介绍,让玩家了解游戏背景。
# 创建一个函数来处理用户的选择:
def play(): # 开始函数play()
response = input("Would you like to (1) fight or (2) run away?\n") # 询问用户要选择哪个动作?
if response == '1': # 用户选择了打斗
fight() # 调用fight()函数,开始打斗
elif response == '2': # 用户选择了逃跑
runaway() # 调用runaway()函数,开始逃跑
else: # 如果用户输入的不是1也不是2,就重复询问他要干什么。
play() # 重复询问直到正确的动作输入。
# 创建一个fight函数来处理打斗场景:
def fight(): # 函数fight()开始
print_pause("As you approach the dragon, you see that he has two heads.\n")
print_pause("He stares at you with his red eyes and then opens his jaws to roar!\n")
print_pause("You feel a bit scared but bravely ready your sword for the battle.\n")
dragon = random.choice(['head', 'tail']) # 随机生成dragon变量的值为head 或者 tail
if dragon == "head": # 如果dragon变量的值是head
print_pause("You quickly slice off one of its heads! \n")
print_pause("The dragon falls down dead on the ground. \n")
victory() # 进入victory场景
elif dragon == "tail": # 如果dragon变量的值是tail
print
创作工场
免责声明:
以上内容除特别注明外均来源于网友提问,创作工场回答,未经许可,严谨转载。
点击这里>>使用🔥专业版,更聪明、更完整、更原创!