基于文本的冒险游戏-使用Python

时间:2019-07-07 18:43:57

标签: python-3.x

我是整个编程领域的新手,并且我正在开发冒险游戏代码,这是学习代码之旅的一部分。作为审查的一部分,我被要求将playAgain更改为一个函数。这是我一直坚持的部分,希望对您有所帮助。如何将以下部分更改为函数并使代码运行?

playAgain = "yes"
while playAgain == "yes" or playAgain == "y":
displayIntro()
choice = choosePath()
checkPath(choice) # choice is equal to "1" or "2"
playAgain = input("Do you want to play again? (yes or y to continue 
playing): ")

谢谢您的帮助。

import random
import time

def displayIntro():
     print("It is the end of a long year of battling space criminals 
 in a galaxy far far away!")
 print("you come to crossroads on your trip home, one path leads 
 home")
print("where you will be handsomely rewarded for a job well done")
print("and the other leads through an infinite loop that will send 
you into time continuum")
print()

def choosePath():
    path = ""
 while path != "1" and path != "2": # input validation
    path = input("Which path will you choose? (1 or 2): ")

return path

def checkPath(chosenPath):
print("You head down the path")
time.sleep(2)
print("there's an planet nearby that looks familiar, that must be a 
good sign...")
time.sleep(2)
print("But your radar picks up some transmission...")
print()
time.sleep(2)

   correctPath = random.randint(1, 2)

    if chosenPath == str(correctPath):
    print("That transmission was from the comms of your planets 
   defence network!")
    print("Welcome home!")
     else:
    print("An extremely powerful singularity loop draws you into 
    it")
    print("causing all of the ondoard comuputers to fail")
    print("and your are sent into the continuum.")


   playAgain = "yes"
   while playAgain == "yes" or playAgain == "y":
  displayIntro()
  choice = choosePath()
  checkPath(choice) # choice is equal to "1" or "2"
  playAgain = input("Do you want to play again? (yes or y to 
  continue playing): ")

0 个答案:

没有答案