所以我目前正在为一个学校项目做一个战斗模拟,在这个项目中,两辆坦克将互相战斗。
每辆坦克都有可能拥有多个枪械。
所以我做了一个让用户创建枪支的方法,但是我想确保每次调用这个方法时,生成的列表都会得到保存在gunListName
变量中的名称。有没有办法因为我不知道该怎么做。在
我说的方法是:
def createguns(self,):
gunList = []
gunListName = input("please input the name of the tank that will use these guns: ")
gunNumber = input("how many guns do you wish to give your tank? ")
for x in range(int(gunNumber)):
gunName = input("please input the name of your gun: ")
gunRange = input("please input the range of your gun in Meters(example: 1000 CM would be 1KM range): ")
gunMinRange = input("please input the minimum range of your gun: ")
gunDamage = input("please input the damage value of your tank: ")
gunReload = input("please input the reload time of your gun")
gunName = Gun(gunName,gunRange,gunMinRange,gunDamage,gunReload)
gunList.append(gunName)
return gunList
像这样做
相关问题 更多 >
编程相关推荐