【发布时间】:2018-05-05 15:39:34
【问题描述】:
我刚开始和朋友一起制作 RPG。我们希望能够使用箭头键或 WASD 来移动角色。我不知道该怎么做,我一直在网上找了一会儿。我知道我必须使用 ActionListener,但除此之外,我不知道我在用它做什么。这是使用键盘输入的代码部分,但我不知道该怎么做
public class Character implements ActionListener
{
public static char KBoard(char w, char a, char s, char d)
{
/_\-|(This is what I need help with, reading in the keyboard input)|-/_\
return kBoard;
}
public static int MoveX (int velocity)
{
velocity = 5
Switch (kBoard)
case 'w':
characterPosX -= velocity;
break;
case 's':
characterPosX += velocity;
break;
return characterPosY;
}
public static int MoveY (int velocity)
{
velocity = 5
Switch (kBoard)
case 'a':
characterPosY -= velocity;
break;
case 'd':
characterPosY += velocity;
break;
return characterPosY;
}
public void Character ()
{
(code to make the character appear)
}
}
【问题讨论】:
-
All-left 格式不好,请缩进代码 - 整理 switch 语句使其可行,返回什么以及 characterPosY 在哪里?
-
所以,characterPosY 返回按下 'd' 或 'a' 按钮后角色的新 Y 位置,并将其返回给方法 Character,改变 Y位置。与 characterPosY 相同。我马上就会开始格式化。
标签: java input bluej direction