Here, try this for a trowing-routine (for one die):
Where MAXIMUM and MINIMUM are the maximum and minimum number of eyes on the die, respectivly. For a normal die, these would be 6 and 1.Code:double throw = Math.random(); dice1 = (int) Math.ceil((throw*(MAXIMUMEYES-MINIMUMEYES+1)+(MINIMUMEYES-1)));
If you feel up to it, you could even create a seperate die-class. In your program, you would create two instances of the class. The class could look something like this:
Code:import java.lang.Math; public class Die { private static final int MINIMUMEYES = 1; // minimum number of eyes on the die private static final int MAXIMUMEYES = 6; // maximum number of eyes on the die private int eyes; // Represents number of eyes trown public int getEyes() // value: eyes { return eyes; } public void roll() // action: roll the die, and set any value out of {1,2,3,4,5,6} in eyes { double throw1 = Math.random(); eyes = (int) Math.ceil((throw1*(MAXIMUMEYES-MINIMUMEYES+1)+(MINIMUMEYES-1))); } }




Reply With Quote