//Exercise G
//Greg Batha DESMA 28 Interactivity
PFont font;
String letters = "";
int mode = 0;
//initializes strings for riddles
String welcome;
String riddle1;
String riddle2;
String riddle3;
String congrats;
String correct;
String r1ans;
String r2ans;
String r3ans;
//booleans that check if riddles are answered correctly
boolean r1correct;
boolean r2correct;
boolean r3correct;
//int that counts how many are answered correctly
int numCorrect;
void setup() {
size(400, 400);
font = loadFont("Eureka-24.vlw");
textFont(font);
textAlign(CENTER);
//defines strings
welcome = "Welcome to the riddle game! type 'ready' and press enter or return to begin playing. If a riddle has you stumped, type 'hint' for some help, or type 'give up' to give up and go to the next riddle. There are no spaces in any answer. Always press enter or return after giving your answer and be careful of spelling!";
riddle1 = "Riddle #1: What word can be written forward, backward or upside down, and can still be read from left to right?";
riddle2 = "Riddle #2: What kind of clothes do lawyers wear?";
riddle3 = "What has four eyes but can't see?";
congrats = "Congratulations, you're done! you got ";
correct = "Correct!";
r1ans = "Answer: NOON";
r2ans = "Answer: lawsuits";
r3ans = "Answer: Mississippi";
//booleans for correcly answered riddles all start as false
r1correct = false;
r2correct = false;
r3correct = false;
numCorrect = 0;
}
void draw() {
background(102);
text(letters, width/2, 370);
//displays the welcome page when program starts
if(mode == 0)
{
textSize(24);
text(welcome, 50, 20, 300, 350);
}
//riddle 1
else if(mode == 1)
{
text(riddle1, 50, 100, 300, 350);
}
//riddle 2
else if(mode == 2)
{
if(r1correct == true)
{text(correct, 50, 20, 300, 350);}
else
{text(r1ans, 50, 20, 300, 350);}
text(riddle2, 50, 100, 300, 350);
}
//riddle 3
else if(mode == 3)
{
if(r2correct == true)
{text(correct, 50, 20, 300, 350);}
else
{text(r2ans, 50, 20, 300, 350);}
text(riddle3, 50, 100, 300, 350);
}
//the end!
else if(mode == 4)
{
if(r3correct == true)
{text(correct, 50, 20, 300, 350);}
else
{text(r3ans, 50, 20, 300, 350);}
text(congrats + numCorrect + " out of 3 right!", 50, 100, 300, 350);
}
}
void keyPressed() {
if ((key == ENTER) || (key == RETURN)) {
letters = letters.toLowerCase();
println(letters); // Print to console to see input
//begins the game
if (letters.equals("ready") && mode == 0) {
mode = 1;
}
//tests the hint command
else if (letters.equals("hint") && mode == 0) {
welcome += "HINT: you correctly asked for a hint!";
}
//answer for riddle 1
else if(letters.equals("noon") && mode == 1)
{
mode = 2;
r1correct = true;
numCorrect ++;
}
//hint for riddle 1
else if(letters.equals("hint") && mode == 1)
{
riddle1 += "\n HINT: the word is completely upper-case.";
}
//give up on riddle 1
else if(letters.equals("give up") && mode == 1)
{
mode = 2;
}
//answer riddle 2
else if(letters.equals("lawsuits") && mode ==2)
{
mode = 3;
r2correct = true;
numCorrect ++;
}
//give up on riddle 2
else if(letters.equals("give up") && mode ==2)
{
mode = 3;
}
//hint for riddle 2
else if(letters.equals("hint") && mode ==2)
{
riddle2 += "\n HINT: they're very nice clothes";
}
//answer for riddle 3
else if(letters.equals("mississippi") && mode == 3)
{
mode = 4;
r3correct = true;
numCorrect ++;
}
//give up on riddle 3
else if(letters.equals("give up") && mode == 3)
{
mode = 4;
}
//hint for riddle 3
else if(letters.equals("hint") && mode == 3)
{
riddle3 += "\n HINT: It's a state";
}
letters = ""; // Clear the variable
} else if ((key > 31) && (key != CODED)) {
// If the key is alphanumeric, add it to the String
letters = letters + key;
}
}Gregory - G
on Wednesday, Oct 22, 2008 – 1:56 am
3 Comments
funny and i like the hints, but you spelled Mississippi wrong
Watch the spelling: Mississippi
Typo fixed. Thanks for the input :)