forked from zwickethomas/Photonics-Helfer
add menu
parent
4cdbc32365
commit
b18c263913
125
src/main.c
125
src/main.c
|
@ -1,12 +1,15 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <termio.h>
|
||||||
#elif _WIN32
|
#elif _WIN32
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <conio.h>
|
#include <conio.h>
|
||||||
|
#include <conio.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// import sub programme
|
// import sub programme
|
||||||
|
@ -44,11 +47,12 @@ void get_terminal_size_windows(int argc, char **argv, int *width, int *height){
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void print_wellcome_line(char line[100], int spaces){
|
void print_line(char line[100], int spaces, char color[5]){
|
||||||
for(int i = 0; i < spaces; i++){
|
for(int i = 0; i < spaces; i++){
|
||||||
printf(" ");
|
printf(" ");
|
||||||
}
|
}
|
||||||
printf("%s\n", line);
|
printf("\033[1%sm %s \033[0m\n", color, line);
|
||||||
|
// printf("%s\n", line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear_terminal(){
|
void clear_terminal(){
|
||||||
|
@ -67,25 +71,29 @@ void sleep_universal(int t){
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print_blank_lines(int lines){
|
||||||
|
for(int i = 0; i < lines; i++){
|
||||||
|
printf("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void print_wellcome(int terminal_width, int terminal_height){
|
void print_wellcome(int terminal_width, int terminal_height){
|
||||||
clear_terminal();
|
clear_terminal();
|
||||||
|
|
||||||
for(int i = 0; i < (terminal_height - 10) / 2; i++){
|
print_blank_lines((terminal_height - 10) / 2);
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
int spaces = (terminal_width - 83) / 2;
|
int spaces = (terminal_width - 83) / 2;
|
||||||
print_wellcome_line("__ ___ _ _ _ ", spaces);
|
print_line("__ ___ _ _ _ ", spaces, ";37");
|
||||||
print_wellcome_line("\\ \\ / (_) | | | _____ _ __ ___ _ __ ___ ___ _ __ _____ _ _ __ ___ ", spaces);
|
print_line("\\ \\ / (_) | | | _____ _ __ ___ _ __ ___ ___ _ __ _____ _ _ __ ___ ", spaces, ";37");
|
||||||
print_wellcome_line(" \\ \\ /\\ / /| | | | |/ / _ \\| '_ ` _ \\| '_ ` _ \\ / _ \\ '_ \\ |_ / | | | '_ ` _ \\", spaces);
|
print_line(" \\ \\ /\\ / /| | | | |/ / _ \\| '_ ` _ \\| '_ ` _ \\ / _ \\ '_ \\ |_ / | | | '_ ` _ \\", spaces, ";37");
|
||||||
print_wellcome_line(" \\ V V / | | | | < (_) | | | | | | | | | | | __/ | | | / /| |_| | | | | | | ", spaces);
|
print_line(" \\ V V / | | | | < (_) | | | | | | | | | | | __/ | | | / /| |_| | | | | | | ", spaces, ";37");
|
||||||
print_wellcome_line(" \\_/\\_/ |_|_|_|_|\\_\\___/|_| |_| |_|_| |_| |_|\\___|_| |_| /___|\\__,_|_| |_| |_| ", spaces);
|
print_line(" \\_/\\_/ |_|_|_|_|\\_\\___/|_| |_| |_|_| |_| |_|\\___|_| |_| /___|\\__,_|_| |_| |_| ", spaces, ";37");
|
||||||
print_wellcome_line(" ", spaces);
|
print_line(" ", spaces, ";37");
|
||||||
print_wellcome_line(" ____ _ _ _ _ _ _ _ __ ", spaces);
|
print_line(" ____ _ _ _ _ _ _ _ __ ", spaces, ";37");
|
||||||
print_wellcome_line("| _ \\| |__ ___ | |_| |__ ___ _ __ (_) ___ ___ | | | | ___| |/ _| ___ _ __ ", spaces);
|
print_line("| _ \\| |__ ___ | |_| |__ ___ _ __ (_) ___ ___ | | | | ___| |/ _| ___ _ __ ", spaces, ";37");
|
||||||
print_wellcome_line("| |_) | '_ \\ / _ \\| __| '_ \\ / _ \\| '_ \\| |/ __/ __| | |_| |/ _ \\ | |_ / _ \\ '__| ", spaces);
|
print_line("| |_) | '_ \\ / _ \\| __| '_ \\ / _ \\| '_ \\| |/ __/ __| | |_| |/ _ \\ | |_ / _ \\ '__| ", spaces, ";37");
|
||||||
print_wellcome_line("| __/| | | | (_) | |_| | | | (_) | | | | | (__\\__ \\ | _ | __/ | _| __/ | ", spaces);
|
print_line("| __/| | | | (_) | |_| | | | (_) | | | | | (__\\__ \\ | _ | __/ | _| __/ | ", spaces, ";37");
|
||||||
print_wellcome_line("|_| |_| |_|\\___/ \\__|_| |_|\\___/|_| |_|_|\\___|___/ |_| |_|\\___|_|_| \\___|_| ", spaces);
|
print_line("|_| |_| |_|\\___/ \\__|_| |_|\\___/|_| |_|_|\\___|___/ |_| |_|\\___|_|_| \\___|_| ", spaces, ";37");
|
||||||
|
|
||||||
sleep_universal(3);
|
sleep_universal(3);
|
||||||
|
|
||||||
|
@ -104,10 +112,81 @@ void print_wellcome(int terminal_width, int terminal_height){
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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");
|
||||||
|
getchar();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void print_menu(int terminal_width, int terminal_height, int line){
|
||||||
|
clear_terminal();
|
||||||
|
print_blank_lines((terminal_height - 11) / 2);
|
||||||
|
int spaces = (terminal_width - 41) / 2;
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
print_line("┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
|
print_line("┃ Programm 1 ┃", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (0 <= line && line < 2) ? ";31": ";37");
|
||||||
|
print_line("┃ Programm 1 ┃", spaces, (1 <= line && line < 2) ? ";31": ";37");
|
||||||
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (1 <= line && line < 3) ? ";31": ";37");
|
||||||
|
print_line("┃ Programm 1 ┃", spaces, (2 <= line && line < 3) ? ";31": ";37");
|
||||||
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (2 <= line && line < 4) ? ";31": ";37");
|
||||||
|
print_line("┃ Programm 1 ┃", spaces, (3 <= line && line < 4) ? ";31": ";37");
|
||||||
|
print_line("┣━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┫", spaces, (3 <= line && line < 5) ? ";31": ";37");
|
||||||
|
print_line("┃ ┃", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
|
print_line("┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
|
#elif _WIN32
|
||||||
|
print_line("+---------------------------------------+", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
|
print_line("| Programm 1 |", spaces, (0 <= line && line < 1) ? ";31": ";37");
|
||||||
|
print_line("+---------------------------------------+", spaces, (0 <= line && line < 2) ? ";31": ";37");
|
||||||
|
print_line("| Programm 1 |", spaces, (1 <= line && line < 2) ? ";31": ";37");
|
||||||
|
print_line("+---------------------------------------+", spaces, (1 <= line && line < 3) ? ";31": ";37");
|
||||||
|
print_line("| Programm 1 |", spaces, (2 <= line && line < 3) ? ";31": ";37");
|
||||||
|
print_line("+---------------------------------------+", spaces, (2 <= line && line < 4) ? ";31": ";37");
|
||||||
|
print_line("| Programm 1 |", spaces, (3 <= line && line < 4) ? ";31": ";37");
|
||||||
|
print_line("+---------------------------------------+", spaces, (3 <= line && line < 5) ? ";31": ";37");
|
||||||
|
print_line("| |", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
|
print_line("+---------------------------------------+", spaces, (4 <= line && line < 5) ? ";31": ";37");
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __linux__
|
||||||
|
int getch(){
|
||||||
|
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
|
||||||
|
|
||||||
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 os = 0; // 0 == None, 1 = linux, 2 = windows
|
int os = 0; // 0 == None, 1 = linux, 2 = windows
|
||||||
|
int line = 0;
|
||||||
|
bool run = true;
|
||||||
|
|
||||||
// Terminal grösse herauslesen
|
// Terminal grösse herauslesen
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
@ -130,7 +209,21 @@ int main(int argc, char **argv){
|
||||||
|
|
||||||
// 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){
|
||||||
|
char key_input = (char)getch();
|
||||||
|
|
||||||
|
switch (key_input) {
|
||||||
|
case 'k': line--; break;
|
||||||
|
case 'j': line++; break;
|
||||||
|
|
||||||
|
case 'q': run = false;
|
||||||
|
}
|
||||||
|
if(line < 0){line = 4;}
|
||||||
|
if(line > 4){line = 0;}
|
||||||
|
print_menu(width, height, line);
|
||||||
|
}
|
||||||
// zürück zum alten terminal (nur linux)
|
// zürück zum alten terminal (nur linux)
|
||||||
system("tput rmcup");
|
system("tput rmcup");
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue