void circuit() { int r, c; int do_cut; int radius; int centerx, centery; clear_invert_map(); grid = (char **) new_grid(map.num_row, map.num_col, sizeof(char)); count = (int *) new_array(map.num_row, sizeof(int)); radius = (map.sec_width > map.sec_height ? map.sec_width : map.sec_height)/4.0; radius = (radius == 0 ? 1 : radius ); line_size = (map.sec_width > map.sec_height ? map.sec_width : map.sec_height)/4.0; line_size = (line_size == 0 ? 1 : line_size); for( r = 0; r < map.num_row; r++ ) { count[r] = 0; for( c = 0; c < map.num_col; c++ ) { if( (r == 0 || r == map.num_row-1) && (c == 0 || c == map.num_col/2 || c == map.num_col-1) ) do_cut = 1; else do_cut = rand()%4; if( do_cut != 1 ) { grid[r][c] = 0; continue; } section_center(¢erx, ¢ery, r, c); circlefill(map.map, centerx, centery, radius, 255); grid[r][c] = 1; count[r]++; } } connect_rows(); connect_front(); connect_back(); connect_mid(); delete_grid((void **)grid, map.num_row); delete_array(count); /* redraw outline */ /* TODO: once in a while if cuts off the edge.. */ rect(map.map, 0, 0, map.width-1, map.height-1, 0); return; }
int main() { grid testG = new_grid(); printf("grid created\n"); delete_grid(testG); printf("grid deleted\n"); return 0; }
Board& Board::operator=(const Board& rhs) { if (this == &rhs) { return *this; } else { num_cols = rhs.num_cols; num_rows = rhs.num_rows; if (grid != NULL) { delete_grid(); } grid = new char*[num_cols]; for (int c = 0; c < num_cols; c++) { grid[c] = new char[num_rows]; for (int r = 0; r < num_rows; r++) { grid[c][r] = rhs.grid[c][r]; } } return *this; } }
int main() { grid testG = new_grid(); printf("grid created\n"); add_tile(testG); bool isGameOver = game_over(testG); if(isGameOver) // check if an empty grid is a gameover { return EXIT_FAILURE; } else printf("game not over with an empty grid\n"); // FILLING THE GRID WITH UNIQUE VALUES int k = 1; for(int i = 0; i < GRID_SIDE; i++) { for(int j = 0; j < GRID_SIDE; j++) { set_tile(testG, i, j, (tile)k); printf("[%d][%d]:%d\n", i, j, get_tile(testG, i, j)); k++; } } isGameOver = game_over(testG); if(!isGameOver) return EXIT_FAILURE; // check if it's game over with a grid filled with unique values else printf("gameover with a grid filled with unique values\n"); delete_grid(testG); printf("grid deleted\n"); return EXIT_SUCCESS; }
Board::~Board() { //std::cout << "DELETE" << std::endl; delete_grid(); }