为什么我的键绑定没有响应?



我正在为我编写的游戏调制代码。当我调整播放器类时,我添加了所有额外的参数/自变量,以便可以将其分离。我在主游戏模块中保留了密钥绑定。

密钥绑定代码看起来像这个


turtle.listen()
a=turtle.onkey(player.go_left(walls), "Left")
b=turtle.onkey(player.go_right(walls), "Right")
c=turtle.onkey(player.go_up(walls), "Up")
d=turtle.onkey(player.go_down(walls), "Down")
e=turtle.onkey(player.headright(missile,lives), "d")
f=turtle.onkey(player.headleft(missile,lives), "a")
g=turtle.onkey(player.headdown(missile,lives),"s")
h=turtle.onkey(player.headup(missile,lives),"w")
i=turtle.onkey(player.headright(missile,lives),"D")
j=turtle.onkey(player.headleft(missile,lives), "A")
k=turtle.onkey(player.headdown(missile,lives),"S")
l=turtle.onkey(player.headup(missile,lives),"W")
o=turtle.onkey(player.drink(info),"space")
m=turtle.onkey(player.fireball(missile2,info,lives),"z")
n=turtle.onkey(player.fireball(missile2,info,lives),"Z")

游戏运行时没有出现错误,但按键对操作没有响应。

你可以在中找到代码

https://github.com/Ninedeadeyes/7-Dungeons-Deep/tree/master

密钥绑定代码在游戏中(mod版本(

所有功能都在"player.py"中

任何帮助都会很棒。

onkey函数只允许一个没有参数的函数,因此不可能使用有参数的函数——因此它不起作用。

https://docs.python.org/2/library/turtle.html#turtle.onkey

但是。。。如果您使用

turtle.onkey((lambda:player.go_left(walls((,";左"(

它将起作用,因为您正在函数中创建一个函数,该函数将像没有参数一样表达输出。

最新更新