Search code examples
javadice

Change the eye of a dice


School gave me the assignment to make a dice game where the user can change the eye of the Dice, the only hint they gave me was using the ASCII table..

This is my code so far and i'm hitting a brick wall as how i can make the numbers be the input of the user (I'm not very creative):

 System.out.println("Which character should be used as the eye of the dice:");
    char eyeDice = input.next().charAt(0);
    System.out.println(eyeDice);


    int Dice;
    Dice = (int)(Math.random()* 6 + 1);

    while (Dice < 6) {
        Dice = (int)(Math.random()* 6 + 1);
        System.out.println(Dice);

    }

The output of the code looks as follows:

Which character should be used as the eye of the dice:
$
$
1
4
1
1
1
1
4
1
2
2
6

Process finished with exit code 0

This is what it should end up looking like:

Which character should be used as the eye of the dice:

#
  #
    #

#   #
  #
#   #

#   #

#   #
#   #
#   #


Process finished with exit code 0

Any tips or hints in the right direction would be greatly appreciated!


Solution

  • Computers do not ship with code to turn the digit '4' into an ascii drawing.

    You'd have to write this yourself. I suggest drawing these out on a piece of paper. In your java code, you can have a bunch of if/elseif statements, one for each of the 6 faces. Each block would print 3 lines. Start by locking in the character to use for the eye, then work on making that something the user can configure later.

    Here's part of it to get you started:

    if (dieRoll == 5) {
        System.out.println("* *");
        System.out.println(" * ");
        System.out.println("* *");
    } else if (dieRoll == 6) {
        // you figure it out from here...