/* Photonics helper main programm Das main programm startet die sub programme der verschienene gruppen Autor: Noah Balsinger, Thomas Zwicker Version: 0.1 Datum: 04.12.2024 Änderungen: 0.1 04.12.2024 Dokument erstellt 0.2 09.12.2024 Willkommensnachricht 0.3 10.12.2024 Meun hinzugefügt 0.4 11.12.2024 pipes + easter eggs hinzugefügt 0.5 12.12.2024 Windows version fix 0.6 13.12.2024 Pfeiltasten wurden hinzugefügt */ #include #include #include #include #include #ifdef __linux__ #include #include #include #include "Main-vz/kbhit_linux.h" #elif _WIN32 #include #include #endif // import sub programme #include "Ramen-vz/Ramen_Physik.h" #include "Fehlenden-vz/Fehlenden_Elektronik.h" #include "Wein-tz/Abbildungsrechner.h" #include "Flugi-tz/Funktion_Flugi.h" #include "Wein-vz/InformatikZusammenfassung.h" #include "Haenchen-vz/Haenchen_Drehmoment.h" #include "test_prog.h" #include "Main-vz/pipes_test.h" #include "Main-vz/pipes2.h" #include "Main-vz/pipes2_game.h" #ifdef __linux__ int getch(){ // getch funktion für linux (für windows in der conio.h lib) int ch; struct termios oldattr, newattr; tcgetattr(STDIN_FILENO, &oldattr); newattr = oldattr; newattr.c_lflag &= ~ICANON; newattr.c_lflag &= ~ECHO; newattr.c_cc[VMIN] = 1; newattr.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &newattr); ch = getchar(); tcsetattr(STDIN_FILENO, TCSANOW, &oldattr); return ch; } #endif #ifdef __linux__ void get_terminal_size_linux(int argc, char **argv, int *width, int *height){ struct winsize w; ioctl(STDOUT_FILENO, TIOCGWINSZ, &w); *height = w.ws_row; *width = w.ws_col; } #elif _WIN32 void get_terminal_size_windows(int argc, char **argv, int *width, int *height){ CONSOLE_SCREEN_BUFFER_INFO csbi; int columns, rows; GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi); *width = csbi.srWindow.Right - csbi.srWindow.Left + 1; *height = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; } #endif void print_line(char line[100], int spaces, char color[5]){ // funktion welche den text in einer farbe und mit space printet for(int i = 0; i < spaces; i++){ printf(" "); } printf("\033[1%sm %s \033[0m\n", color, line); } void clear_terminal(){ printf("\e[1;1H\e[2J"); } void sleep_universal(int t){ #ifdef __linux__ sleep(t); #elif _WIN32 // Sleep ist in Milisekunden Sleep(t * 1000); #endif } void print_blank_lines(int lines){ // funktion die leere zeilen printet for(int i = 0; i < lines; i++){ printf("\n"); } } void print_wellcome(int terminal_width, int terminal_height){ clear_terminal(); print_blank_lines((terminal_height - 10) / 2); int spaces = (terminal_width - 83) / 2; print_line("__ ___ _ _ _ ", spaces, ";37"); print_line("\\ \\ / (_) | | | _____ _ __ ___ _ __ ___ ___ _ __ _____ _ _ __ ___ ", spaces, ";37"); print_line(" \\ \\ /\\ / /| | | | |/ / _ \\| '_ ` _ \\| '_ ` _ \\ / _ \\ '_ \\ |_ / | | | '_ ` _ \\", spaces, ";37"); print_line(" \\ V 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"); sleep_universal(2); } void print_game_over(int terminal_width, int terminal_height){ clear_terminal(); print_blank_lines((terminal_height - 5) / 2); int spaces = (terminal_width - 50) / 2; print_line(" ____ ", spaces, ";37"); print_line(" / ___| __ _ _ __ ___ ___ _____ _____ _ __ ", spaces, ";37"); print_line("| | _ / _` | '_ ` _ \\ / _ \\ / _ \\ \\ / / _ \\ '__| ", spaces, ";37"); print_line("| |_| | (_| | | | | | | __/ | (_) \\ V / __/ | ", spaces, ";37"); print_line(" \\____|\\__,_|_| |_| |_|\\___| \\___/ \\_/ \\___|_| ", spaces, ";37"); print_blank_lines(2); print_line("Press a key to contine: ", spaces, ";37"); char key_input = (char)getch(); } 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){ clear_terminal(); printf("Drücke ? für Hilfe\n"); print_blank_lines((terminal_height - 23) / 2); int spaces = (terminal_width - 41) / 2; print_line("╔═══════════════════════════════════════╗", spaces, ";34"); print_line("║ Photonics Helfer ║", spaces, ";34"); print_line("╚═══════════════════════════════════════╝", spaces, ";34"); printf("\n"); print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37"); print_line("┃ 1 Physik (vz) ┃", spaces, (0 <= line && line < 1) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (0 <= line && line < 2) ? ";31": ";37"); print_line("┃ 2 Elektronik (vz) ┃", spaces, (1 <= line && line < 2) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (1 <= line && line < 3) ? ";31": ";37"); print_line("┃ 3 Informatik (vz) ┃", spaces, (2 <= line && line < 3) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37"); print_line("┃ 4 Drehmoment (vz) ┃", spaces, (3 <= line && line < 4) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37"); print_line("┃ 5 (vz) ┃", spaces, (4 <= line && line < 5) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (4 <= line && line < 6) ? ";31": ";37"); print_line("┃ 6 Abbildungsrechner (tz) ┃", spaces, (5 <= line && line < 6) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (5 <= line && line < 7) ? ";31": ";37"); print_line("┃ 7 Numpy (tz) ┃", spaces, (6 <= line && line < 7) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (6 <= line && line < 8) ? ";31": ";37"); print_line("┃ 8 (tz) ┃", spaces, (7 <= line && line < 8) ? ";31": ";37"); print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (7 <= line && line < 9) ? ";31": ";37"); print_line("┃ 9 (tz) ┃", spaces, (8 <= line && line < 9) ? ";31": ";37"); print_line("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛", spaces, (8 <= line && line < 9) ? ";31": ";37"); } void print_help(){ clear_terminal(); printf("? \t Diese Hilfe anzeigen\n"); printf("gg \t zum obersten Programm springen\n"); printf("G \t zum untersten Programm springen\n"); printf("j \t Ein Programm nach unten\n"); printf("k \t Ein Programm nach oben\n"); printf("Enter \t Um das ausgewählte Programm zu starten\n"); printf("1 - 9 \t Um das n Programm zu starten\n"); printf("q \t Um das Programm zu beenden\n"); printf("\nDrücke eine Taste um zurück zu kommen\n"); char key_input = (char)getch(); } void get_terminal_size(int argc, char **argv, int *width, int *height){ #ifdef __linux__ get_terminal_size_linux(argc, argv, width, height); #elif _WIN32 get_terminal_size_windows(argc, argv, width, height); #endif } void get_terminal_size_init(int argc, char **argv, int *width, int *height){ get_terminal_size(argc, argv, width, height); if (*width < 100 || *height < 30){ clear_terminal(); printf("Terminal zu klein!\n"); fflush(stdout); while(*width < 100 || *height < 30){ get_terminal_size(argc, argv, width, height); sleep_universal(1); } } } void run_programm(int programm, int width, int height, bool *used){ clear_terminal(); int return_code = 0; switch (programm) { case 0: return_code = Ramen_Physik(); break; case 1: return_code = Fehlenden_Elektronik_main(); break; case 2: return_code = Informatik_main(); break; case 3: return_code = Haenchen_Drehmoment_main(); break; case 4: return_code = test_gruppe_programmname(); break; case 5: return_code = Abbildungsrechner(); break; case 6: return_code = Flugi(); break; case 7: return_code = test_gruppe_programmname(); break; case 8: return_code = test_gruppe_programmname(); break; } // ist dazu da um "\n" aus dem buffer zu entfernen! int c; while ((c = getchar()) != '\n' && c != EOF) { } // getchar(); switch (return_code) { case 10: used[programm] = 1; break; case 20: print_game_over(width, height); break; } } void speed(int width, int height, int *start_time, bool *used){ if (*start_time + 30 < time(0)){ return; } for (int i = 0; i < 6; 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 width = 0; int height = 0; int line = 0; bool run = true; bool *used = (bool[6]){0}; int start_time = time(0); bool arrows = false; if (argc >= 2 && strcmp(argv[1], "--ich-benutze-windows-und-bin-auf-die-pfeiltasten-angewiesen") == 0){ arrows = true; } // umlaute für windows #ifdef _WIN32 system("chcp 65001 >null"); #endif // neues terminal öffnen (nur linux) #ifdef __linux__ system("tput smcup"); #endif // Terminal grösse herauslesen get_terminal_size_init(argc, argv, &width, &height); // print wellcome message print_wellcome(width, height); // Hauptschleife while(run){ // liest die terminal grösse ein get_terminal_size_init(argc, argv, &width, &height); // zeigt das menu an print_menu(width, height, line); // liest die Tastatur aus // char key_input = (char)getch(); // timer updateten int last_input = time(0); while (!kbhit()){ if (last_input + 30 <= time(0)){ pipes_2(width, height); last_input = time(0); print_menu(width, height, line); } } #ifdef __linux__ char key_input = (char)getchar(); #elif _WIN32 char key_input = (char)getch(); #endif // verarbeitet die Tastatur eingabe switch (key_input) { // vim movement case 'k': line--; break; case 'j': line++; break; case 'g': { char key_input = (char)getch(); if (key_input == 'g'){ line = 0; } break; } case 'G': line = 8; break; case 'q': run = false; break; case '?': print_help(); break; case 'p': pipes(width, height); break; case 'P': pipes_2(width, height); break; case 'o': pipes_2_game(width, height); break; // windows case -32:{ key_input = (char)getch(); if (arrows){ switch (key_input){ case 72: line--; break; // printf("up\n"); case 80: line++; break; // printf("down\n"); // case 77: printf("right\n"); break; // case 75: printf("left\n"); break; } } else{ open(); } break; } // linux case 27:{ key_input = (char)getch(); key_input = (char)getch(); if (arrows){ switch (key_input){ case 65: line--; break; // printf("up\n"); case 66: line++; break; // printf("down\n"); // case 67: printf("right\n"); break; // case 68: printf("left\n"); break; } } else { open(); } break; } // enter unter linux case '\n': run_programm(line, width, height, used); break; // enter under windows case 13 : run_programm(line, width, height, used); break; // schnell start 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; case '6': run_programm(5, width, height, used); break; case '7': run_programm(6, width, height, used); break; case '8': run_programm(7, width, height, used); break; case '9': run_programm(8, width, height, used); break; default: printf(" Es wurde die Taste: %i gedrückt\n", key_input); // getch(); } if(line < 0){line = 8;} if(line > 8){line = 0;} speed(width, height, &start_time, used); } // zurück zum alten terminal (nur linux) #ifdef __linux__ system("tput rmcup"); #endif return 0; }