Introduction

One more practice with loops. This program will be a bit more involved that the previous.

For this program, you will create a simulation of the dice game Pig.

The objective of the game is for players to gain 100 points before their opponents, further details will be discussed in the tasks.

In this case the opponent will be the computer.

Task 1

This game requires two 6-sided dice. You will need to simulate these dice with a random number generator.

The two dice (random number generators) must:

Produce values between 1-6
Have a seed of 140L and 340L, respectively for die one and die two (for testing purposes)
Task 2

Now that you have your dice, we can go over the rules you will be playing by.

Rules:

For each turn, the players will take turns rolling the two dice.
If a 1 doesn't appear on either dice, the values are added to the player's total. They then have the choice to roll again (choice 0) or pass the turn to the other player(choice 1).
If a 1 appears on one of the dice, the player gets no points added to their total for that entire turn and it becomes the other player's turn to roll (points earned on previous turns will still be present in their totals).
If a player rolls both 1s, the player's turn is over and their total is reset to 0.
You will need one more random number generator that will determine if the computer(0) or player(1) will go first. This will also be used to simulate the computer's choice to either roll again or pass the turn over. The seed for this generator will be 140L.

Assume valid input from the user.

Output should begin with the statement "Welcome of the Game of Pigs"

All following user prompts should look similar to:

Your turn (current points: 0)
You rolled 3 and 2, points earned this turn:5
Press 0 to roll again or 1 to start computer's turn
And all computer prompts should look like:

Computer's turn (current points: 0)
Computer rolled 1 and 4, no points earned and your turn
They announce which player's turn and current points.

Then numbers that were rolled by what player followed by

if points earned, display total points earned for that turn (see the user's prompt 2nd line)
if a one was rolled, announce no points earned and the next player's turn (see computer prompt 2nd line)
if both are ones, use display message "/whichever player/ rolled two ones, points reset and /opponent's/ turn"

```
import java.util.Scanner;
import java.util.Random;

public class GameOfPigs {
    public static void main(String[] args) {
        Random die1 = new Random(140L);
        Random die2 = new Random(340L);
        Random compDecision = new Random(140L);
        Scanner scnr = new Scanner(System.in);

        int computerTotal = 0;
        int playerTotal = 0;
        boolean playerTurn = true;

        // Decides who goes first...
        if ((compDecision.nextInt(2)) == 0) {
            playersTurn = false;
        }

        System.out.println("Welcome of the Game of Pigs");

        // Main game loop
        while (computerTotal < 100 && playerTotal < 100) {
            System.out.println();
            int currentPlayerPoints = 0;

            // Player's loop
            while (playersTurn) {
                System.out.println("Your turn (current points: " + playerTotal + ")");
                int roll1 = die1.nextInt(6) + 1;
                int roll2 = die2.nextInt(6) + 1;

                // First Rule...Not the same as the example in class!!!
                // Adjust accordingly!!!! Multiple ways to do this!!!!
                if (roll1 == 1 && roll2 == 1) {
                    playerTotal = 0;
                    playersTurn = false;
                    break;
                }

                // Second Rule
                else if (roll1 == 1 || roll2 == 1) {
                    playerTotal = playerTotal;
                    playersTurn = false;
                    break;
                }

                // Third Rule
                else {
                    playerTotal += currentPlayerPoints;
                    int choice = scnr.nextInt();
                    if (choice == 1) {
                        playerTotal += currentPlayerPoints;
                        playersTurn = false;
                        break;
                    }
                }
            }
            if (playerTotal >= 100) {
               break;
            }

            // 
            int currentCompPoints = 0;

            // Computer's loop
            while (!playersTurn) {
                System.out.println("Computer's turn (current points: " + computerTotal + ")");
                int roll1 = die1.nextInt(6)+1;
                int roll2 = die2.nextInt(6)+1;

                if (roll1 == 1 && roll2 == 1) {
                    computerTotal = 0;
                }
                else if (roll1 == 1 || roll2 == 1) {
                    computerTotal = computerTotal;
                }
                else {
                    int choice = compDecision.nextInt(2);
                    computerTotal += currentPlayerPoints;
                    }
                }
            }           
        }
        if (playerTotal > computerTotal) {
            System.out.println("Congratulations! You won!");
        }
        else {
            System.out.println("Too Bad, the computer won.");
        }
    }
}

GameOfPigs.java:86: error: illegal start of type
        if (playerTotal > computerTotal) {
        ^
GameOfPigs.java:86: error: <identifier> expected
        if (playerTotal > computerTotal) {
                       ^
GameOfPigs.java:86: error: ';' expected
        if (playerTotal > computerTotal) {
                         ^
GameOfPigs.java:86: error: illegal start of type
        if (playerTotal > computerTotal) {
                                       ^
GameOfPigs.java:86: error: <identifier> expected
        if (playerTotal > computerTotal) {
                                        ^
GameOfPigs.java:86: error: ';' expected
        if (playerTotal > computerTotal) {
                                          ^
GameOfPigs.java:87: error: illegal start of type
            System.out.println("Congratulations! You won!");
                  ^
GameOfPigs.java:87: error: ';' expected
            System.out.println("Congratulations! You won!");
                      ^
GameOfPigs.java:87: error: invalid method declaration; return type required
            System.out.println("Congratulations! You won!");
                       ^
GameOfPigs.java:87: error: illegal start of type
            System.out.println("Congratulations! You won!");
                               ^
GameOfPigs.java:89: error: class, interface, or enum expected
        else {
        ^
GameOfPigs.java:91: error: class, interface, or enum expected
        }
        ^
12 errors

```

---

Thanks! But now it says:

```
GameOfPigs.java:18: error: cannot find symbol
            playersTurn = false;
            ^
  symbol:   variable playersTurn
  location: class GameOfPigs
GameOfPigs.java:29: error: cannot find symbol
            while (playersTurn) {
                   ^
  symbol:   variable playersTurn
  location: class GameOfPigs
GameOfPigs.java:29: error: illegal start of type
            while (playersTurn) {
                  ^
GameOfPigs.java:38: error: cannot find symbol
                    playersTurn = false;
                    ^
  symbol:   variable playersTurn
  location: class GameOfPigs
GameOfPigs.java:45: error: cannot find symbol
                    playersTurn = false;
                    ^
  symbol:   variable playersTurn
  location: class GameOfPigs
GameOfPigs.java:55: error: cannot find symbol
                        playersTurn = false;
                        ^
  symbol:   variable playersTurn
  location: class GameOfPigs
GameOfPigs.java:68: error: cannot find symbol
            while (!playersTurn) {
                    ^
  symbol:   variable playersTurn
  location: class GameOfPigs
7 errors

```