I almost finished coding the user's turn, but I don't know how to allow the user to give up the dice to the computer. I am not exactly sure what I need to to in order for this to happen but I am guessing that you need to somehow activate another loop in the loop that the user is using. If this way won't work, what can I do to make it work?
Here are the variable declarations:
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner;
- public class FourFive
- {
- public static void main (String[] args)
- {
- Pigs myopp = new Pigs();
- Scanner scan = new Scanner (System.in);
- final int Round = 20;
- int num1 = 0, num2 = 0;
- int playerTotal = 0;
- int compTotal = 0;
- int win = 100;
- int turnOver = 1;
- Pigs die1 = new Pigs();
- Pigs die2 = new Pigs();
- int play;
- int playerTotal = 0;
- int compTotal = 0;
- int win = 100;
- int turnOver = 1;
- Pigs die1 = new Pigs();
- Pigs die2 = new Pigs();
- int play;
Expand|Select|Wrap|Line Numbers
- System.out.println("Type 1 to roll, type 2 to turn over the dice");
- play = scan.nextInt();
- while (play != 0)
- {
- for (int roll = 1; roll <= 6; roll++)//6 sided die
- {
- num1 = die1.roll();
- num2 = die2.roll();
- int points = num1 + num2;
- System.out.println("You roll " + num1 + " and " + num2);
- if (num1 == 1 && num2 == 1) {
- playerTotal = 0;
- System.out.println("You lose control of the dice and lose all points");
- play = 2;// trying to make the computer roll
- }
- else if (num1 != 1 && num2 != 1) {
- playerTotal += points;
- System.out.println("you earned " + points + " this round");
- play = 2;//trying to make the computer roll
- }
- else
- System.out.println("No additional points added, you lose control of the dice");
- if (play == 2)
Expand|Select|Wrap|Line Numbers
- while (play == 2)//computers turn
- {
- int roundTotal = num1 + num2;//Not sure what loops to use
- while (roundTotal <= 20)//total number of points for each round
- {
- for (int roll = 1; roll <= 6; roll++)//six sided die
- {
- num1 = die1.roll();
- num2 = die2.roll();
- System.out.println("Computer rolls " + num1 + " and " + num2);
- if (num1 == 1 && num2 == 1) {
- compTotal = 0;
- System.out.println("Computer loses control of the dice and loses all points, Your turn");
- play = 1;//trying to make player roll
- }
- else if (num1 != 1 && num2 != 1) {
- compTotal += roundTotal;
- System.out.println("Computer earned " + roundTotal + " this round");
- play = 1;//trying to make player roll
- }
- else {
- System.out.println("Computer gained no additional points, your turn");
- }
- System.out.println("Computer has a total of " + compTotal);
- }
- }
- }
- System.out.println("Type anything to roll (0 to quit)");
- play = scan.nextInt();
- }
- }