Мышь нажата проблема зацикливания - PullRequest
0 голосов
/ 24 сентября 2019

Это мой текущий код: (все варианты коммутаторов похожи)

    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 (которая очищает доску).Это заставляет меня верить, что это что-то с переключателем.Я хочу, чтобы код выдавал единицу на выходе при каждом нажатии мыши.Что мне делать?

1 Ответ

0 голосов
/ 24 сентября 2019

Вы должны поставить команду 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;
        }
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...