diff --git a/src/pipes_test.c b/src/pipes_test.c index e3a3a30..7bb780d 100644 --- a/src/pipes_test.c +++ b/src/pipes_test.c @@ -13,7 +13,7 @@ #define INFILL_PLAIN_PAPER 0 #define INFILL_X_PIPE 1 #define INFILL_Y_PIPE 2 -#define FILLER "░" // ░ +#define FILLER " " // ░ // #define GRID_GROESSE_X 200 // x:y -> 2:1 for a square looking grid // #define GRID_GROESSE_Y 60 @@ -166,9 +166,13 @@ void print_grid(int x, int y, char **grid) { } } -void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int laenge) { +void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int laenge, int GRID_GROESSE_X, int GRID_GROESSE_Y) { if(laenge < 0){ for (int i = *x_start; i > *x_start + laenge; i--) { + if (i <= -laenge/2 -1) { + *x_start = GRID_GROESSE_X + laenge/2; + return; + } grid[*y_start][i] = INFILL_X_PIPE; printf("\33[H\033[J"); print_grid(x, y, grid); @@ -176,6 +180,10 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int } } else{ for (int i = *x_start; i < *x_start + laenge; i++) { + if (i >= GRID_GROESSE_X - laenge/2+1) { + *x_start = laenge/2; + return; + } grid[*y_start][i] = INFILL_X_PIPE; printf("\33[H\033[J"); print_grid(x, y, grid); @@ -186,10 +194,11 @@ void generate_pipe_x(int x, int y, char **grid, int *x_start, int *y_start, int *x_start += laenge; } -void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int laenge) { +void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int laenge, int GRID_GROESSE_X, int GRID_GROESSE_Y) { if(laenge < 0){ for (int i = *y_start; i > *y_start + laenge/2; i--) { - if (i <= 0) { + if (i <= -laenge/2) { + *y_start = GRID_GROESSE_Y + laenge/2; return; } grid[i][*x_start] = INFILL_Y_PIPE; @@ -199,7 +208,8 @@ void generate_pipe_y(int x, int y, char **grid, int *x_start, int *y_start, int } } else{ for (int i = *y_start; i < *y_start + laenge/2; i++) { - if (i <= 0) { + if (i >= (GRID_GROESSE_Y / 2)*2 - 1) { + *y_start = laenge/2; return; } grid[i][*x_start] = INFILL_Y_PIPE; @@ -263,15 +273,16 @@ int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { char key_input = (char)getch_directions(); switch (key_input) { - case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); break; - case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); break; - default: return 0; + case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, GRID_GROESSE_X, GRID_GROESSE_Y); break; + case 'q': return 0; + default: continue; } @@ -285,17 +296,17 @@ int main_program(int GRID_GROESSE_X, int GRID_GROESSE_Y) { } - if (DEBUGGER_RANDOM) { - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1); - generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9); - generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); - } +// if (DEBUGGER_RANDOM) { +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1); +// generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9); +// generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge); +// }