我无法弄清楚为什么我会收到此错误:
Traceback (most recent call last):
File "C:/Users/tyler/Desktop/PycharmProjects/Arcade Game/AttackDirectory.py", line 63, in <module>
ThiefPdmg = randint(lambda x: (round(x*0.75)), lambda x: (round(x*1.00)))(Thief['stats']['Attack'])
File "C:\Python27\lib\random.py", line 242, in randint
return self.randrange(a, b+1)
TypeError: unsupported operand type(s) for +: 'function' and 'int'
我还在学习python,我正在为游戏制作战斗系统。我确信代码是粗糙的,所以如果你有任何办法让它变得不那么粗糙并且可能更好地工作,我愿意接受建议。
import random
import pygame
from random import randint
pygame.init()
Thief = {'name' : 'Thief',
'Class' : 'Player',
'Sub-Class' : 'Thief',
'lvl' : 1,
'xp' : 0,
'lvlNext' : 25,
'Weak' : {'Lightning'},
'Normal' : {'Shock'
'Burn'
'Water'
'Freeze'},
'Resistance' : {'Ice'
'Fire'},
'Null' : {'Poison'},
'stats': {'Attack' : 6,
'Magic' : 6,
'Speed' : 5,
'HP' : 20,
'MP' : 40}}
def ThiefLevelUp():
while Thief['lvl'] < 50 and Thief['xp'] >= Thief['lvlNext'] :
Thief['lvl']+= 1
xp = Thief['xp'] - Thief['lvlNext']
lvlNext = round(Thief['lvlNext'] * 1.5)
Thief['stats']['HP'] = Thief['stats']['HP'] + round(Thief['stats']['HP'] * .25)
print("Level Up!")
print('Level:', Thief['lvl'])
if Thief['xp'] < Thief['lvlNext']:
print('XP Needed:', Thief['xpNeeded'])
print('Exp:', Thief['xp'])
print('Strength:', Thief['stats']['PStrength'])
print('Prosperity:', Thief['stats']['PProsperity'])
print('Dexterity:', Thief['stats']['PDexterity'])
print('Vitality:', Thief['stats']['PVitality'])
print('Agility:', Thief['stats'][''])
Imp = {'name' : 'Imp',
'Class' : 'Enemy',
'lvl' : 1,
'xp' : 0,
'lvlNext' : 25,
'Weak' : {'Lightning'},
'Normal' : {'Fire',
'Ice',
'Poison',
'Freeze',
'Burn'},
'Resistance' : {},
'Null' : {},
'stats' : {'Attack' : 8,
'Speed' : 5,
'HP' : 25,
'MP' : 40}}
ThiefPdmg = randint(lambda x: (round(x*0.75)), lambda x: (round(x*1.00)))(Thief['stats']['Attack'])
ThiefMdmg = randint(lambda x: (round(x*0.75)), lambda x: (round(x*1.00)))(Thief['stats']['Magic'])
ThiefHP = Thief['stats']['HP']
ImpDMG = randint(lambda x: (round(x*0.75 / Thief['lvl'] + 1, lambda x: (round(x*0.75 / Thief['lvl'] + 1)) )))(Imp['stats']['Attack'])
ImpHP = Imp['stats']['HP']
def AtkMiss():
if random.random > .25:
Attack()
else:
print("You Missed!")
if random.random > .25:
ThiefHP - ImpDMG
ThiefHP = Thief['stats']['HP'] - ImpDMG
def Attack():
AttackerDMG = ThiefPdmg
print('You Attacked!')
if Thief['stats']['Speed'] >= Imp['stats']['Speed']:
ImpHP - ThiefPdmg
ImpHP = Imp['stats']['HP'] - ThiefPdmg
if random.random > .25:
ThiefHP - ImpDMG
ThiefHP = Thief['stats']['HP'] - ImpDMG
if Imp['stats']['Speed'] > Thief['stats']['Speed'] :
ThiefHP - ImpDMG
print('Thief Took {} Damage!'.format(ImpDMG))
if random.random > .25:
ImpHP - ThiefPdmg
print('Imp Took {} Damage!'.format(ThiefPdmg))
else:
print('The Attack Missed!')
if ImpHP <= 0:
print('{} Was Killed!'.format(Imp['name']))
if ThiefHP <= 0:
print('You Were Killed!')
def command():
cmd = raw_input('What Will You Do?')
if 'Atk' in cmd:
AtkMiss()
else:
Pass
def Battle():
Attackerhp = Thief['stats']['HP']
Defenderhp = Imp['stats']['HP']
print('An imp appeared!')
print(' ')
while Defenderhp and Attackerhp > 0:
command()
print('Your Health: {}'.format(ThiefHP))
print('Enemies Health: {}'.format(ImpHP))
if Defenderhp <= Defenderhp:
print('Took {} Damage!'.format(Enemy['name'], Dmg or Mdmg))
错误来自哪里?
答案 0 :(得分:0)
UITableView
[1]函数期望将UILabel
个数作为其参数传递。相反,您传递的lambda函数似乎是不必要的。例如,只需执行randint
,而不是int
。只使用lambda,其中某些东西需要传递给randint(lambda x: round(x*0.25), lambda x: round(x*0.75))
,就像回调一样。