Advertisement
Guest User

Untitled

a guest
Feb 7th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 KB | None | 0 0
  1. package dicegame;
  2.  
  3. import java.util.Random;
  4. import java.util.Scanner;
  5.  
  6. /**
  7. *
  8. * @author Zaki
  9. */
  10. public class DiceGame {
  11.  
  12. static Scanner L = new Scanner(System.in);
  13. static int diceroll;
  14. static Random rand = new Random();
  15. static int diceroll2;
  16. static int p1Score;
  17. static int p2Score;
  18. static int roundScore;
  19.  
  20. /**
  21. * @param args the command line arguments
  22. */
  23. public static void main(String[] args) {
  24.  
  25. int option;
  26. System.out.println("Welcome to the Dice Game!");
  27. do {
  28.  
  29. System.out.println("______________________________");
  30. System.out.println("Main Menu");
  31. System.out.println("Choose from the following options: \n 1 Register to play \n 2 Log in to play \n 3 Hi-Scores \n 4 End game");
  32. System.out.println("Enter the preferred number");
  33.  
  34. option = L.nextInt();
  35.  
  36. switch (option) {
  37. case 1:
  38. Register();
  39. break;
  40. case 2:
  41. LogIn();
  42. break;
  43. case 3:
  44. HiScore();
  45. break;
  46. case 4:
  47. EndGame();
  48. break;
  49. default:
  50. System.out.println("Invalid Option");
  51. break;
  52. }
  53. } while (option > 4 || option <= 3);
  54.  
  55. }
  56.  
  57. private static void Register() {
  58. System.out.println("_______________________________");
  59. System.out.println("Register to play \n Please enter your Username:");
  60. System.out.println("Please enter your Password");
  61.  
  62. }
  63.  
  64. private static void LogIn() {
  65. System.out.println("Player 1 enter your username:");
  66. System.out.println("Player 2 enter your password:");
  67. System.out.println("Player 1 enter your username:");
  68. System.out.println("Player 2 enter your password:");
  69. game();
  70. }
  71.  
  72. private static void HiScore() {
  73. System.out.println("INSERT TABLE HERE BRO");
  74. }
  75.  
  76. private static void EndGame() {
  77. System.out.println("Thank you for playing the Dice Game!");
  78. }
  79.  
  80. private static void game() {
  81. System.out.println("Lets play! \n Player 1 Press X to roll the dice");
  82. L.skip("\n");
  83. int dice1, dice2;
  84. char roll = L.nextLine().charAt(0);
  85. if (roll == 'x') {
  86. dice1 = diceRoll();
  87. dice2 = diceRoll();
  88. p1Score = dice1 + dice2;
  89. System.out.println("You rolled a " + dice1 + " and a " + dice2);
  90. p1Score = oddEven(p1Score);
  91. System.out.println("Your score is: " + p1Score);
  92.  
  93. }
  94.  
  95.  
  96. System.out.println("Player 2 turn \n Press x");
  97. char roll2 = L.nextLine().charAt(0);
  98. if (roll == 'x') {
  99. dice1 = diceRoll();
  100. dice2 = diceRoll();
  101. p2Score = dice1 + dice2;
  102. System.out.println("You rolled a " + dice1 + " and a " + dice2);
  103. p2Score = oddEven(p2Score);
  104. System.out.println("Your score is: " + p2Score);
  105.  
  106. }
  107. }
  108.  
  109. public static int diceRoll() {
  110. return diceroll = rand.nextInt(6) + 1;
  111. }
  112.  
  113. private static int oddEven(int Score) {
  114.  
  115. if (Score % 2 == 0) {
  116. Score = Score + 10;
  117. } else {
  118. Score = Score - 5;
  119. }
  120. System.out.println(Score);
  121. return Score;
  122. }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement