I am currently trying to develop a snake game with two different snakes in the same game, in order to play with two people. I am using code that I found on the internet, and it worked. However when I decide to add a second snake, to be controlled with WASD and the first one to be controlled by the arrow keys only the first snake will move...
我目前正在尝试在同一场比赛中用两条不同的蛇开发蛇形游戏,以便与两个人一起玩。我正在使用我在互联网上找到的代码,并且它有效。然而,当我决定添加第二条蛇时,用WASD控制,第一条蛇用箭头键控制,只有第一条蛇会移动......
I have put a link below to the repl page with all my code
我在下面的链接中添加了一个包含我所有代码的链接
https://repl.it/@AmirGareev/Snake
https://repl.it/@AmirGareev/Snake
1 个解决方案
#1
0
Only methods keyPressed
, keyReleased
and keyTyped
will receive key events. Methods keyPressed1
and keyReleased1
will not receive any events as they are not part of the KeyListener
interface.
只有keyPressed,keyReleased和keyTyped方法才会收到关键事件。方法keyPressed1和keyReleased1不会接收任何事件,因为它们不是KeyListener接口的一部分。
You must handle the keys for both snakes in keyPressed
, keyRelease
and keyTyped
only.
您必须仅在keyPressed,keyRelease和keyTyped中处理两个蛇的键。
#1
0
Only methods keyPressed
, keyReleased
and keyTyped
will receive key events. Methods keyPressed1
and keyReleased1
will not receive any events as they are not part of the KeyListener
interface.
只有keyPressed,keyReleased和keyTyped方法才会收到关键事件。方法keyPressed1和keyReleased1不会接收任何事件,因为它们不是KeyListener接口的一部分。
You must handle the keys for both snakes in keyPressed
, keyRelease
and keyTyped
only.
您必须仅在keyPressed,keyRelease和keyTyped中处理两个蛇的键。