# Score help 30 hello

**URL:** https://discourse.processing.org/t/score-help-30-hello/28110
**Category:** Processing
**Tags:** homework
**Created:** [February 27, 2021, 10:33am UTC](https://discourse.processing.org/t/score-help-30-hello/28110 "2021-02-27T10:33:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Mrcroissant](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mrcroissant/32/12235_2.png) [@Mrcroissant](https://discourse.processing.org/u/Mrcroissant)
#### Post date: [February 27, 2021, 10:33am UTC](https://discourse.processing.org/t/score-help-30-hello/28110/1 "2021-02-27T10:33:45Z")

</div>

> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147)

Hello i want too stop the programe when the score go to 30 how i can do that  
int x,y, couleur; // Déclaration variables coordonées cible et couleur de la cible  
int mx,my; // Couleur du rectangle et coordonées du curseur  
boolean cible\_en\_cours; // ne mettre qu’une cible à la fois  
int score=0;  
boolean scorre ;  
long temps, debut;

int square\_size = 50;  
float square\_x;  
float square\_y;

final int menu = 0;  
final int jeux1 = 1;  
final int jeux2 = 2;  
int state = menu;  
PFont font;

void setup() // partie faite qu’une seule fois  
{

size(900,600); // définition de la taille de l’aire de jeux ici 900 pixels par 600 pixels

}

void draw(){

```
switch (state) {

```

case 0:  
{  
showMenu();  
break;  
}  
case 1:  
{  
handlejeux();  
break;  
}

```
case 2:
{
handlejeux2();
break;
}

```

default:

```
println ("Unknown state (in draw) "
  + state
  + " ++++++++++++++++++++++");
exit();
break;

```

} // switch  
}//func

void keyPressed() {  
// We use a switch() to eval state  
switch (state) {  
case menu:  
keyPressedForMenu(); // touche presse pour le menu  
break;  
case 1:  
keyPressedForjeux1(); // touche presse pour le jeux1  
break;  
case 2:  
keyPressedForjeux2(); // touche presse pour le jeux2  
break;  
default:  
println (“Unknown state (in keypressed) "  
+ state  
+ " ++++++++++++++++++++++”);  
exit();  
break;  
}  
}

void keyPressedForMenu() {

```
switch(key) {

```

case ‘1’:  
{  
state = jeux1; // etat du jeux quand la touche est presse pour le jeux1  
break;  
}

case ‘2’:  
{  
state = jeux2; // etat du jeux quand la touche est presse pour le jeux2  
break;  
}

case ‘x’: // quiter le jeu  
{  
exit();  
break;  
}

default:  
{  
//  
key=0; // Interdir Esc  
break;  
}  
}  
}

void keyPressedForjeux1() { // Fonction qui fait lance la dificulté 1  
switch(key) {  
case 1:  
{  
state = 1; // etat qui permet de lancer le jeu 1  
break;  
}  
default:  
key=0; // kill Esc  
state = menu;  
break;  
} // switch  
//  
} // func

void keyPressedForjeux2() { // Fonction qui fait lance la dificulté 2  
switch(key) {  
case 2:  
{  
state = 2; // etat qui permet de lancer le jeu 2  
break;  
}  
default:  
{  
key=0; // kill Esc  
state = menu;  
break;  
}  
} // switch  
//  
} // func

void showMenu(){ //visuel (fond rectange nom ect…)  
size(900,600);

PImage menu;  
menu = loadImage(“menu.jpg”); //Fond du jeu

image(menu,0,0); // position de l’image  
fill(0);  
textSize(23); // taille du texte  
fill(0, 25, 255);  
text("Press 1 Pour lancer le niveaux 1 ", 100, 260);// Lancer le jeu  
fill(255, 0, 0);  
text("Press x Pour Quitter ", 100, 350);// Quiter le jeu  
fill(255, 255, 255);  
text("Press 2 Pour lancer le niveaux 2 ", 100, 300);// Quiter le jeu  
}

