For my game I am trying to create a menu for a character selection of sorts. This part is working fine, but when i click on the text I would like to make it turn red. There are other names on the menu, and when these names are clicked I would like the currently selected one to switch to white. Currently I have a Boolean set to false and when the image is clicked on it changes to red and sets the boolean to true. The code then never runs through again to change the boolean. Thanks in advance for the help.
public class Colonist2 extends ColonistMain
{
int a = Greenfoot.getRandomNumber(18);
int b = Greenfoot.getRandomNumber(4);
private boolean click2 = false;
public void act()
{
ColonistName();
}
public void ColonistName()
{
String Fname[] = {"Anderson", "Jack", "Bryce", "Dale", "Ashton", "Gordan", "Joe", "Luke", "Steven"};
String Lname[] = {"Palumbo", "Miller", "Smith", "Martinez"};
if (a <= 18)//this is set to be the only one running so I only have to write code for this line for now
{
if (b <= 4)//same as if statement a
{
if (Greenfoot.mouseClicked(Colonist1) || Greenfoot.mouseClicked(Colonist3))
{
click2=false;
}
else if (Greenfoot.mouseClicked(this))
{
setImage(new GreenfootImage(Fname[0] + " " + Lname[0], 24, Color.RED, new Color (85, 85, 85)));
click2 = true; //sets click2 equal to true
}
else if (click2==false)//this line checks to see if the boolean is false so this can run
{
setImage(new GreenfootImage(Fname[0] + " " + Lname[0], 24, Color.WHITE, new Color (85, 85, 85)));
}
}
