Working on a homework assignment and I’m absolutely horrible with programming. I need to run a program that asks a riddle and lists some words. the Answer to the riddle is the first letter of each word. Once the user inputs the correct answer into JOptionPane the screen is supposed to turn black. The part that I’m hung up on is getting the user input to turn the screen black and I can’t seem to find any tutorial videos that will talk about this using strings. I found one that uses int’s but I’m at a loss as to how to do this with strings.
color boxFill =color(0);
color letterFill = color (0, 200, 0);
String input;
void setup()
{
size (500, 500);
textSize (40);
rectMode (CORNERS);
textAlign (CENTER);
}
void draw ()
{
background (100);
opener ();
clues();
finalQuestion();
answerButton();
}
void opener ()
{
String opener = "i am: ";
fill (boxFill);
stroke (0);
rect (width/2-textWidth(opener)/2, height/24+textAscent(),
width/2+textWidth(opener)/2, height/24-textDescent());
fill (letterFill);
opener = opener.toUpperCase();
text (opener, width/2, height/10);
}
void clues()
{
stroke (0);
String clues = ("one, two, three, four ");
clues = clues.toUpperCase();
String [] list = clues.split(" ");
for (int i = 0; i < list.length; i++)
{
fill (boxFill);
rect (width/2-textWidth(list[i])/2, height/7+i*50+textAscent(),
width/2+textWidth(list[i])/2, height/7+i*50-textDescent());
fill (letterFill);
text (list[i], width/2, height/5+i*50);
}
}
void finalQuestion ()
{
String question = "Who am I?";
stroke (0);
fill (boxFill);
rect (width/2-textWidth(question)/2, height-height/3-textAscent(),
width/2+textWidth(question)/2, height-height/3+textDescent());
fill (letterFill);
text (question, width/2, height-height/3);
}
void answerButton()
{
String correct = "Correct";
String answer = "Answer?";
fill (255, 0, 0);
stroke (255);
rect (width/2-textWidth(answer)/2, height-height/5-textAscent(),
width/2+textWidth(answer)/2, height-height/5+textDescent());
fill (255);
text (answer, width/2, height-height/5);
if (mousePressed && mouseX >= 200 && mouseX <= 300 && mouseY >= 300 && mouseY <= 400)
{
String solution = "";
while (!solution.equals("OTTF"))
{
String input = javax.swing.JOptionPane.showInputDialog(null, answer);
if (input.equals("OTTF"))
{
background (0);
noLoop();
}
}
}
}