This is my first post on this website so I'm extremely sorry if I break rules or stuff I don't know. That said, I have been assigned to make a Simon Says program by my teacher and I am struggling with the class so I am looking for other avenues of help. The rules are as follows:
The means of completing this assignment is entirely up to you. The code must work exactly as specified to receive proper credit. You will design the game Simon. In Simon there are four colors: red, blue, green and yellow. The user has to pick the same color(s) that Simon picks and in the correct sequence. The colors Simon chooses must be random. Each successive round Simon adds another color into the sequence. When the user fails, Simon should tell the user how many rounds they lasted. There should be no limit to how many rounds you can play. GUI is not required for this assignment. If you are using JOptionPane for choosing colors you must use the letter shortcuts of Red, Blue, Green and Yellow. You must also include instructions to the game. You must also keep track of the high score for each play and allow the user to type in their name for their high score. You do not have to keep score if you close the program; only while the program is open.
When I execute my code, it doesn't continue the game when the user gives the right answer but instead terminates after one loop. Weirdly, it only seems to loop if i give it the wrong answer. Lastly, I wanted to point out that my program is really basic because this is honestly all i know how to use. Thank you for your help
package stuff;
import java.util.ArrayList;
import javax.swing.JOptionPane;
public class Simon {
String s = "";
String a = "";
String c = "";
String d = "";
boolean b = true;
boolean b2 = true;
String obj[] = { "Red", "Yellow", "Green", "Blue" };
ArrayList<String> colors = new ArrayList<String>();
String[] options = new String[] { "Red", "Yellow", "Green", "Blue" };
int count = 0;
int count2 = 0;
int score = 0;
public String simon() {
do {
int c = ((int) (Math.random() * 4));
if (c == 0)
colors.add(obj[0]);
else if (c == 1)
colors.add(obj[1]);
else if (c == 2)
colors.add(obj[2]);
else if (c == 3)
colors.add(obj[3]);
else {
JOptionPane.showMessageDialog(null,
"weird stuff happened bruh");
}
JOptionPane.showMessageDialog(null, colors.get(count));
b2 = true;
while (b2) {
for (int i2 = 0; i2 < colors.size(); i2++) {
a = JOptionPane.showInputDialog("put letter");
if(a != null){
if (a.equalsIgnoreCase(colors.get(i2))) {
JOptionPane.showMessageDialog(null,
"Your color is right" + score);
score += 1;
if (i2 == colors.size() - 1)
b2 = false;
else {
JOptionPane.showMessageDialog(null, "weird stuff happened bruh fo realz");
}
} else {
b2 = false;
b = false;
}
}else{
System.exit(0);
}
}
}
count++;
} while (b == false);
return s;
}
}