Not Sure what to do from here...stuck. Please help
in
Programming Questions
•
7 months ago
I want the program to ask for persons name, then move on to 2nd question if that person wants to play a game with their name in the text, based on their answer y/n a text text will pop up. But I know I placed something wrong and it wont move on from the first question.
PFont F= createFont("CenturyGothic", 16, true);
String firstname="";
String typing="";
int indent;
char answer = 0;
void setup()
{
size (500, 500);
indent = width/5;
}
void draw()
{
question1();
}
void keyReleased()
{
if (keyCode == BACKSPACE)
{
if (typing.length() > 0)
{
typing = typing.substring(0, typing.length()-1);
}
}
else if (keyCode != SHIFT && keyCode != CONTROL && keyCode != ALT)
{
typing = typing + key;
}
}
void keyPressed()
{
switch(keyCode)
{
case ENTER:
firstname = typing;
question2();
break;
}
switch (key)
{
case 'y':
answer = key;
text("Let's play!", indent, 40);
break;
case 'n':
background(255);
text("You said no :(", indent, 40);
}
}
void question1()
{
background (255);
textFont(F);
fill(0);
text("What is your first name:", indent, 40);
text(typing, indent*2.78, 40);
}
void question2()
{
background (255);
textFont(F);
fill(0);
text("Do you want to play a game " +firstname+"? y/n", indent, 40);
if (answer == 'y')
{
// Game here
}
}
1