How do I set a variable to be the value of the chosen door?

From ggc

Jump to: navigation, search

I want to set a variable to be the value of the player's choice. If done, I can refer to the choice as a variable instead of a series of "if statements". What exactly would I set to be the value of variable "choice"?

You could for example declare an instance variable:

private int choice;

and in the advanceFrame method you would have something like:

if(door1.intersects(click))
{
    choice=1;
    //more code here to remove doors
}
else if(door2.intersects(click))
{
    choice=2;
    //more code here to remove doors
}
...

and where you are on the second part, you can then use statements like:

if(choice==1)
{
    //do something
}
else if(choice==2)
{
    //do something else
}
else
{
    //do another something
}




Views
Personal tools
Add to 
del.icio.usAdd to 
diggAdd to 
FacebookAdd to 
favoritesAdd to 
GoogleAdd to 
MySpaceAdd to 
PrintAdd to 
SlashdotAdd to 
StumbleUponAdd to 
Twitter