pipes2game
MuedeHydra 2024-12-11 17:24:20 +01:00
parent ae53688748
commit db56e1d635
1 changed files with 104 additions and 19 deletions

View File

@ -1,6 +1,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <time.h>
#ifdef __linux__ #ifdef __linux__
#include <sys/ioctl.h> #include <sys/ioctl.h>
@ -13,6 +14,7 @@
// import sub programme // import sub programme
#include "pipes_test.h" #include "pipes_test.h"
#include "test_prog.h"
/* /*
Photonics helper main programm Photonics helper main programm
@ -25,6 +27,7 @@ Datum: 04.12.2024
0.1 04.12.2024 Dokument erstellt 0.1 04.12.2024 Dokument erstellt
0.2 09.12.2024 Willkommensnachricht 0.2 09.12.2024 Willkommensnachricht
0.3 10.12.2024 Meun hinzugefügt 0.3 10.12.2024 Meun hinzugefügt
0.4 11.12.2024 pipes + easter eggs hinzugefügt
*/ */
#ifdef __linux__ #ifdef __linux__
@ -149,9 +152,35 @@ void print_game_over(int terminal_width, int terminal_height){
} }
void print_speedrun(int terminal_width, int terminal_height, int speed_time){
clear_terminal();
print_blank_lines((terminal_height - 12) / 2);
int spaces = (terminal_width - 70) / 2;
print_line(" _ ____ _ _ ___ _______ _______ __ __ _____ _ _ _____ ", spaces, ";37");
print_line(" / \\ / ___| | | |_ _| ____\\ \\ / / ____| \\/ | ____| \\ | |_ _| ", spaces, ";37");
print_line(" / _ \\| | | |_| || || _| \\ \\ / /| _| | |\\/| | _| | \\| | | |(_) ", spaces, ";37");
print_line(" / ___ \\ |___| _ || || |___ \\ V / | |___| | | | |___| |\\ | | | _ ", spaces, ";37");
print_line("/_/ \\_\\____|_| |_|___|_____| \\_/ |_____|_| |_|_____|_| \\_| |_|(_) ", spaces, ";37");
print_line(" ", spaces, ";37");
print_line(" ____ ____ _____ _____ ____ ____ _ _ _ _ _ _ _____ ____ ", spaces, ";37");
print_line("/ ___|| _ \\| ____| ____| _ \\| _ \\| | | | \\ | | \\ | | ____| _ \\ ", spaces, ";37");
print_line("\\___ \\| |_) | _| | _| | | | | |_) | | | | \\| | \\| | _| | |_) | ", spaces, ";37");
print_line(" ___) | __/| |___| |___| |_| | _ <| |_| | |\\ | |\\ | |___| _ < ", spaces, ";37");
print_line("|____/|_| |_____|_____|____/|_| \\_\\\\___/|_| \\_|_| \\_|_____|_| \\_\\ ", spaces, ";37");
print_blank_lines(2);
print_line("", spaces, ";37");
printf("Du brauchtest: %i Sekunden.", speed_time);
char key_input = (char)getch();
}
void print_menu(int terminal_width, int terminal_height, int line){ void print_menu(int terminal_width, int terminal_height, int line){
clear_terminal(); clear_terminal();
print_blank_lines((terminal_height - 11) / 2); printf("Drücke ? für Hilfe\n");
print_blank_lines((terminal_height - 19) / 2);
int spaces = (terminal_width - 41) / 2; int spaces = (terminal_width - 41) / 2;
print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37"); print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37");
@ -163,8 +192,16 @@ void print_menu(int terminal_width, int terminal_height, int line){
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37");
print_line("┃ Programm 4 ┃", spaces, (3 <= line && line < 4) ? ";31": ";37"); print_line("┃ Programm 4 ┃", spaces, (3 <= line && line < 4) ? ";31": ";37");
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37");
print_line("┃ ┃", spaces, (4 <= line && line < 5) ? ";31": ";37"); print_line("┃ Programm 5 ┃", spaces, (4 <= line && line < 5) ? ";31": ";37");
print_line("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛", spaces, (4 <= line && line < 5) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (4 <= line && line < 6) ? ";31": ";37");
print_line("┃ Programm 6 ┃", spaces, (5 <= line && line < 6) ? ";31": ";37");
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (5 <= line && line < 7) ? ";31": ";37");
print_line("┃ Programm 7 ┃", spaces, (6 <= line && line < 7) ? ";31": ";37");
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (6 <= line && line < 8) ? ";31": ";37");
print_line("┃ Programm 8 ┃", spaces, (7 <= line && line < 8) ? ";31": ";37");
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (7 <= line && line < 9) ? ";31": ";37");
print_line("┃ Programm 9 ┃", spaces, (8 <= line && line < 9) ? ";31": ";37");
print_line("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛", spaces, (8 <= line && line < 9) ? ";31": ";37");
} }
@ -176,6 +213,7 @@ void print_help(){
printf("j \t Ein Programm nach unten\n"); printf("j \t Ein Programm nach unten\n");
printf("k \t Ein Programm nach oben\n"); printf("k \t Ein Programm nach oben\n");
printf("Enter \t Um das ausgewählte Programm zu starten\n"); printf("Enter \t Um das ausgewählte Programm zu starten\n");
printf("1-n \t Um das n Programm zu starten\n");
printf("q \t Um das Programm zu beenden\n"); printf("q \t Um das Programm zu beenden\n");
printf("\nDrücke eine Taste um zurück zu kommen\n"); printf("\nDrücke eine Taste um zurück zu kommen\n");
char key_input = (char)getch(); char key_input = (char)getch();
@ -205,11 +243,54 @@ void get_terminal_size_init(int argc, char **argv, int *width, int *height){
} }
} }
void run_programm(int programm, int width, int height, bool *used){
clear_terminal();
int return_code = 0;
switch (programm) {
case 0: return_code = test_gruppe_programmname(); break;
case 1: return_code = test_gruppe_programmname(); break;
case 2: return_code = test_gruppe_programmname(); break;
case 3: return_code = test_gruppe_programmname(); break;
case 4: return_code = test_gruppe_programmname(); break;
}
switch (return_code) {
case 10: used[programm] = 1; break;
case 20: print_game_over(width, height); break;
}
getchar();
}
void speed(int width, int height, int *start_time, bool *used){
if (*start_time + 20 < time(0)){
return;
}
for (int i = 0; i < 5; i++){
if (used[i] == 0){
return;
}
}
int speed_time = time(0) - *start_time;
*start_time -= 20;
print_speedrun(width, height, speed_time);
printf("speed: %i", speed_time);
}
void open(){
#ifdef __linux__
system("xdg-open https://media1.tenor.com/m/xTZp3_9gnE0AAAAd/linux-linux-convention.gif");
#elif _WIN32
system("start msedge.exe --kiosk https://www.ravbug.com/bsod/bsod10/ --edge-kiosk-type=fullscreen");
#endif
}
int main(int argc, char **argv){ int main(int argc, char **argv){
int width = 0; int width = 0;
int height = 0; int height = 0;
int line = 0; int line = 0;
bool run = true; bool run = true;
bool *used = (bool[5]){0};
int start_time = time(0);
// umlaute für windows // umlaute für windows
#ifdef _WIN32 #ifdef _WIN32
@ -222,24 +303,15 @@ int main(int argc, char **argv){
#endif #endif
// Terminal grösse herauslesen // Terminal grösse herauslesen
// get_terminal_size(argc, argv, &width, &height);
get_terminal_size_init(argc, argv, &width, &height); get_terminal_size_init(argc, argv, &width, &height);
// int x = test_gruppe_programmname();
printf ("lines %d\n", height);
printf ("columns %d\n", width);
// print wellcome message // print wellcome message
print_wellcome(width, height); print_wellcome(width, height);
// print_game_over(width, height);
// print_menu(width, height, line);
while(run){ while(run){
get_terminal_size_init(argc, argv, &width, &height); get_terminal_size_init(argc, argv, &width, &height);
print_menu(width, height, line); print_menu(width, height, line);
char key_input = (char)getch(); char key_input = (char)getch();
switch (key_input) { switch (key_input) {
@ -252,19 +324,32 @@ int main(int argc, char **argv){
} }
break; break;
} }
case 'G': line = 4; break; case 'G': line = 8; break;
case '?': print_help(); break; case '?': print_help(); break;
case 'p': pipes(); break; case 'p': pipes(); break;
case 'q': run = false; break; case 'q': run = false; break;
case '\n': printf(" Es wurde die Enter Taste gedrückt"); getchar(); break;
default: printf(" Es wurde die Taste: %c gedrückt", key_input); case 'A': open(); break;
case 'B': open(); break;
case 'C': open(); break;
case 'D': open(); break;
case '\n': run_programm(line, width, height, used); break;
case '1': run_programm(0, width, height, used); break;
case '2': run_programm(1, width, height, used); break;
case '3': run_programm(2, width, height, used); break;
case '4': run_programm(3, width, height, used); break;
case '5': run_programm(4, width, height, used); break;
default: printf(" Es wurde die Taste: %c gedrückt", key_input); getch();
} }
if(line < 0){line = 4;} if(line < 0){line = 8;}
if(line > 4){line = 0;} if(line > 8){line = 0;}
// print_menu(width, height, line); speed(width, height, &start_time, used);
} }
// zürück zum alten terminal (nur linux) // zürück zum alten terminal (nur linux)
#ifdef __linux__ #ifdef __linux__
system("tput rmcup"); system("tput rmcup");