Results 1 to 7 of 7
Thread: Help with horizontal output
- 01-27-2011, 05:32 PM #1
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
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:
- 01-27-2011, 06:10 PM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Using System.out.print instead of System.out.println should work.
- 01-27-2011, 06:24 PM #3
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
print still prints it out vertically
- 01-27-2011, 06:26 PM #4
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!
- 01-27-2011, 07:01 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
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:
You decide how you want to print individual lines of individual dice.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 }
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 01-27-2011, 07:47 PM #6
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Start with this:
Then write a method:Java Code:private static final String[][] diceStrings = { { "- - - - -", "- -", "- * -", "- -", "- - - - -" }, { "- - - - -", "- * -", "- -", "- * -", "- - - - -" }, { "- - - - -", "- * -", "- * -", "- * -", "- - - - -" }, { "- - - - -", "- * * -", "- -", "- * * -", "- - - - -" }, { "- - - - -", "- * * -", "- * -", "- * * -", "- - - - -" }, { "- - - - -", "- * * -", "- * * -", "- * * -", "- - - - -" } };
You should be able to figure out the rest with a simple nested loop.Java Code:public void displayDice(int[] dice) { ... }
-Gary-
- 01-28-2011, 05:00 PM #7
Member
- Join Date
- Jan 2011
- Posts
- 9
- Rep Power
- 0
Similar Threads
-
how to get the resultset output into an output file
By renu in forum New To JavaReplies: 0Last Post: 09-30-2010, 08:16 PM -
Print Horizontal Bars
By xstrandedx7688 in forum New To JavaReplies: 3Last Post: 03-31-2010, 04:52 AM -
Java, output string, getting correct output? HELP!
By computerboyo in forum New To JavaReplies: 2Last Post: 02-25-2009, 11:44 PM -
JFileChooser horizontal scrollbar problem
By nenadm in forum AWT / SwingReplies: 4Last Post: 11-12-2008, 11:16 AM -
How to use vertical and horizontal sliders in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:06 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks