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

/**
 * CIS 284 Assignment 2
 *   One-player, one-turn version of the dice game Pig.
 * 
 * @author nerdkid93
 *
 */
public class PigSolitaire {

	/**
	 * 
	 * Runs a single game of PigGame for one player. Player's
	 *   score starts at 0; they roll.  The value of the roll
	 *   is added to their score, and they choose whether to 
	 *   roll again.  If at any point they roll a 1, their
	 *   score is set to 0 and their turn ends. They continue
	 *   playing the game until they reach 100 points.
	 * 
	 * @param args command line arguments (ignored)
	 */
	public static void main(String[] args) {
		Random random = new Random();
		Scanner scanner = new Scanner(System.in);

		int numTurn = 0;
		int turnScore = 0;
		int gameScore = 0;
		//double holdAmount = 0;
		boolean turnQuit = false;

		// Runs the game.
		while (gameScore < 100) {
			
			numTurn++;
			System.out.println("Turn " + numTurn);
			System.out.println("Your overall score is " + gameScore + ".");
			turnQuit = false;
			turnScore = 0;
			
			// Runs each turn.
			while (turnQuit == false) {
				int rollScore = random.nextInt(6) + 1;

				if (rollScore == 1) {
					System.out.println("You rolled a pig.");
					turnScore = 0;
					turnQuit = true;
				}
				else {
					turnScore = turnScore + rollScore;

					System.out.println("Your score for this turn is " + turnScore + ".");
					System.out.println("Do you want to roll again?");

					String response = scanner.next();
					if (response.toLowerCase().startsWith("n")) {
						turnQuit = true;
					}
				}
			}
			
			gameScore += turnScore;
			System.out.println("Your final score for the turn is " + turnScore + ".");
			System.out.println();
		}

		System.out.println("Your final score for the game is " + gameScore + ".");
		System.out.println("It took you " + numTurn + " turns to reach 100.");
	}
}
