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.");
        }
    }
}

Recommended Answers

All 4 Replies

There needed more code

and 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.

how do you expect us to be of assistance?

Sorry.

The output of the code must be like this:

Starting Doubles ... 
die1  die2 
***** ***** 
2     4 
3     2 
1     3 

Your score = 0 

Or:

Starting Doubles ... 
die1  die2 
***** ***** 
3     3 
6     1 
5     2 

Your score = 1 

Or:

Starting Doubles ... 
die1  die2 
***** ***** 
3     3 
6     6 
2     2 

Your score = 3 

I must use the following tips that are provided:
-use either printf of String.format() to manage two column layout
-use a for loop to control the throw of the two Die
-each iteration will involve throwing two die and displaying the resulting values
-use System.out.print if you don’t want to break the line display

I need to know what the puesdo code for it?
And I need to figure out how to make the code show the output shown above?

the pseudo code?

set total to 0

while ( total != 6 )
  get die1
  get die2
  print die1   die2
    if die1 == die2
      add 1 to total
end-while

print your score

this in your code should worry you, though:

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;
            }
        }

do you understand why the second while loop will never (ever) execute?
if not: you only get out of the first if gameOver is true.
hence, the condition of your second while (not gameOver) will never be true, so the iteration will never run.

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.