So I'm making a Yahtzee game for my java class with lots of methods and such, so close to being finished but this one part is causing me quite the headache and I would love help. I won't bother posting all my code since it shouldn't be necessary...and I don't want other students copying it = D.
This is my method that allows the user to choose which dice to throw again (if any) and I want it to end reading the input when the user presses the enter key. I understand that the Scanner class can't record keystrokes and I need to somehow incorporate nextLine() but I can't for the life of me figure it out.....any help or input would be great, thanks.
Ouput should look like:
Welcome to Yahtzee!
1 1 1 6 6
List which die to throw again: 1 2 3
5 2 5 6 6
This is chance.
Would you like to throw again(yes/no)? no
Edited by Mullinz - 11/27/11 at 11:53am
This is my method that allows the user to choose which dice to throw again (if any) and I want it to end reading the input when the user presses the enter key. I understand that the Scanner class can't record keystrokes and I need to somehow incorporate nextLine() but I can't for the life of me figure it out.....any help or input would be great, thanks.
Code:
public static void throwAgain(int dice){
Scanner input = new Scanner(System.in);
int a = 0, b = 0;
int redo = new int;
System.out.print("List which die to throw again: ");
while (input.hasNextInt() == true){
b = input.nextInt();
while(b 5 || redo.length > 6){
System.out.println("Illegal die!");
System.out.print("List which die to throw again: ");
b = input.nextInt();
}
redo = b;
a++;
}
for(int i = 0; i < 5; i++){
if(redo == 1)
dice = (int)(6*Math.random() + 1);
else if(redo == 2)
dice = (int)(6*Math.random() + 1);
else if(redo == 3)
dice = (int)(6*Math.random() + 1);
else if(redo == 4)
dice = (int)(6*Math.random() + 1);
else if(redo == 5)
dice = (int)(6*Math.random() + 1);
}
}
Ouput should look like:
Welcome to Yahtzee!
1 1 1 6 6
List which die to throw again: 1 2 3
5 2 5 6 6
This is chance.
Would you like to throw again(yes/no)? no
Edited by Mullinz - 11/27/11 at 11:53am





