我正在创建一个回合为一个小游戏战斗系统,我收到了错误
TypeError: object of type 'type' has no len()
在线:
AImove = random.choice(AImove)
作为参考,AImove
变量的设置如下:
我试图在代码中添加AImove = int
和AImove = str
,但我要么收到与之前相同的错误,要么是{
使用AImove
的函数如下所示,如有任何反馈,将不胜感激。在
def combat(health, turn, loop, gold, AImove):
enemy_health = (random.choice(random_enemy_Health))
enemy_attack = (random.choice(random_enemy_Attack))
print("\nYou are fighting a" ,random.choice(enemies), "with an attack amount of" ,enemy_attack, "and a health amount of" ,enemy_health,".")
while health > 0 and enemy_health > 0:
if turn == 1:
while loop == False:
print("\nDo you want to attack or flee? Type '1' to attack and '2' to flee.")
response=input()
if response == "1":
enemy_health = enemy_health - attack
print("You attacked!")
loop = True
elif response == "2":
hub_travel()
print ("You fled the battle, come back once you are stronger!")
loop = True
else:
print ("Invalid number, try again")
continue
turn = 2
if turn == 2:
AImove = random.choice(AImove)
if AImove == 1:
print ("Enemy attacked!")
health = health - enemy_attack
if AImove == 2:
print("Enemy missed!")
turn = 1
continue
您立即将},在下一次迭代中,您尝试
AImove
替换为random.choice
的结果,然后它要么是1
,要么是{random.choice(1)
(或2
),这解释了您所看到的异常。在您只需在此处使用另一个变量名:
相关问题 更多 >
编程相关推荐