i appreciate your speedy reply, but it didn't work.. my explanation may not be clear.. please try the game and lemme know your thoughts... the code for my simple game:
int state = 0;
int MAXGUESS=10;
String secret = "";
String guess = "";
String [] guesses = new String[MAXGUESS];
int counter=0;
int nguess=0;
void setup() {
size(650,480);
secret += char('1'+ int(random(5)));
secret += char('1'+ int(random(5)));
secret += char('1'+ int(random(5)));
println(secret);
}
int hint1() {
int h1 = 0;
println("guess="+guess);
if(secret.indexOf(guess.charAt(0))>=0)
h1 = h1 + 1;
if(secret.indexOf(guess.charAt(1))>=0)
h1 = h1 + 1;
if (secret. indexOf(guess.charAt(2))>=0)
h1 = h1 + 1;
return h1;
}
int hint2() {
int h2 = 0;
if(guess.charAt(0)==secret.charAt(0))
h2 = h2 + 1;
if(guess.charAt(1)==secret.charAt(1))
h2 = h2 + 1;
if(guess.charAt(2)==secret.charAt(2))
h2 = h2 + 1;
return h2;
}
void keyPressed() {
if(state==0) {
background(#009933);
draw_intro();
if(key=='h'|| key=='H')
state=1;
if(key=='s'|| key=='S')
state=2;
}
if (state==1) {
background(#009933);
draw_help();
if(key=='s'||key=='S')
state=2;
}
if (state==2) {
background(#009933);
int y=45, x=10;
draw_game();
guess="";
// while (nguess < MAXGUESS){
if(key=='h'|| key=='H')
state=1;
else //if (key=='0'||key=='1'||key=='2'||key=='3'||key=='4'||key=='5'||key=='6'||key=='7'||key=='8'||key=='9')
guess += key;
println("guess: " + guess);
if (guess.length()==3) {
y = y+20;
int h1 = hint1();
int h2 = hint2();
println ("hint: "+ h1 + h2);
text (h1 + " " + h2, 325, y);
}
//}
if (guess.charAt(0)== secret.charAt(0) && guess.charAt(1)== secret.charAt(1)&& guess.charAt(2)== secret.charAt(2)) {
state = 4;
draw_win();
}
if (nguess > MAXGUESS) {
state = 3;
draw_lose();
}
}
}
//0 - intro screen
//1 - help screen
//2 - game screen
//3 - end screen lose
//4 - end screen win
void draw_intro() {
background(#009933);
fill(#ffffff);
text("Welcome to the number guessing game!", 155, 65);
text("Press 'S' to start.", 225, 125);
text("Press 'H' for help.", 225, 145);
}
void draw_help() {
background(#009933);
fill(#ffffff);
text("OBJECTIVE: Correctly guess the secret code.", 10, 25);
text("INSTRUCTIONS: Using only digits 1-5, enter a 3-digit code. You will then be",10,65);
text("given a hint. The first digit of the hint is the number of times one of your",10, 85);
text("guessed digits appears in the secret code. The second digit is the number of",10, 105);
text("digits that appear in the correct location.",10, 125);
text("EXAMPLE: Secret Code is 123.",10, 165);
text(" Your guess is 135.",10,185);
text(" The hint would be 21.",10, 205);
text("EXPLANATION:",10, 245);
text("The first digit tells us that 2 of my guesses appear in the code.",10, 265);
text("The second digit tells us that 1 of my guesses appears in the correct location.",10,285);
text("Press 'S' to start.",10, 325);
}
void draw_lose() {
background(#009933);
fill(#ffffff);
text("Sorry. Try again.",155,65);
}
void draw_win() {
background(#009933);
fill(#ffffff);
text("You WIN!");
}
void draw_game() {
fill(#ffffff);
stroke(#ffffff);
strokeWeight(3);
text("GUESS: ", 10,25);
text("HINT: ", 325,25);
line(10,35,640,35);
line(305,35,305,475);
int x = 10, y = 65;
text(guess, 10, 65);
for(int row=0; row < nguess; row++) {
text(guesses[row],x,y);
y=y+20;
}
}
void draw() {
PFont arial;
arial= loadFont("Arial-Black-48.vlw");
textFont(arial, 15);
if(state==0)
draw_intro();
if (state==1)
draw_help();
if (state==2)
draw_game();
if (state==3)
draw_lose();
if (state==4)
draw_win();
}