【发布时间】:2014-10-25 08:26:36
【问题描述】:
我想制作一个基于文本的格斗游戏,但为了做到这一点,我需要使用几个函数并传递诸如伤害、武器和生命值之类的值。
请允许此代码能够在我的代码中传递“武器”“伤害”“p1 n p2”。如您所见,我尝试使用 p1 n p2 的参数,但我有点新手。
import random
def main():
print("Welcome to fight club!\nYou will be fighting next!\nMake sure you have two people ready to play!")
p1=input("\nEnter player 1's name ")
p2=input("Enter player 2's name ")
print("Time to get your weapons for round one!\n")
round1(p1,p2)
def randomweapons(p1,p2):
weapon=["Stick","Baseball bat","Golf club","Cricket bat","Knife",]
p1weapon=random.choice(weapon)
p2weapon=random.choice(weapon)
print(p1 +" has found a "+p1weapon)
print(p2 +" has found a "+p2weapon)
def randomdamage():
damage=["17","13","10","18","15"]
p1damage=random.choice(damage)
p2damage=random.choice(damage)
def round1(p1,p2):
randomweapons(p1,p2)
def round2():
pass
def round3():
pass
def weaponlocation():
pass
main()
【问题讨论】:
-
你有什么问题?您预期的输入/输出是什么?此外,你的格式都搞砸了。该程序不会运行。
标签: python variables parameters python-idle