# Version of Whack-a-mole Game- Robot C (NEED HELP!)

My team and I have been trying to create a wack-a-mole type game. So what we have done is have a button and a light next to each other and when light activates you press the button and you get a point( meaning another light activates). BUT we have ran into the problem that we can’t get the the light that keeps the score to light up when button and LED are on. We have four buttons and four lights and when a light goes on you press the corresponding button then you get a point then LED 5 (the light that keeps score) lights up for 2 seconds. (This is on RobotC.)

int value;

{

while(1==1)

{

value = rand() % 4 + 1;

if (value == 1)

{

turnLEDOn(GreenLED1);

waitInMilliseconds(600);

turnLEDOff(GreenLED1);

waitInMilliseconds(600);

}

if (value == 2)

{

turnLEDOn(GreenLED2);

waitInMilliseconds(600);

turnLEDOff(GreenLED2);

waitInMilliseconds(600);

}

if (value == 3)

{

turnLEDOn(GreenLED3);

waitInMilliseconds(600);

turnLEDOff(GreenLED3);

waitInMilliseconds(600);

}

if (value == 4)

{

turnLEDOn(GreenLED4);

waitInMilliseconds(600);

turnLEDOff(GreenLED4);

waitInMilliseconds(600);

}

if(SensorValue(GreenLED1)==true && SensorValue(Button1)==1)

{

turnLEDOn(GreenLED5);

waitInMilliseconds(2000);

turnLEDOff(GreenLED5);

}

}

}

Are you doing this with robot c, if you are i would suggest looking into switch var statements and cases to at least shorten all the if statements

You turn the LED on and off before you have a chance to check to see if it’s pressed.

Try something like
‘Loop for game
Pick light
Light light
Loop for 600ms
check to see if button is pressed
if pressed then score = score + 1
end Loop
turn off light
end game loop’’’

We have four buttons and four lights and when a light goes on you press the corresponding button then you get a point then LED 5 (the light that keeps score) lights up for 2 seconds.

yes we’re doing this in Robot C, I’m going to try and changing the if statements to switch.

Your code turns the light on and off and THEN it checks to see if it’s on. It needs to check while the light is on.