gpt4 book ai didi

java - 鼠标按下循环问题

转载 作者:行者123 更新时间:2023-12-02 09:29:54 25 4
gpt4 key购买 nike

这是我当前的代码:(开关盒都相似)

    void mousePressed() {
if(firstClick == true){//first time to start game
if (mousePressed == true){
if(mouseX >= width/2.0 - (3.0*width/8.0) && mouseX <= width/2.0 + (3.0*width/8.0) && mouseY >= height/2.0 - height/8.0 && mouseY <=height/2.0 + height/8.0){//start button pressed
drawBall();
firstClick = false;
}
}
}
else{
drawBall();//clear screen
if(mousePressed == true){
if(mouseX <= width - width/20.0 && mouseX >= width - 3.0*width/20.0 && mouseY <= height - height/30.0 && mouseY >= height - 5.0*width/30.0){//play button pressed
int fortune = (int)random(0,8);
switch(fortune)//fortunes
{
case 0:
textSize(25*height/800);
fill(255);
text("Fortunes are for people who cant understand RND.",width/2, height/2);

case 1:
textSize(25*height/800);
fill(255);
text("You will be overrun by sadness :(",width/2, height/2);

case 2:
textSize(25*height/800);
fill(255);
text("You will have great luck today 1",width/2, height/2);

case 3:
textSize(25*height/800);
fill(255);
text("You will fail a test :(",width/2, height/2);

case 4:
textSize(25*height/800);
fill(255);
text("You will get a good score on a test!",width/2, height/2);

case 5:
textSize(25*height/800);
fill(255);
text("No one will listen to you today :(",width/2, height/2);

case 6:
textSize(25*height/800);
fill(255);
text("You will get what you want!",width/2, height/2);

case 7:
textSize(25*height/800);
fill(255);
text("Your day will suck :(",width/2, height/2);

default:
textSize(25*height/800);
fill(255);
text("You will have a great day!",width/2, height/2);
}
}
}
}

当我运行代码时。它对文本进行分层,即使我输入了一个名为 DrawBall 的函数(用于清除棋盘)。这让我相信这与开关有关。我希望代码在每次按下鼠标时给出一个输出。我该怎么办?

最佳答案

您必须在每种情况下放置 break; 命令并默认,除非您的所有情况都会同时执行

 switch(fortune)//fortunes
{
case 0:
textSize(25*height/800);
fill(255);
text("Fortunes are for people who cant understand RND.",width/2, height/2);
break;

case 1:
textSize(25*height/800);
fill(255);
text("You will be overrun by sadness :(",width/2, height/2);
break;

case 2:
textSize(25*height/800);
fill(255);
text("You will have great luck today 1",width/2, height/2);
break;

case 3:
textSize(25*height/800);
fill(255);
text("You will fail a test :(",width/2, height/2);
break;

case 4:
textSize(25*height/800);
fill(255);
text("You will get a good score on a test!",width/2, height/2);
break;

case 5:
textSize(25*height/800);
fill(255);
text("No one will listen to you today :(",width/2, height/2);
break;

case 6:
textSize(25*height/800);
fill(255);
text("You will get what you want!",width/2, height/2);
break;

case 7:
textSize(25*height/800);
fill(255);
text("Your day will suck :(",width/2, height/2);
break;

default:
textSize(25*height/800);
fill(255);
text("You will have a great day!",width/2, height/2);
break;
}

关于java - 鼠标按下循环问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58078939/

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