CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 2006
    Posts
    102

    Horizontal output?

    So I'm writing a dice game that displays 5 dice on the screen at one time. Part of my code looks like this:

    diceshow();
    diceshow();
    diceshow();
    diceshow();
    diceshow();

    This function determines the random value of five dice and displays the 5 ascii dice on the screen. The output looks roughly like this:

    Code:
    ---------
    I         I
    I   O    I 
    I-------I
    
    ---------
    I      O I
    I O      I 
    I-------I
    
    ---------
    I         I
    I   O    I 
    I-------I
    That is, the dice are stacked vertically on the screen upon output. Lol, this would be fine, except the screen isn't big enough to display all five of the dice onscreen.

    Is there a way to skip the newline somehow so that that the output comes out horizontally like this:

    Code:
    ---------    --------     ---------
    I         I    I     O I    I        I
    I   O    I   I O     I     I   O  I
    I-------I    I-------I    I------I
    (Sorry for the god-awful dice here--don't have time to edit them perfectly here )

    Thanks!

  2. #2
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Horizontal output?

    Not using standard IO, unless you want to majorly re-write your die-drawing function to only do one line at a time. Platform-specific console routines may allow you to do this more easily.

  3. #3
    Join Date
    Apr 2004
    Posts
    102

    Re: Horizontal output?

    Do your loops so you iterate by row and by die number, with an array holding the roll values. Make a function that will draw a given row (but not every row) for a given roll value.

    Maybe this code snippet will explain better, I'll leave the rest of the implementation up to you:
    Code:
    for(int row=0; row<numRows; ++row)
    {
    	for(int dieNum=0; dieNum<numDice; ++dieNum)
    	{
    		drawRow(diceValueArray[dieNum],row);
    		cout<<" ";
    	}
    	cout<<endl;
    }

  4. #4
    Join Date
    May 2006
    Posts
    102

    Re: Horizontal output?

    Awesome, thanks. I'll see what I can do

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured