Note that there are some explanatory texts on larger screens.

plurals
  1. POPlacing simple char markers in a board of array for a simple candy crush game
    primarykey
    data
    text
    <p>I am a first year degree student in ICT and my assignment requires me to develop a simple candy crush game.</p> <p>So my issue right now is to print the markers( i.e <code>"|"</code> and <code>"_"</code> ) that surrounds the number at <code>board[5][5]</code> when the program initialize.</p> <p>Here is my code:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; //FUNCTION: Draw the Board int drawBoard() { //Declare array size int board[9][9]; //initialize variables int rows, columns, randomNumber, flag; //random number seed generator srand(time(NULL)); for ( rows = 0 ; rows &lt; 9 ; rows++ ) { for ( columns = 0 ; columns &lt; 9 ; columns++ ) { flag = 0; do { //generate random numbers from 2 - 8 randomNumber = rand() %7 + 2; board[rows][columns] = randomNumber; //Checks for 2 adjacent numbers. if ( board[rows][columns] == board[rows - 1][columns] || board[rows][columns] == board[rows][columns - 1] ) { flag = 0; continue; } else { flag = 1; printf( " %d ", board[rows][columns] ); } } while ( flag == 0 ); }//end inner for-loop printf("\n\n"); }//end outer for-loop marker(); }//end FUNCTION drawBoard //FUNCTION: Mark the surrounding of the number with "|" and "_" at board[5][5] void marker() { printf( " _ \n" ); printf( "|%c|\n", a ); printf( " _ \n" ); } int main() { drawBoard(); } </code></pre> <p>So...yeah I'm stuck at this part:</p> <pre><code>printf( "%c" , drawBoard(board[5][5]) ); printf( "\n\n%c" , drawBoard( board[5][5]) ); </code></pre> <p>Well I guess I am just weak at function. I want to create a separate function( <code>i.e void marker()</code> ) that can be called in the <code>drawBoard</code> function, and then have function <code>marker()</code> to mark the surrounding area of the number at coordinate <code>board[5][5]</code>.</p> <p>Am I thinking and doing it in a wrong way? Please advice.</p> <p>Sam</p> <p>EDIT 1: Thanks for the help haccks! Yeah I think I understand the basic usage of function now. The remaining problem is that even though I called <code>marker( board[5][5] )</code> from <code>drawBoard()</code>, the printing of the marker <strong>does not happen</strong> on the number that is placed in board[5][5].</p> <p>The marker is printed after the board is printed. Any idea why this happens? By right it should be printed at the coordinate [5][5] :/</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload