Hi, I am trying to run a simple hangman game, and when the game ends I wanted the system to exit. To do this I inserted a delay after the screen ‘notified’ the user they had won or lost, and then used the exit command. But the code seems to be using the delay, then writing the text, and immediatly exiting with no time for the user to view the final result. (It’s line 63 and 64 in the code). Thank you!
char t = 't';
char a = 'a';
char n = 'n';
char g = 'g';
char l = 'l';
char e = 'e';
char d = 'd';
int x = 0;
int y = 265;
int newscore = 0;
int score = 0;
char priorKey = 0;
void setup()
{
size(500,500);
background(200,60,90);
textSize(20);
stroke(255);
}
void draw()
{
text("Welcome to Hangman!", 15,20);
text( "_ _ _ _ _ _ _", 50,450);
noFill();
strokeWeight(10);
rect(250,400,220,50); //used letters box
//the following is the gallows
line(350,100,350,150);
line(350,100,450,100);
line(450,100,450,350);
line(420,350,480,350);
if (keyPressed)
{
if (key != priorKey){
if( key == t) {text("t",50,440); x = x + 1;}
else if( key == a) {text("a",65,440); x = x + 1;}
else if( key == n) {text("n",80,440); x = x + 1;}
else if( key == g) { text("g",98,440); x = x + 1;}
else if( key == l) {text("l",118,440); x = x + 1;}
else if( key == e) {text("e",129,440); x = x + 1;}
else if( key == d) {text("d",144,440); x = x + 1;}
else {
text(key,y,425);
y = y + 10;
newscore = newscore + 1;
}
}
priorKey = key;
}
strokeWeight(3);
if (newscore==1) ellipse(350,175,50,50); //head
if (newscore==2) line(350,200,350,275); //body
if (newscore==3) line(350,230,320,210); //left arm
if (newscore==4) line(350,230,380,210); //right arm
if (newscore==5) line(350,275,320,305); //left leg
if (newscore==6) {
line(350,275,380,305); //right leg
text("YOU LOSE",150,200);
delay(3000);
exit();
}
if (x == 7){
text("Congradulations, you've figured it out!", 100,200);
delay(3000);
exit();
}
}