So my array currently assign 5 instances of a dice object. My issue is that I have another class that needs to lock a dice from use.
public class Yahtzee {
OneDice[] dice = new OneDice[5];
public Yahtzee() {
yahtzeeRoll(); //constructor
}
public void yahtzeeRoll() {
for (int i = 0; i != dice.length; i++) {
dice[i] = new OneDice();
}
public void lock(int which) {
dice[which - 1].lockDice();
}
}
however my dice[i] = new OneDice(); creates a whole new set of random numbers each time yahtzeeRoll is called.
here is the method passing the which parameter.
@Override
public void choose() {
int which;
Scanner sc = new Scanner(System.in);
System.out.println(getName() + " Rolling.");
hand.printYahtzee();
System.out.println("Would you like to lock dice 1? 1 for yes");
choice = sc.nextInt();
if (choice == 1) {
which = 1;
hand.lock(which);
}
how can I assign a random value to each dice index without creating a brand new set of rolls that negates the lock. At least that appears to be the issue to me?