How do I set a variable to be the value of the chosen door?
From ggc
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
}
- This page was last modified on 1 February 2008, at 13:17.
- This page has been accessed 243 times.
- Privacy policy
- About ggc
- Disclaimers
- Powered by MediaWiki!









