Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. public class DiceGame {
  2. public static void displayIntro() {
  3. System.out.println("The Game of Lucky Chances");
  4. System.out.println("A board game with 4 players and 20 squares.");
  5. System.out.println("Rolling an even space will result in moving forward with the resulting number and rerolling.");
  6. System.out.println("Rolling an odd number will result in moving back with the resulting number and ending turn.");
  7. System.out.println("-------------------------------");
  8. }
  9.  
  10. public static void main(String[] args) {
  11.  
  12. Scanner kb = new Scanner(System.in);
  13. int counter = 0; // counter for the rounds
  14. displayIntro();
  15.  
  16. System.out.println("");
  17.  
  18. // Creating player objects.
  19. BoardGameTest PlayerOne = new BoardGameTest(0, 'A');
  20. BoardGameTest PlayerTwo = new BoardGameTest(0, 'B');
  21. BoardGameTest PlayerThree = new BoardGameTest(0, 'C');
  22. BoardGameTest PlayerFour = new BoardGameTest(0, 'D');
  23.  
  24. // Display all player's position at the end of each round
  25. do {
  26. PlayerOne.diceRoll();
  27. PlayerTwo.diceRoll();
  28. PlayerThree.diceRoll();
  29. PlayerFour.diceRoll();
  30. counter++;
  31.  
  32. System.out.printf("\nPlayer %s is currently at position %d.\n", PlayerOne.name(), PlayerOne.getPosition());
  33. System.out.printf("Player %s is currently at position %d.\n", PlayerTwo.name(), PlayerTwo.getPosition());
  34. System.out.printf("Player %s is currently at position %d.\n", PlayerThree.name(), PlayerThree.getPosition());
  35. System.out.printf("Player %s is currently at position %d.\n", PlayerFour.name(), PlayerFour.getPosition());
  36. //System.out.printf("---------------End of Round %d Results---------------\n", counter);
  37.  
  38. int n=0;
  39. while (n<20) {
  40.  
  41. if (n==PlayerOne.getPosition())
  42. System.out.printf("%s",PlayerOne.name());
  43.  
  44. if (n==PlayerTwo.getPosition())
  45. System.out.printf("%s",PlayerTwo.name());
  46.  
  47. if (n==PlayerThree.getPosition())
  48. System.out.printf("%s",PlayerThree.name());
  49.  
  50. if (n==PlayerFour.getPosition())
  51. System.out.printf("%s",PlayerFour.name());
  52.  
  53. if (n!=PlayerOne.getPosition() && n!=PlayerTwo.getPosition() && n!=PlayerThree.getPosition() && n!=PlayerFour.getPosition())
  54. System.out.print("-");
  55.  
  56. n++;
  57. }
  58.  
  59.  
  60. }while(PlayerOne.getPosition() < 20 && PlayerTwo.getPosition() < 20 && PlayerThree.getPosition() < 20 && PlayerFour.getPosition() < 20);
  61.  
  62. //After someone has reached the end
  63. if( PlayerOne.getPosition() >= 20) {
  64. System.out.println("Player " +PlayerOne.name() + " has reached the end first!");
  65. }
  66. else if ( PlayerTwo.getPosition() >= 20) {
  67. System.out.println("Player " +PlayerTwo.name() + " has reached the end first!");
  68. }
  69. else if ( PlayerThree.getPosition() >= 20) {
  70. System.out.println("Player " +PlayerThree.name() + " has reached the end first!");
  71. }
  72. else if ( PlayerFour.getPosition() >= 20) {
  73. System.out.println("Player " +PlayerFour.name() + " has reached the end first!");
  74. }
  75.  
  76. System.out.println("Thanks for playing! Bye.");
  77.  
  78. kb.close();
  79.  
  80. } //end of main
  81.  
  82. } //end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement