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
Recommended Answers
Jump to Postand what's your point?
…
we have no idea what your game 'doubles' is supposed to do, so we can't even verify that what you are doing so far is correct.
we also don't know what it is you don't have yet, or what is stopping you from writing that code.
All 4 Replies
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.