Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.50 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. // Creating player objects.
  17. BoardGameTest PlayerOne = new BoardGameTest(0, 'A');
  18. BoardGameTest PlayerTwo = new BoardGameTest(0, 'B');
  19. BoardGameTest PlayerThree = new BoardGameTest(0, 'C');
  20. BoardGameTest PlayerFour = new BoardGameTest(0, 'D');
  21.  
  22. // Display all player's position at the end of each round
  23. do {
  24. PlayerOne.diceRoll();
  25. PlayerTwo.diceRoll();
  26. PlayerThree.diceRoll();
  27. PlayerFour.diceRoll();
  28. counter++;
  29.  
  30. System.out.printf("\nPlayer %s is currently at position %d.\n", PlayerOne.name(), PlayerOne.getPosition());
  31. System.out.printf("Player %s is currently at position %d.\n", PlayerTwo.name(), PlayerTwo.getPosition());
  32. System.out.printf("Player %s is currently at position %d.\n", PlayerThree.name(), PlayerThree.getPosition());
  33. System.out.printf("Player %s is currently at position %d.\n", PlayerFour.name(), PlayerFour.getPosition());
  34. //System.out.printf("---------------End of Round %d Results---------------\n", counter);
  35.  
  36. int n=0;
  37. while (n<20) {
  38.  
  39. if (n==PlayerOne.getPosition())
  40. System.out.printf("%s",PlayerOne.name());
  41.  
  42. if (n==PlayerTwo.getPosition())
  43. System.out.printf("%s",PlayerTwo.name());
  44.  
  45. if (n==PlayerThree.getPosition())
  46. System.out.printf("%s",PlayerThree.name());
  47.  
  48. if (n==PlayerFour.getPosition())
  49. System.out.printf("%s",PlayerFour.name());
  50.  
  51. if (n!=PlayerOne.getPosition() && n!=PlayerTwo.getPosition() && n!=PlayerThree.getPosition() && n!=PlayerFour.getPosition())
  52. System.out.print("-");
  53.  
  54. n++;
  55. }
  56.  
  57.  
  58. }while(PlayerOne.getPosition() < 20 && PlayerTwo.getPosition() < 20 && PlayerThree.getPosition() < 20 && PlayerFour.getPosition() < 20);
  59.  
  60. //After someone has reached the end
  61. if( PlayerOne.getPosition() >= 20) {
  62. System.out.println("Player " +PlayerOne.name() + " has reached the end first!");
  63. }
  64. else if ( PlayerTwo.getPosition() >= 20) {
  65. System.out.println("Player " +PlayerTwo.name() + " has reached the end first!");
  66. }
  67. else if ( PlayerTwo.getPosition() >= 20) {
  68. System.out.println("Player " +PlayerTwo.name() + " has reached the end first!");
  69. }
  70. else if ( PlayerTwo.getPosition() >= 20) {
  71. System.out.println("Player " +PlayerTwo.name() + " has reached the end first!");
  72. }
  73.  
  74. System.out.println("Thanks for playing! Bye.");
  75.  
  76. kb.close();
  77.  
  78. } //end of main
  79.  
  80. } //end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement