java中如何把true改为false_java – 如何在其他所有内容之前将变量从True变为False?...

我有一个我需要的项目

>创建贴纸.

>点击它后贴纸会发出声音.

>让下一次点击复制并放置贴纸. (必须能够按照我想要的次数放置,而不必返回并再次单击原始贴纸.)

>能够点击另一个贴纸并选择要放置的贴纸.

在我的代码中,我的所有贴纸变量都是假的.一旦达到合适的条件,1个贴纸变量将成立,我将能够贴上贴纸.但是当我点击第二个贴纸时,第一个贴纸仍然是真的,并在第二个贴纸上贴了一个贴纸.我不希望这样.当我在第二个贴纸上释放鼠标左键时,如何将贴纸变量更改为false.我的代码使它在之后将其更改为false.我以前想要.请帮忙.谢谢.

boolean hatSoundPlay = false;

boolean bluntSoundPlay = false;

boolean dealwithitSoundPlay = false;

boolean weedSoundPlay = false;

while(true) {

int clickX = EZInteraction.getXMouse();

int clickY = EZInteraction.getYMouse();

if (EZInteraction.wasMouseLeftButtonReleased()){

if (hatPicture.isPointInElement(clickX, clickY)){

bluntSoundPlay = false;

weedSoundPlay = false;

dealwithitSoundPlay = false;

if (!hatSoundPlay) {

hatsound.play();

hatSoundPlay = true;

}

}

else if (backgroundPicture.isPointInElement(clickX, clickY) && hatSoundPlay == true && EZInteraction.wasMouseLeftButtonReleased()){

EZ.addImage("hat.png", clickX, clickY);

hatsound.play();

}

if (bluntPicture.isPointInElement(clickX, clickY)){

hatSoundPlay = false;

weedSoundPlay = false;

dealwithitSoundPlay = false;

if (!bluntSoundPlay) {

bluntsound.play();

bluntSoundPlay = true;

}

}

else if (backgroundPicture.isPointInElement(clickX, clickY) && bluntSoundPlay == true && EZInteraction.wasMouseLeftButtonReleased()){

EZ.addImage("blunt.png", clickX, clickY);

bluntsound.play();

}

if (dealwithitPicture.isPointInElement(clickX, clickY)){ hatSoundPlay = false;

bluntSoundPlay = false;

weedSoundPlay = false;

if (!dealwithitSoundPlay) {

dealwithitsound.play();

dealwithitSoundPlay = true;

}

}

else if (backgroundPicture.isPointInElement(clickX, clickY) && dealwithitSoundPlay == true && EZInteraction.wasMouseLeftButtonReleased()){

EZ.addImage("dealwithit.png", clickX, clickY);

dealwithitsound.play();

}

if (weedPicture.isPointInElement(clickX, clickY)){

dealwithitSoundPlay = false;

hatSoundPlay = false;

bluntSoundPlay = false;

if (!weedSoundPlay) {

weedsound.play(); //then weedsound will play

weedSoundPlay = true;

}

}

else if (backgroundPicture.isPointInElement(clickX, clickY) && weedSoundPlay == true && EZInteraction.wasMouseLeftButtonReleased()){

EZ.addImage("weed.png", clickX, clickY);

weedsound.play();

}

}

EZ.refreshScreen();

}

最佳答案 首先,您应该检查该点是否在一个贴纸的区域内.如果没有,请检查另一个贴纸,依此类推.只有在检查完所有贴纸并设置相应的布线后,才能处理贴纸.

而不是4个布尔值,最好有一个变量代表当前活动的贴纸.

在伪代码中,类似于

if (point in hat) {

set hat

} else if (point in blunt) {

set blunt

} else if ...

...

} else {

place the active sticker

}

所以你的代码看起来像这样:

if (hatPicture.isPointInElement(clickX, clickY)){

bluntSoundPlay = false;

weedSoundPlay = false;

dealwithitSoundPlay = false;

if (!hatSoundPlay) {

hatsound.play();

hatSoundPlay = true;

}

} else if (bluntPicture.isPointInElement(clickX, clickY)){

hatSoundPlay = false;

weedSoundPlay = false;

dealwithitSoundPlay = false;

if (!bluntSoundPlay) {

bluntsound.play();

bluntSoundPlay = true;

}

} else if (dealwithitPicture.isPointInElement(clickX, clickY)){

hatSoundPlay = false;

bluntSoundPlay = false;

weedSoundPlay = false;

if (!dealwithitSoundPlay) {

dealwithitsound.play();

dealwithitSoundPlay = true;

}

} else if (weedPicture.isPointInElement(clickX, clickY)){

dealwithitSoundPlay = false;

hatSoundPlay = false;

bluntSoundPlay = false;

if (!weedSoundPlay) {

weedsound.play(); //then weedsound will play

weedSoundPlay = true;

}

} else if (backgroundPicture.isPointInElement(clickX, clickY) {

if (hatSoundPlay){

EZ.addImage("hat.png", clickX, clickY);

hatsound.play();

} else if (bluntSoundPlay){

EZ.addImage("blunt.png", clickX, clickY);

bluntsound.play();

} else if (dealwithitSoundPlay){

EZ.addImage("dealwithit.png", clickX, clickY);

dealwithitsound.play();

} else if (weedSoundPlay){

EZ.addImage("weed.png", clickX, clickY);

weedsound.play();

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值