Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1.     // This method bubble sorts an array of Player objects using the value stored in the player's dice object
  2.     // If 2 or more players roll the same, those dice are re-rolled, and placed after the set players
  3.     static void sortPlayers() {
  4.         for (Player player : players) {
  5.             player.die.roll();
  6.         }
  7.         Player temp;
  8.         boolean sorted;
  9.         for (int i = 0; i < players.length; i++) {
  10.             sorted = true;
  11.             for (int j = 1; j < (players.length-i); j++) {
  12.                 if (players[j-1].die.getValue() > players[j].die.getValue()) {
  13.                     temp = players[j-1];
  14.                     players[j-1] = players[j];
  15.                     players[j] = temp;
  16.                     sorted = false;
  17.                 }
  18.             }
  19.         }
  20.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement