Schiarizzi

Craps Machine in Java

Apr 3rd, 2014
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. import java.lang.String;
  2. import java.util.Scanner;
  3.  
  4. public class CrapTableMachine{
  5.  
  6. public static(String []) {
  7.  
  8. Scanner.input = new Scanner;
  9. int dice1 = 0, dice2 = 0, starter, addedRoll;
  10. String nameOfRoll;
  11.  
  12. System.out.print("\f"); \\clear the field
  13. System.out.print("Welcome to the Craps Table!\n"); \\ Title
  14. System.out.print("Enter anything to roll or 0 to quit: ");
  15. starter = input.nextInt();
  16.  
  17. \\Get the random numbers for the dice.
  18. dice1 = 1 + (int)(Math.random() * ((6 - 1) + 1));
  19. dice2 = 1 + (int)(Math.random() * ((6 - 1) + 1));
  20. addedRoll = dice1 + dice2;
  21.  
  22. \\waits for the player to enter anything showing that they are ready. If they enter 0 the program ends.
  23. do{
  24. if(addedRoll == 12){nameOfRoll = "Box-Cars!"; }
  25. else if(addedRoll == 11){nameOfRoll = "Yo-Leven!"; }
  26. else if(addedRoll == 2){nameOfRoll = "Snake Eyes!"; }
  27. else if(addedRoll == 3){nameOfRoll = "Ace-Duece!"; }
  28. else if(addedRoll == 5){nameOfRoll = "Fever Five!"; }
  29. else if(addedRoll == 7){nameOfRoll = "Seven out!"; }
  30. else if(addedRoll == 9){nameOfRoll = "Nina!"; }
  31.  
  32. if(addedRoll == 4){ if(dice1 == dice2){nameOfRoll = "Hard Four!";}else{nameOfRoll = "Easy Four!";} }
  33.  
  34. else if(addedRoll == 6){if(dice1 == dice2){nameOfRoll = "Hard Six!";}else{nameOfRoll = "Easy Six!";} }
  35.  
  36. else if(addedRoll == 8){if(dice1 == dice2){nameOfRoll = "Hard Eight!";}else{nameOfRoll = "Easy Eight!";} }
  37.  
  38. else if(addedRoll == 10){if(dice1 == dice2){nameOfRoll = "Hard Ten!";}else{nameOfRoll = "Easy Ten!";} }
  39.  
  40.  
  41. System.out.print("" + dice1); \\ Show dice rolls and what they are called.
  42. System.out.print("" + dice2);
  43. System.out.print("" + nameOfRoll);
  44.  
  45. starter = 0;
  46. }while (starter != 0);
  47.  
  48. System.out.print("\n" + "Game Over.");
  49.  
  50.  
  51.  
  52. }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment