This question already has an answer here:
- Get random boolean in Java 9 answers
How can I attribute the first player to play? I flip turns with a boolean so that when player1 touchs a cell, it flips to player2 and so on. But I have a fixed turn set to either player1 or player2.
I delcare something:
boolean playerSwitcher;
Then inside the onCreate method:
playerSwitcher = false; //False for player 1
And then on my method which manage tapping:
@Override
public void onCellTapped(int x, int y) {
//....
//Do a bunch of things here
playerSwitcher = !playerSwitcher; //This flips to true then false and so on
//Do a bunch of things here: Drawing circle on the grid, printings position, etc
}
On initialization, only player1 starts first. I would like to randomize their turns. How can I do that?
Aucun commentaire:
Enregistrer un commentaire