gpt4 book ai didi

java - 使用 isShiftDown() 两次

转载 作者:行者123 更新时间:2023-12-01 10:45:01 25 4
gpt4 key购买 nike

我正在开发一个小游戏,我需要使用 isShiftDown 两次,第一次当他使用 Shift+click 时,一个框变成绿色,当他第二次在同一个框上 Shift+click 时,她会改变颜色,变成红色。这就是我所做的,但它不起作用,事实上,我第一次 Shift+单击一个框时,她变成绿色((字节)6),但我不知道如何第二次 Shift+单击。

boolean count = false;
public synchronized void mouseClicked(MouseEvent e) {
synchronized (gameModel) {
int width = getGameX(e) ;
int height = getGameY(e) ;
if (e.isShiftDown() && count == false){
gameModel.set(width, height, (byte)6);
count = true;
}
if (e.isShiftDown() && count == true){}
else {
byte c = (byte)1 ;
gameModel.set(width,height,c);
}
notify(gameModel) ;
}

最佳答案

您的第一个 if block 将 count 设置为 true。您的第二个 if block 检查 count 是否为 true(这肯定是,因为您刚刚将其设置为 true),因此 else block 永远不会触发。

也许你的意思更像是这样的:

if (e.isShiftDown() && !count){
gameModel.set(width, height, (byte) 6);
count = true;
} else if (e.isShiftDown()) {
byte c = (byte) 1;
gameModel.set(width,height,c);
}

关于java - 使用 isShiftDown() 两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34232411/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com