Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* It’s a dice game then when the button is clicked two dice roll and the textbox says “player 1 rolls” until the two dice match like 6-6 or 2-2 etc.
- from which the textbox then says “player 1 wins”.
- that’s all working sound, but now I want it to be 2 player, so after each click of the button it says
- click: player 1 rolls.
- Click: player 2 rolls.
- Click: player 1 rolls.
- Click player 2 rolls.
- Etc.
- Until someone wins.
- Heres the code snippet … any idea how to do it?*/
- int dice1;
- int dice2;
- int player = 1;
- TextView mText2;
- // Create a boolean variable which determines whos turn it is.
- // If isPlayer1Turn = false, then its GOT to be players 2 turn, and vice versa.
- // Set the default value to true, so player 1 goes first.
- boolean:isPlayer1Turn = true;
- // Player has won because dice1 and dice2 match.
- if (dice1 == dice2) {
- mText2.setText("Player " + player + " wins");
- }else if (dice1 != dice2) { // Dice do not match, set it to player 2's turn.
- // It WAS players 1s turn, so now its player 2's turn
- if(isPlayer1Turn == true) {
- mText2.setText("Player 2 rolls!");
- isPlayer1Turn = false;
- }else{ // It WAS player 2s turn, but now its player 1s turn!
- isPlayer1Turn = true;
- mText2.setText("Player 1 rolls!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment