I am rather new to android developing and can't figure out how to do a double check on a button press. I am working in Android Studio and am trying to create a little simple game and have the following: two buttons (button1 and button2)declared and instantiated in an onClick method. When button 1 is pressed a counter is incremented and a specific value is shown on the button from an array with the values 0, 10, 50, 100. This part works like a charm. What I can't do is create a working "tiebreaker rule" which should be something like:
if (button1 value == 100 and button2 value == 100) or this can be done with the counter if (counter1 == 3 && counter2 == 3)
tiebreaker();
this is what I need to do:
public void tiebreaker(){
if (button1 is pressed){
button1.setText(String.valueOf("OK. One more!");
if (button1 is pressed (again){
resetCounters();
goForPlayer1(); //distinct method
} else if (button2 is pressed) {
//set both values back to 100
tiebreaker(); //calls itself in order to repeat until a button is pressed twice consecutivelly
} (else?)
if(button2 is presed){
//same code as above, just with the numbers 1 and 2 swapped
}
}
I have tried implementing this tiebreaker method in different ways, but with no final success. I tried with if(button1.isPressed())
as condintion, having a boolean turn true when the button is pressed and using it as a condition, using the values from the buttons with button.equals("100") or whatever should be written
but nothing.
Also, I tried making the tiebreaker as a second onClick method and doing checks based on switch (View.getId())
but the problem here is that the method being view dependant (tiebreaker(View v)
) I am not sure how to call it from a different method.
IMO the main issue is that if within another if or switch/case within another switch/case can't be used when it comes to button presses (I could be wrong, though), but I don't know of any other way to do this.
I hope I did not miss anything and managed to make myself clear. I appreciate any input in helping me solve this tiebreaker rule. Thank you