Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**Author:Paige Hill
- * s5060971
- * week 20 task3
- * this program is the craps game. The user runs the program and 2 dices will
- * generate a random number which will then be added together
- * once this has been done, the user will then win or lose depending on which number they receive.
- * a winning number is 7 or 11
- * a losing number is 2,3 or 12 and any other number will just keep the program running and offer the user a second go.
- */
- import java.util.Scanner;
- public class Craps {
- Dice dice1 = new Dice();
- Dice dice2 = new Dice();
- int score;
- String userinput;
- // throws two dice
- public void shoot(){
- dice1.roll();
- dice2.roll();
- }
- //calculate score
- public int calculateScore(){
- score = dice1.getFaceValue() + dice2.getFaceValue();
- return score;
- }
- //display details
- public void displayDetails(){
- System.out.println("Dice 1 " + dice1.getFaceValue());
- System.out.println("Dice 2 " + dice2.getFaceValue());
- System.out.println("Score is " + score);
- }
- public static void main(String [] ars){
- Craps craps = new Craps();
- Scanner scan = new Scanner(System.in);
- int userChoice = 0;
- do {
- craps.shoot();
- craps.calculateScore();
- craps.displayDetails();
- if ((craps.calculateScore() == 7) || (craps.calculateScore() == 11)){
- System.out.println("Winning Throw!");
- }
- else if ((craps.calculateScore() == 2) || (craps.calculateScore() == 3) || (craps.calculateScore() == 12)){
- System.out.println("Losing Throw:(");
- }
- System.out.println("press 0 to stop press 1 to continue ");
- userChoice = scan.nextInt();
- }while(userChoice != 0);
- scan.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement