I'm working on a JPanel project where you play the computer in Rock, Paper, Scissors. I'm using an enum for the choices. I have it set up like so
enum Choices {rock, paper, scissors}
And now, to set the "players choice" to be whatever button they press, I have
if (event.getSource() == rock){ //Makes it so when you press rock button, your choice is rock
Choice playerChoice = Choice.rock;
}
But now when I try to do
if (playerChoice == Choice.rock)
if (cpuChoice == Choice.scissors)
playerWon = true;
.. and so on for each of the options, I get an error on "playerChoice" saying it cannot find symbol. Any ideas? Thanks in advance!
Edit: It was suggested "Using variables outside of an if statement", but on that, the person was initializing and instantiating the variable inside. I have already initialized it the enum.