Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This method bubble sorts an array of Player objects using the value stored in the player's dice object
- // If 2 or more players roll the same, those dice are re-rolled, and placed after the set players
- static void sortPlayers() {
- for (Player player : players) {
- player.die.roll();
- }
- Player temp;
- boolean sorted;
- for (int i = 0; i < players.length; i++) {
- sorted = true;
- for (int j = 1; j < (players.length-i); j++) {
- if (players[j-1].die.getValue() > players[j].die.getValue()) {
- temp = players[j-1];
- players[j-1] = players[j];
- players[j] = temp;
- sorted = false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement