Compare commits
No commits in common. "20b2302b5bee6c2fc0f738b0f3de54bba6ef0a82" and "8373a0474786633b7a716c6d4b9c906ba64b506c" have entirely different histories.
20b2302b5b
...
8373a04747
124
src/pipes_test.c
124
src/pipes_test.c
|
@ -6,9 +6,6 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <unistd.h>
|
||||
#include <termio.h>
|
||||
#elif _WIN32
|
||||
#include <windows.h>
|
||||
#include <conio.h>
|
||||
#endif
|
||||
|
||||
#define DEBUGGER_PIPES_TO_NUMBERS 0
|
||||
|
@ -44,7 +41,6 @@ void random_color() {
|
|||
color = colors[rand() % (sizeof(colors) / sizeof(colors[0]))];
|
||||
}
|
||||
|
||||
#ifdef __linux__
|
||||
int getch_pipes(){
|
||||
int ch;
|
||||
struct termios oldattr, newattr;
|
||||
|
@ -61,21 +57,15 @@ int getch_pipes(){
|
|||
|
||||
return ch;
|
||||
}
|
||||
#endif
|
||||
|
||||
void print_grid(int x, int y, char **grid, int how_many_targets) {
|
||||
int target_count = 0;
|
||||
void print_grid(int x, int y, char **grid) {
|
||||
for (int i = 0; i < y; i++) {
|
||||
printf("\n");
|
||||
for (int j = 0; j < x; j++) {
|
||||
if(grid[i][j] == 3){
|
||||
target_count += 1;
|
||||
}if (!DEBUGGER_PIPES_TO_NUMBERS){
|
||||
if (!DEBUGGER_PIPES_TO_NUMBERS){
|
||||
if(grid[i][j] == 0){
|
||||
printf(FILLER);
|
||||
} else if(grid[i][j] == 3){
|
||||
printf("%s█","\033[31m" );
|
||||
} else if(grid[i][j] != 0 && grid[i][j] != 1 && grid[i][j] != 2 && grid[i][j] != 3){
|
||||
} else if(grid[i][j] != 0 && grid[i][j] != 1 && grid[i][j] != 2){
|
||||
return;
|
||||
|
||||
} else if(grid[i - 1][j] == 0 && grid[i + 1][j] == 0 && grid[i][j - 1] != 0 && grid[i][j + 1] != 0 && grid[i][j] == 1 ){
|
||||
|
@ -141,10 +131,6 @@ void print_grid(int x, int y, char **grid, int how_many_targets) {
|
|||
} else if(grid[i - 1][j] == 2 && grid[i + 1][j] == 2 && grid[i][j - 1] == 2 && grid[i][j + 1] == 2 && grid[i][j] == 2 ){
|
||||
printf("%s┃", color);
|
||||
|
||||
|
||||
} else if(grid[i][j] == 3){
|
||||
printf("✨");
|
||||
|
||||
|
||||
|
||||
} else if(grid[i - 1][j] != 0 && grid[i + 1][j] != 0 && grid[i][j - 1] != 0 && grid[i][j + 1] != 0 && grid[i][j] == 0 ){
|
||||
|
@ -174,28 +160,9 @@ void print_grid(int x, int y, char **grid, int how_many_targets) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (target_count <= 2*how_many_targets - 1*how_many_targets) {
|
||||
printf("\e[1;1H\e[2J");
|
||||
printf("\n");
|
||||
printf(" █ █ █████ █ █ █ █ █████ ██ █\n");
|
||||
printf(" ██ ██ █ █ █ █ █ █ █ █ ███ █\n");
|
||||
printf(" █████ █ █ █ █ █ █ █ █ █ ██ █\n");
|
||||
printf(" █ █ █ █ █ █ ██ █ █ █ █ ███\n");
|
||||
printf(" █ █████ █████ █ █ █████ █ ██\n");
|
||||
printf("\n");
|
||||
printf("Targets overritten: %i\n", 8*how_many_targets-target_count);
|
||||
if (target_count > 3) {
|
||||
printf("\nspecial achivement!!!!!!\n");
|
||||
} else {
|
||||
system("xdg-open https://bit.ly/3BlS71b");
|
||||
}
|
||||
printf("'q' for start menue");
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void generate_pipe_x(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge, int how_many_targets) {
|
||||
void generate_pipe_x(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge) {
|
||||
if(laenge < 0){
|
||||
for (int i = *x_start; i > *x_start + laenge; i--) {
|
||||
if (i <= -laenge/2 -1) {
|
||||
|
@ -204,7 +171,8 @@ void generate_pipe_x(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x
|
|||
}
|
||||
grid[*y_start][i] = INFILL_X_PIPE;
|
||||
printf("\33[H\033[J");
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid, how_many_targets);
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid);
|
||||
usleep(SLEEP_TIMER);
|
||||
}
|
||||
} else{
|
||||
for (int i = *x_start; i < *x_start + laenge; i++) {
|
||||
|
@ -214,14 +182,15 @@ void generate_pipe_x(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x
|
|||
}
|
||||
grid[*y_start][i] = INFILL_X_PIPE;
|
||||
printf("\33[H\033[J");
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid, how_many_targets);
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid);
|
||||
usleep(SLEEP_TIMER);
|
||||
}
|
||||
}
|
||||
|
||||
*x_start += laenge;
|
||||
}
|
||||
|
||||
void generate_pipe_y(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge, int how_many_targets) {
|
||||
void generate_pipe_y(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge) {
|
||||
if(laenge < 0){
|
||||
for (int i = *y_start; i > *y_start + laenge/2; i--) {
|
||||
if (i <= -laenge/2) {
|
||||
|
@ -230,7 +199,8 @@ void generate_pipe_y(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x
|
|||
}
|
||||
grid[i][*x_start] = INFILL_Y_PIPE;
|
||||
printf("\33[H\033[J");
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid, how_many_targets);
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid);
|
||||
usleep(SLEEP_TIMER);
|
||||
}
|
||||
} else{
|
||||
for (int i = *y_start; i < *y_start + laenge/2; i++) {
|
||||
|
@ -240,30 +210,14 @@ void generate_pipe_y(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x
|
|||
}
|
||||
grid[i][*x_start] = INFILL_Y_PIPE;
|
||||
printf("\33[H\033[J");
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid, how_many_targets);
|
||||
print_grid(GRID_GROESSE_X, GRID_GROESSE_Y, grid);
|
||||
usleep(SLEEP_TIMER);
|
||||
}
|
||||
}
|
||||
|
||||
*y_start += laenge/2;
|
||||
}
|
||||
|
||||
void generate_target(int GRID_GROESSE_X, int GRID_GROESSE_Y, char **grid, int *x_start, int *y_start, int laenge) {
|
||||
int abstand_vom_rand_x = 6;
|
||||
int abstand_vom_rand_y = 3;
|
||||
int target_x = 0;
|
||||
int target_y = 0;
|
||||
while (target_x <= abstand_vom_rand_x || target_x >= GRID_GROESSE_X - abstand_vom_rand_x || target_y <= abstand_vom_rand_y || target_y >= GRID_GROESSE_Y - abstand_vom_rand_y) {
|
||||
target_x = ((rand() % GRID_GROESSE_X));
|
||||
target_y = ((rand() % GRID_GROESSE_Y));
|
||||
}
|
||||
for (int j = target_y; j < target_y + 2; j++) {
|
||||
for (int i = target_x; i < target_x + 1; i++) {
|
||||
grid[j][i] = 3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) {
|
||||
//int main() {
|
||||
// system("chcp 65001 >null");
|
||||
|
@ -292,11 +246,6 @@ int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) {
|
|||
}
|
||||
|
||||
int richtungswechsler = 1;
|
||||
int how_many_targets = 3;
|
||||
for (int i = 1; i <= how_many_targets; i++) {
|
||||
generate_target(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, 1, how_many_targets);
|
||||
|
||||
while (!DEBUGGER_RANDOM) {
|
||||
|
||||
|
@ -306,21 +255,18 @@ int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) {
|
|||
}
|
||||
|
||||
laenge = ((rand() %max_l)+min_l);
|
||||
|
||||
#ifdef __linux__
|
||||
char key_input = (char)getch_pipes();
|
||||
#elif _WIN32
|
||||
char key_input = (char)getch();
|
||||
#endif
|
||||
|
||||
char key_input = (char)getch_pipes();
|
||||
|
||||
switch (key_input) {
|
||||
case 'h': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, how_many_targets); break;
|
||||
case 'a': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, how_many_targets); break;
|
||||
case 'l': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets); break;
|
||||
case 'd': generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets); break;
|
||||
case 'j': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets); break;
|
||||
case 's': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets); break;
|
||||
case 'k': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, how_many_targets); break;
|
||||
case 'w': generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, how_many_targets); break;
|
||||
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;
|
||||
case 'q': return 0;
|
||||
default: continue;
|
||||
}
|
||||
|
@ -338,25 +284,25 @@ int pipes(int GRID_GROESSE_X, int GRID_GROESSE_Y) {
|
|||
}
|
||||
|
||||
if (richtungswechsler == 1) {
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets);
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge);
|
||||
richtungswechsler *= -1;
|
||||
} else {
|
||||
generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets);
|
||||
generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge);
|
||||
richtungswechsler *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (DEBUGGER_RANDOM) {
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets);
|
||||
generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets);
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets);
|
||||
generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -0.1, how_many_targets);
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1.05, how_many_targets);
|
||||
generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * -1, how_many_targets);
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.1, how_many_targets);
|
||||
generate_pipe_y(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge * 0.9, how_many_targets);
|
||||
generate_pipe_x(GRID_GROESSE_X, GRID_GROESSE_Y, grid, &x_start, &y_start, laenge, how_many_targets);
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue