Hey all!
For a game I'm working on I need to determine the order of who goes first by rolling a pair of dice. I am stuck on the situation when two or more players roll the same number and would have to re-roll the dice. This is the code I am using that just implemts a dice roll for each player. An array of size numberOfPlayers is created to store the dice roll for each player. Index 1 refers to the first player to roll the dice, and index n would refer to the nth player to to roll the dice. How should I go about handleing the situation I stated above? Thanks for all your time!!!
private void diceRoll(int numPlayers)
{
int [] playerRoll = new int [numPlayers+1];
int die1; // Number showing on the first die.
int die2; // Number showing on the second die.
for(int player = 1; player < numPlayers; player++)
{
JOptionPane.showMessageDialog(null, "Player " + player +
" roll the dice to determine order.");
die1 = (int)(Math.random()*6) + 1; // Range 1-6
die2 = (int)(Math.random()*6) + 1;
int total = die1 + die2;
playerRoll[player] = total;
}
}