void handlejeux(){ // Lance la difficulté 1

temps=millis();  
if (cible\_en\_cours) // si aucune cible ou cible trouvée alors créer une autre cible  
{  
x=round (random(100, 580));  
y=round (random(100, 580));  
fill(0,255,0);  
rect(x,y,30,30); // dessin du rectangle  
cible\_en\_cours=false;  
debut=temps;  
;// cible affichée en attente d’être touchée  
}

```
   if((temps-debut)>1000){
fill(255, 0,0);
textSize(25);
rect(x,y,30, 30);
background(255);
score=score-1 ;
text("score =" + " " +score,10, 20);

```

if (scorre)  
{  
score = 10;  
state = menu;  
}

```
cible_en_cours=true;
   }

 mx = mouseX; // lecture coordonée x de la souris
 my= mouseY; 
 // lecture coordonnée y de la souris

```

}

void handlejeux2(){ // lance la difficulté 2

temps=millis();  
if (cible\_en\_cours) // si aucune cible ou cible trouvée alors créer une autre cible  
{  
x=round (random(100, 580)); //position au hazard sur l’axe x  
y=round (random(100, 580)); //position au hazard sur l’axe y  
fill(0,255,0);  
rect(x,y,30,30); // dessin du rectangle  
cible\_en\_cours=false;  
debut=temps;  
;// cible affichée en attente d’être touchée  
}

```
   if((temps-debut)>700){ //vitesse d'apparition d'un carré
fill(255, 0,0);
textSize(25);
rect(x,y,30, 30); //taille du rectangle 
background(255); //réinitialisation du fond
score=score-1 ;
text("score =" + " " +score,10, 20);

cible_en_cours=true;
   }

 mx = mouseX; // lecture coordonée x de la souris
 my= mouseY; 
 // lecture coordonnée y de la souris

```

{  
temps=millis(); //cible en rouge quand loupé  
if (cible\_en\_cours) // si aucune cible ou cible trouvée alors créer une autre cible  
{  
x=round (random(100, 580)); //position au hazard sur l’axe x  
y=round (random(100, 580)); //position au hazard sur l’axe y  
fill(255, 0, 0);  
rect(x,y,30,30); // dessin du rectangle  
cible\_en\_cours=false;  
debut=temps;  
;// cible affichée en attente d’être touchée  
}

```
   if((temps-debut)>700){
fill(255, 0,0);
textSize(25);
rect(x,y,30, 30); //taille du rectangle 
background(255); //réinitialisation du fond
score=score-1 ;
text("score =" + " " +score,10, 20);

cible_en_cours=true;
   }

 mx = mouseX; // lecture coordonée x de la souris
 my= mouseY; 
 // lecture coordonnée y de la souris

```

}  
}

void mousePressed()

```
 {{
 if((mx>=x)&&(mx<=x+30)&&(my>=y)&&(my<=y+30)) // if curseur sur rectangle alors..
           {
           fill(0,0,0); // remplir le rectangle de noir
           rect(x+5,y+5,20,20); // mais pas complètement
           cible_en_cours=true;
           background(255);
           score = score+1;
           // cible touchée 
           }
           else {
             fill(255,0,0); 
             score=score-1;
             cible_en_cours=true;
             background(255);
}

```

}

text(“score =” + " " +score,10, 20);  
}

---

<div class="post-metadata">

### Author: ![TfGuy44](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tfguy44/32/41_2.png) [@TfGuy44](https://discourse.processing.org/u/TfGuy44)
#### Post date: [February 27, 2021, 12:33pm UTC](https://discourse.processing.org/t/score-help-30-hello/28110/2 "2021-02-27T12:33:27Z")

</div>

Your variable called `score` appears to be keeping track of the score.

If that variable has a value of thirty, then call `exit()`. This will close your sketch.

The addition to your code will look something like this:

```auto
if( score == 30 ){
  exit();
}

```

Put this anywhere where the score changes.

* * *

That said, your code is an unreadable mess. Please (PLEASE PLEASE PLEASE FOR THE LOVE OF ALL THAT IS HOLY PLEASE) learn how to format your code when you post by using the \</\> button.
