Thanks for all your advice. I tried to incorporate some of it into my code, so I hope it's at least a little easier to read.
When I run my program now, I'm only able to get from tactic 1 to tactic 2 by pressing "c", which is the right answer. Unfortunately, I'd like my explanations of why a, b and d are wrong to show up when I press those letters. For some reason, they aren't doing that. If you look in the Tactics class, at the checkAnswer() function, it looks like the explanations should be showing up (I call them responses).
Also, I'm not able to get from tactic 2 to tactic 2, even when I press the right key (and again, explanations don't show up if I get tactic 2 wrong).
Code:Tactics tactic1;
Tactics tactic2;
Tactics tactic3;
PImage Tactic;
PFont Perpetua;
boolean T1Completed = false;
boolean T2Completed = false;
char a;
char b;
char c;
char d;
void setup() {
size(800,600);
smooth();
Perpetua = loadFont("Perpetua-48.vlw");
tactic1 = new Tactics(loadImage("TOne.jpg"), "One", "...Nxh4", "...d2", "...Rg7", "...Rxh7", "Black", "Easy", "Wrong. If ...Nxh4+, then Rxh4.",
"Wrong. If ...d2, pushing the pawn, the rook on d6 simply eats the pawn.", "Correct.", "Wrong. If ...Rxh7, picking up the pawn, white can mate by Rd8#.", c);
tactic2 = new Tactics(loadImage("TTwo.jpg"), "Two", "Bxh7", "g4", "Nxd8", "Bg5", "White", "Easy", "Wrong. There is a better move lurking.",
"Wrong. g4 threatens g5#, but the black king can now go to e7.", "Wrong. There is a better move lurking.", "Correct.", d);
tactic3 = new Tactics(loadImage("TThree.jpg"), "Three", "...Bxc3", "...a6", "...Qb6", "...Bd7", "Black", "Easy", "Correct.", "...a6 prepares ...b5, but the queen still isn't trapped.",
"...Qb6 doesn't create any threats.", "Even if attacked, the enemy queen can still go to b3 or c2.", a);
}
void draw() {
background(125, 0, 0);
tactic1.display();
tactic1.checkAnswer();
if (T1Completed) {
tactic2.display();
tactic2.checkAnswer();
if (T2Completed) {
tactic3.display();
tactic3.checkAnswer();
}
}
}
void keyPressed() {
if (key == 'c') {
if (!T1Completed) {
T1Completed = true;
if (key == 'd') {
if (!T2Completed) {
T2Completed = true;
}
}
}
}
}
Code:class Tactics {
PImage Tactic;
String Number, ChoiceA, ChoiceB, ChoiceC, ChoiceD, Color, Difficulty, ResponseA, ResponseB, ResponseC, ResponseD;
char Correct;
Tactics(PImage tempTactic, String tempNumber, String tempChoiceA, String tempChoiceB, String tempChoiceC, String tempChoiceD, String tempColor, String tempDifficulty,
String tempResponseA, String tempResponseB, String tempResponseC, String tempResponseD, char tempCorrect) {
Tactic = tempTactic;
Number = tempNumber;
ChoiceA = tempChoiceA;
ChoiceB = tempChoiceB;
ChoiceC = tempChoiceC;
ChoiceD = tempChoiceD;
Color = tempColor;
Difficulty = tempDifficulty;
ResponseA = tempResponseA;
ResponseB = tempResponseB;
ResponseC = tempResponseC;
ResponseD = tempResponseD;
Correct = tempCorrect;
}
void display() {
image(Tactic, 0, 0);
fill(0);
textFont(Perpetua, 38);
text("Tactic " + Number, 520, 35); //Text displays tactic number
textFont(Perpetua, 32);
text("A: " + ChoiceA, 520, 150); //Text displays tactic choice A
text("B: " + ChoiceB, 520, 200); //Text displays tactic choice B
text("C: " + ChoiceC, 520, 250); //Text displays tactic choice C
text("D: " + ChoiceD, 520, 300); //Text displays tactic choice D
textFont(Perpetua, 30);
text(Color + " to move", 520, 400); //Text displays what color it is to move
textFont(Perpetua, 28);
text("Difficulty: " + Difficulty, 520, 505); //Text displays the difficulty of the tactic
}
void checkAnswer() {
if (keyPressed) {
if (key == 'a' && Correct != a) {
background(255);
text(ResponseA, 0, 25);
}
else if (key == 'b' && Correct != b) {
background(255);
text(ResponseB, 0, 25);
}
else if (key == 'c' && Correct != c) {
background(255);
text(ResponseC, 0, 25);
}
else if (key == 'd' && Correct != d) {
background(255);
text(ResponseD, 0, 25);
}
}
}
}