void ShZshapeManager::draw_shape(const char* content) { if (content == "cube") { draw_cube(); } if (content == "cylinder") { draw_cylinder(); } if (content == "pipe") { draw_pipe(); } if (content == "cone") { draw_cone(); } if (content == "circle") { draw_circle(); } if (content == "ring") { draw_ring(); } if (content == "pyramid") { draw_pyramid(); } if (content == "triangle") { draw_triangle(); } if (content == "rectangle") { draw_rectangle(); } if (content == "polygon") { draw_polygon(); } if (content == "multigonalStar") { draw_multigonalStar(); } }
static void connect_back() { int r, c; int fromr, fromc, tor, toc; /* make gcc shutup about these being uninitialized */ fromc = tor = toc = -1; for( r = 0; r < map.num_row; r++ ) { if( count[r] == 0 ) continue; fromr = r; /* find last well */ for( c = map.num_col-1; c >= 0; c-- ) { if( grid[fromr][c] == 1 ) { fromc = c; break; } } /* tor = -1; */ /* find next row with well */ for( r++; r < map.num_row; r++ ) { if( count[r] > 0 ) { tor = r; break; } } /* there might not be another row after from row */ if( r == map.num_row ) break; /* find last well */ for( c = map.num_col-1; c >= 0; c-- ) { if( grid[tor][c] == 1 ) { toc = c; break; } } draw_pipe(fromr, fromc, tor, toc, 1); printf("BACK: %d, %d ---- %d, %d\n", fromr, fromc, tor, toc); r = tor-1; } return; }
static void connect_front() { int r, c; int fromr, fromc, tor, toc; /* make gcc shutup about these being uninitialized */ fromc = tor = toc = -1; for( r = 0; r < map.num_row; r++ ) { if( count[r] == 0 ) continue; fromr = r; /* find first well */ for( c = 0; c < map.num_col; c++ ) { if( grid[fromr][c] == 1 ) { fromc = c; break; } } /* tor = -1; */ /* find next row with a well */ for( r++; r < map.num_row; r++ ) { if( count[r] > 0 ) { tor = r; break; } } /* there might be no other wells after from row */ if( r == map.num_row ) break; /* find first well on to row */ for( c = 0; c < map.num_col; c++ ) { if( grid[tor][c] == 1 ) { toc = c; break; } } draw_pipe(fromr, fromc, tor, toc, 0); printf("FRONT: %d, %d ---- %d, %d\n", fromr, fromc, tor, toc); r = tor-1; } return; }
static void connect_rows() { int r, c; int fromc, toc; /* make gcc shutup about these being uninitialized */ fromc = toc = -1; for( r = 0; r < map.num_row; r++ ) { /* can't connect if there's not 2 or more... */ if( count[r] < 2 ) continue; /* find first c... */ for( c = 0; c < map.num_col; c++ ) { if( grid[r][c] == 1 ) { fromc = c; break; } } /* find last c... */ for( c++ ; c < map.num_col; c++ ) { if( grid[r][c] == 1 ) toc = c; } draw_pipe(r, fromc, r, toc, 0); } return; }
int main() { int leave_loop = 0; int ch; flappy f; int restart = 1; srand(time(NULL)); // Initialize ncurses initscr(); raw(); // Disable line buffering keypad(stdscr, TRUE); noecho(); // Don't echo() for getch curs_set(0); timeout(0); splash_screen(); while(!leave_loop) { // If we're just starting a game then do some initializations. if (restart) { timeout(0); // Don't block on input. // Start the pipes just out of view on the right. p1.center = (int)(1.2 * (NUM_COLS - 1)); p1.opening_height = rand() / ((float) INT_MAX) * 0.5 + 0.25; p2.center = (int)(1.75 * (NUM_COLS - 1)); p2.opening_height = rand() / ((float) INT_MAX) * 0.5 + 0.25; // Initialize flappy f.h0 = NUM_ROWS / 2; f.t = 0; restart = 0; } usleep((unsigned int) (1000000 / TARGET_FPS)); // Process keystrokes. ch = -1; ch = getch(); switch (ch) { case 'q': // Quit. endwin(); exit(0); break; case KEY_UP: // Give Flappy a boost! f.h0 = get_flappy_position(f); f.t = 0; break; default: // Let Flappy fall along his parabola. f.t++; } clear(); // Print "moving" floor and ceiling draw_floor_and_ceiling(0, NUM_ROWS - 1, '/', 2, frame % 2); // Update pipe locations and draw them. draw_pipe(p1, '|', '=', '=', 0, NUM_ROWS - 1); draw_pipe(p2, '|', '=', '=', 0, NUM_ROWS - 1); pipe_refresh(&p1); pipe_refresh(&p2); // Draw Flappy. If Flappy crashed and user wants a restart... if(draw_flappy(f)) { restart = 1; continue; // ...then restart the game. } mvprintw(0, SCORE_START_COL - bdigs - sdigs, " Score: %d Best: %d", score, best_score); // Display all the chars for this frame. refresh(); frame++; } endwin(); return 0; }
void connect_mid() { int r, c; int fromr, fromc, tor, toc; int mid, i; /* make gcc shutup about these being uninitialized */ fromc = tor = toc = -1; for( r = 0; r < map.num_row; r++ ) { printf("row == %d, count[%d] = %d\n", r, r, count[r]); if( count[r] == 0 ) continue; fromr = r; /* find first middle well */ mid = count[fromr]/2; i = 0; for( c = 0; c < map.num_col; c++ ) { if( grid[fromr][c] == 1 ) { fromc = c; if( i == mid ) break; i++; } } /* tor = -1; */ /* find to row */ for( r++; r < map.num_row; r++ ) { if( count[r] > 0 ) { tor = r; break; } } /* there might not be another row after from row */ if( r == map.num_row ) break; /* find first middle well */ mid = count[tor]/2; i = 0; printf("count[tor]/2 == %d/2 == %d\n", count[tor], mid); for( c = 0; c < map.num_col; c++ ) { if( grid[tor][c] == 1 ) { toc = c; if( i == mid ) break; i++; } } draw_pipe(fromr, fromc, tor, toc, 0); printf("pipe= %d, %d --- %d, %d\n", fromr, fromc, tor, toc); r = tor - 1; } }