Hi, fellow Coders. I recently got this assignment and I’m halfway through it. It’s a number guessing game.
void setup() {
size(600,600);
background(230,230,255);
}
int onum = int(random(0,9)); // onum = Originial Number
char gnum = char(onum+48); // Gnum = "Guess Number" and 48 is 0 char
char input; // Made char for user input
{
print(gnum); // Made seperate part of code so it doesn't constantly rerun and make a new number
}
void draw() {
String Welcome = "Welcome to the Number Guessing Game!";
String Instruct = "The Computer will generate a random number (0 to 9) and It's your job to guess the number by using the number keys";
textSize(20);
fill(0);
text(Welcome, 50, 100, 280, 100);
text(Instruct, 50, 170, 400, 170);
}
String correct = "Congrats! You guessed correctly!";
String guess_lower = "Guess lower!";
String guess_higher = "Guess higher!";
void keyPressed() {
input = key; // Putting input char in use, collecting user input now
textSize(20);
fill(0);
if (keyPressed) {
input = key;
if (input == gnum) {
text(correct, 190, 460, 270, 460);
}
}
if (input > gnum) {
// Guess Lower
text(guess_lower, 230, 460, 320 ,460);
String Welcome = "Welcome to the Number Guessing Game!";
String Instruct = "The Computer will generate a random number (0 to 9) and It's your job to guess the number by using the number keys";
textSize(20);
fill(0);
text(Welcome, 50, 100, 280, 100);
text(Instruct, 50, 170, 400, 170);
}
if (input < gnum) {
// Guess Higher
text(guess_higher, 230, 460, 320 ,460);
}
}
–
The thing I need help on is, making it so when it displays “Guess lower” or “Guess higher” the text disappears. My idea was to draw it over with a rectangle but when I do that it draws over it instantly and I’ve tried messing around with the delay or millis code but no success. If anyone could help me, much appreciated and also If you are willing to help could you please explain it dumb’d down so I can understand. Also, the last part is inviting the user to play and I have an idea on how I would do that, using Y or N to reset the game.
TL;DR
Need help on school assignment;
Need “Guess Higher” or “Guess Lower” text to disappear.