displaying a 2d array of char '*'
im trying to display my array of type char on a screen, but its not working.
i have my world class:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
const int ROWS = 22;
const int COLUMNS = 75;
class World
{
private:
char world_array[COLUMNS][ROWS];
bool out_of_bounds( int col, int row, bool verbose = false );
public:
World();
void display( bool side_marks = false );
void create_life( int col, int row );
void kill_life( int col, int row );
//add additional functions here:
void generation( char world_array[COLUMNS][ROWS] );
};
|
my display function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
/*
Prints out the world (world_array)
@param side_marks if true, prints out axis numbers along the sides
if false, no numbers are printed
if not specified, then defaults to false
*/
void World::display( bool side_marks )
{
system("CLS");
if( side_marks )
{
for( int m = 0; m < COLUMNS; m++ )
{
if( m % 10 == 0 )
cout << (m / 10);
else
cout << ' ';
}
cout << endl;
for( int k = 0; k < COLUMNS; k++ ) cout << (k % 10);
cout << endl;
}
for( int row = 0; row < ROWS; row++ )
{
for( int col = 0; col < COLUMNS; col++ )
{
cout << world_array[col][row];
}
if( side_marks )
{
if( row % 10 == 0 ) { cout << ( row / 10 ); }
else { cout << ' '; }
cout << (row%10);
}
cout << endl;
}
}
|
my create life function:
1 2 3 4 5 6 7 8 9 10
|
/*
Adds life to a coordinate
@param col (0-74)
@param row (0-21)
*/
void World::create_life( int col, int row )
{
if( out_of_bounds( col, row, true ) ) return;
world_array[col][row] = '*';
}
|
and my main function:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
//2d world 75 by 22
cwin.coord(0,0,22,75);
char world_array[COLUMNS][ROWS];
World myWorld;
//initial cells
myWorld.create_life( init_cell_1_x, init_cell_1_y );
myWorld.create_life( init_cell_2_x, init_cell_2_y );
myWorld.create_life( init_cell_3_x, init_cell_3_y );
myWorld.create_life( init_cell_4_x, init_cell_4_y );
myWorld.create_life( init_cell_5_x, init_cell_5_y );
myWorld.create_life( init_cell_6_x, init_cell_6_y );
myWorld.create_life( init_cell_7_x, init_cell_7_y );
myWorld.create_life( init_cell_8_x, init_cell_8_y );
myWorld.create_life( init_cell_9_x, init_cell_9_y );
myWorld.create_life( init_cell_10_x, init_cell_10_y );
// display generation zero
myWorld.display();
|
what could be the issue of why its not displaying my life cells?
Topic archived. No new replies allowed.