我收到错误' TypeError:spec()接受1个位置参数但是2个被给出'错误行以粗体显示。只有一个论点。我是python的初学者,不知道该怎么做。请帮忙。
import random as r
from random import randint
import time as t
class Player():
def __init__(self):
self.health=300
self.dammin=30
self.dammax=55
class Enemy(object):
def __init__(self):
self.health=0
self.dammin=0
self.dammax=0
class Goblin(Enemy):
def __init__(self):
self.health=25
self.dammin=5
self.dammax=20
def spec(endam):
perc=r.randint(0,100)
if perc>0:
endam=9001
msg=("The goblin uses pickpocket and puts a grenade in your pocket")
else:
msg=("The goblin's special fails")
print(msg)
class Orc(Enemy):
def __init__(self):
self.health=50
self.dammin=20
self.dammax=50
def spec(endam):
perc=r.randint(0,100)
if perc>0:
endam*=2
msg=("Orc uses double hit")
else:
msg=("The orc's special fails")
print(msg)
class Beast(Enemy):
def __init__(self):
self.health=75
self.dammin=30
self.dammax=60
def spec(endam):
print("Beast howls at the moon, for some reason. It has no effect")
en=Enemy()
go=Goblin()
orc=Orc()
be=Beast()
pl=Player()
def start():
items={
"small healing potion":4,
"large healing potion":2,
}
effects={"Begginers Luck":2,}
print("Welcome traveler!")
t.sleep(0.5)
print("lets fight!")
t.sleep(1.5)
print
counter=0
print(""*3)
fight(counter,pl.health,items,effects)
Enemy=[go,orc,be]
EnemyName={go:"Goblin",orc:"Orc",be:"Beast"}
actions=["attack","item","run"]
def fight(counter1,plhealth,items,effects):
en=r.choice(Enemy)
curEnemy=EnemyName[en]
msg="An evil %s appeared" % (curEnemy)
print(msg)
enhealth=en.health
while enhealth>0:
print("")
endam=randint(en.dammin,en.dammax)
t.sleep(0.5)
**en.spec(endam)**
if effects["Begginers Luck"] > 0:
endam-=10
print("Begginers Luck. Enemies deal ten less damage.")
msg="The enemy deals %s damage" % (endam)
print(msg)
plhealth-=endam
if plhealth<=0:
death(counter1)
hud(plhealth,enhealth)
action=str(input(": "))
while action not in actions:
msg=("I dont know what %s is") % (action)
print(msg)
action=str(input(": "))
t.sleep(0.5)
if action == "attack":
dam=randint(pl.dammin,pl.dammax)
msg="You deal %s damage" % (dam)
print(msg)
enhealth -= dam
if enhealth<0:
enhealth = 0
elif action == "item":
if all in items == 0:
print("No items left")
else:
itempage(plhealth,enhealth)
item=str(input(": "))
while item not in items:
msg="%s is not an item"%(item)
print(msg)
item=str(input(": "))
while items[item]==0:
msg="You have no %ss left"%(item)
print(msg)
itempage(plhealth,enhealth)
item=str(input(": "))
else:
if item =="small healing potion":
heal=randint(25,50)
oldhealth=plhealth
plhealth+=heal
if plhealth > 300:
plhealth = 300
heal=300-oldhealth
msg="Potion heals you %s" % (str(heal))
print(msg)
elif item =="large healing potion":
heal=randint(75,150)
oldhealth=plhealth
plhealth+=heal
if plhealth > 300:
plhealth = 300
heal=300-oldhealth
msg="Potion heals you %s" % (str(heal))
print(msg)
items[item]-=1
elif action == "run":
print("Don't be such a wimp")
for effect in effects:
effects[effect]-=1
t.sleep(0.5)
msg="The %s is dead" % (curEnemy)
print(msg)
counter1+=1
t.sleep(1)
print("")
fight(counter1,plhealth,items,effects)
def itempage(health,enemyhealth):
line0="______________________________________________________"
if enemyhealth < 10:
line1="| Health %s Enemy Health %s |"%(health,enemyhealth)
else:
line1="| Health %s Enemy Health %s |" % (health,enemyhealth)
line2="| |"
line3="| -small healing potion- -large healing potion- |"
line4="| |"
line5="| -Return- |"
line6="|____________________________________________________|"
lineList=[line0, line1, line2, line3, line4, line5, line6]
for line in lineList:
print(line)
def death(counter2):
print(""*2)
print("You are dead")
if counter2==1:
print("You killed 1 monster")
else:
msg="You killed %s monsters" % (counter2)
print(msg)
t.sleep(3)
print("\n"*5)
start()
def hud(health,enemyhealth):
line0=(" ______________________________")
if enemyhealth < 10:
line1=("| Health %s Enemy Health %s |") % (health,enemyhealth)
else:
line1=("| Health %s Enemy Health %s |") % (health,enemyhealth)
line2=("| |")
line3=("| -Attack- -Item- |")
line4=("| |")
line5=("| -Run- |")
line6=("|_____________________________|")
lineList=[line0, line1, line2, line3, line4, line5, line6]
for line in lineList:
print(line)
start()