Results 1 to 7 of 7
  1. #1
    IdrinkJava is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default Help with horizontal output

    im attempting to make a yhatzee style dice game in netbeans. I want my output to be displayed horizontally instead of vertically, I've searched around the forms but this seems to be more complex than most horizontal outputs due to the multiple strings that im trying to print.

    My code is as follows:

    for(int x=0;x<5;x++)
    {
    int i = rndm.nextInt(6);

    switch (i)
    {
    case 0:
    card = "- - - - -\n- -\n- * -\n- -\n- - - - -";
    System.out.println(card);
    break;

    case 1:
    card = "- - - - -\n- * -\n- -\n- * -\n- - - - -";
    System.out.println(card);
    break;

    case 2:
    card = "- - - - -\n- * -\n- * -\n- * -\n- - - - -";
    System.out.println(card);
    break;

    case 3:
    card = "- - - - -\n- * * -\n- -\n- * * -\n- - - - -";
    System.out.println(card);
    break;

    case 4:
    card = "- - - - -\n- * * -\n- * -\n- * * -\n- - - - -";
    System.out.println(card);
    break;

    case 5:
    card = "- - - - -\n- * * -\n- * * -\n- * * -\n- - - - -";
    System.out.println(card);
    break;




    }

    }
    }
    }

    and my output appears as:
    Attached Thumbnails Attached Thumbnails Help with horizontal output-diceoutput.jpg  

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Using System.out.print instead of System.out.println should work.

  3. #3
    IdrinkJava is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    print still prints it out vertically

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    There is no "easy" way to simply rotate the console output.

    You're going to have to write the code that prints it out how you want it to look, line by line. How you do that is really up to you.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,344
    Blog Entries
    7
    Rep Power
    20

    Default

    If you want to print the character images of four dice on the console you have to print the first line of them, next the second line of them etc. until the last line of those dice. That leads to the following loop structure:

    Java Code:
    for (line = 0; line < MAX_LINES; line++) { // print lines of all dice
       for (int die= 0; die < 4; die++) // print a line of a die
          // print 'line' of die 'die'
       System.out.println(); // this line is done
    }
    You decide how you want to print individual lines of individual dice.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Start with this:
    Java Code:
        private static final String[][] diceStrings = { { "- - - - -",
                                                           "-       -",
                                                           "-   *   -",
                                                           "-       -",
                                                           "- - - - -" },
                                                         { "- - - - -",
                                                           "- *     -",
                                                           "-       -",
                                                           "-     * -",
                                                           "- - - - -" },
                                                         { "- - - - -",
                                                           "- *     -",
                                                           "-   *   -",
                                                           "-     * -",
                                                           "- - - - -" },
                                                         { "- - - - -",
                                                           "- *   * -",
                                                           "-       -",
                                                           "- *   * -",
                                                           "- - - - -" },
                                                         { "- - - - -",
                                                           "- *   * -",
                                                           "-   *   -",
                                                           "- *   * -",
                                                           "- - - - -" },
                                                         { "- - - - -",
                                                           "- *   * -",
                                                           "- *   * -",
                                                           "- *   * -",
                                                           "- - - - -" } };
    Then write a method:
    Java Code:
        public void displayDice(int[] dice) {
            ...
        }
    You should be able to figure out the rest with a simple nested loop.

    -Gary-

  7. #7
    IdrinkJava is offline Member
    Join Date
    Jan 2011
    Posts
    9
    Rep Power
    0

    Default

    thanks everyone for these great responses, i will get right on it

Similar Threads

  1. Replies: 0
    Last Post: 09-30-2010, 08:16 PM
  2. Print Horizontal Bars
    By xstrandedx7688 in forum New To Java
    Replies: 3
    Last Post: 03-31-2010, 04:52 AM
  3. Java, output string, getting correct output? HELP!
    By computerboyo in forum New To Java
    Replies: 2
    Last Post: 02-25-2009, 11:44 PM
  4. JFileChooser horizontal scrollbar problem
    By nenadm in forum AWT / Swing
    Replies: 4
    Last Post: 11-12-2008, 11:16 AM
  5. Replies: 0
    Last Post: 07-02-2008, 08:06 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •