/** * Lab7.java * Course: SE1011 * Term: Fall 2015 * Assignment: Lab 7 * Author: Anonymous * Date: 10/21/2015 */ package class8_3_Elevens; import java.util.Scanner; /** * A Game to be played using the Die.java random die generator * * The player rolls a ten-sided die and a six-sided die,attempting to get as close to 11 as possible without * going over. If the player gets 11 exactly, they * automatically win, but if they go over 11, the computer automatically wins. After both dies have been * rolled once, one of them can be rolled again to attempt a better total. The computer will always re-roll * the smaller die if they have a lower score than the human player. * */ public class Lab7 { public static void main(String[] args) { Player human = new Player("You"); Player computer = new Player("The computer"); Scanner in = new Scanner(System.in); String rollSelect; //selects which die to re-roll on the menu String roll; //selects to roll the dice or not System.out.println("Welcome to Eleven, the game where the player rolls a ten-sided die and a six-sided die,\n " + "attempting to get as close to 11 as possible without going over. If the player gets 11 exactly, they\n " + "automatically win, but if they go over 11, the computer automatically wins. After both dies have been\n " + "rolled once, one of them can be rolled again to attempt a better total. The computer will always re-roll\n " + "the smaller die if they have a lower score than the human player.\n "); System.out.println("Enter r to roll the dice or q to quit"); roll = in.next(); if (roll.equals("r") || roll.equals("R")) { do { System.out.println("You rolled the dice:"); human.initialRoll(); if (!human.isMidgameLooser() && !human.isMidgameWinner()) { System.out.println("Enter 6 to re-roll the six-sided die, 1 to re-roll the ten sided die, or 0 to keep the current rolls."); rollSelect = in.next(); switch (rollSelect.charAt(0)) { case '6': human.reRollOneDie(1); break; case '1': human.reRollOneDie(2); break; case '0': break; } //end switch statement }//end player re-roll if statement if (!human.isMidgameLooser() && !human.isMidgameWinner()) { computer.initialRoll(); if (!computer.isMidgameLooser() && !computer.isMidgameWinner() && computer.getTotal() <= human.getTotal()) { System.out.println("The computer is re-rolling the six-sided die."); computer.reRollOneDie(1); }//end computer re-roll if statement } //end computer roll if statement if (human.isMidgameLooser() || human.getTotal() < computer.getTotal()) { System.out.println("Sorry, You Lose! Try Again Later!"); } else { System.out.println("Congratulations! You Won!"); } System.out.println("Play Again? Enter r to play again or q to quit"); roll = in.next(); }while (roll.equalsIgnoreCase("r")); } // end roll if statement else if (roll.equals("q") || roll.equals("Q")){ System.out.println("Exiting the program, Thanks for playing!"); } //end roll q else if statement else { System.out.println("Invalid entry, restart the program and try again."); } System.out.println("Exiting the program, Thanks for playing!"); } //end main method } //end class Lab7