package die.java;
import java.util.Random;
class DieGame2 {
private final int sides;
private final Random generator = new Random();
public DieGame2(int s) {
sides = s;
}
public boolean throwDie() {
int faceValue = generator.nextInt(sides) + 1;
System.out.print(faceValue);
return faceValue == 6;
}
public static void main(String[] args) {
DieGame die1 = new DieGame(6);
DieGame die2 = new DieGame(6);
int score = 6;
boolean gameOver = false;
System.out.println("Starting Doubles...\n");
System.out.println("Die 1\tDie 2");
System.out.println("*****\t*****");
boolean gotSix;
while (!gameOver) {
gotSix = die1.throwDie();
if (!gotSix) score--;
System.out.println("\t" + score);
if (score == 0 || gotSix) {
gameOver = true;
}
}
while (!gameOver){
gotSix = die2.throwDie();
if(!gotSix) score--;
System.out.println("\t" + score);
if (score == 0 || gotSix) {
gameOver = true;
}
}
if (score > 0) {
System.out.println("\nYou've thrown a six!!! You win with a score of " + score + ".");
}
else {
System.out.println("\nSorry, you lose this time.");
}
}
}
MatthewYeend 0 Newbie Poster
MatthewYeend 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
MatthewYeend 0 Newbie Poster
stultuske 1,116 Posting Maven Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.