#include<stdio.h>
#include<conio.h>
#include<windows.h>
#define RECHTS 77
#define UNTEN 80
#define LINKS 75
#define OBEN 72
#define LEICHT 49
#define MITTEL 50
#define SCHWER 51
int pfeil();
void menu(int *alive);
void neu(/*int feld[80][25], int snake[90][2],*/ int *action, int *alive, int *grad, int *score);
void move(/*int snake[90][2],*/ int action, int grad, int *score, int *alive);
int main() {
int feld[80][24];
int snake[90][2];
int action;
int alive;
int grad;
int score;
menu(&alive);
while(alive) {
if(alive == 2) neu(/*feld[80][25], snake[90][2],*/ &action, &alive, &grad, &score);
move(/*snake[90][2],*/ action, grad, &score, &alive);
system("cls");
if(kbhit()) {
switch(pfeil()) {
case 100:
case -77: action = RECHTS;
break;
case 115:
case -80: action = UNTEN;
break;
case 97:
case -75: action = LINKS;
break;
case 119:
case -72: action = OBEN;
break;
case 27:
case 112: menu(&alive);
}
}
}
return 0;
}
int pfeil() {
int taste = getch();
if(taste == 224) {
taste = getch();
return -taste;
}
return taste;
}
void menu(int *alive) {
char action;
int exit = 0;
if(*alive == 1) {
printf("\n \\--------------------------/\n"
" | .:Pausemenue:. |\n"
" | p: Spiel fortsetzen |\n");
} else if(*alive == 3) {
printf("\n \\--------------------------/\n"
" | .:GAME OVER!:. |\n");
} else {
printf("\n \\--------------------------/\n"
" | .:Hauptmenue:. |\n");
}
printf(" | n: Neues Spiel starten |\n"
" | b: Beenden |\n"
" /--------------------------\\\n");
do{
exit = 0;
action = getch();
switch(action) {
case 'p': if(*alive != 1) exit = 1;
break;
case 'n': *alive = 2;
break;
case 'b': *alive = 0;
break;
default: exit = 1;
}
} while(exit);
system("cls");
}
void move(/*int snake[90][2], */int action, int grad, int *score, int *alive) {
Sleep(1/grad*100);
}
void neu(/*int feld[80][25], int snake[90][2],*/ int *action, int *alive, int *grad, int *score) {
int exit = 0;
*alive = 1;
*score = 0;
*action = RECHTS;
printf("\n \\--------------------------/\n"
" | .:Schwierigkeitsgrad:. |\n"
" | 1: Leicht |\n"
" | 2: Mittel |\n"
" | 3: Schwer |\n"
" /--------------------------\\\n");
do{
*grad = getch();
switch(*grad) {
case '1': case '2': case '3': break;
default: exit = 1;
}
}while(exit);
}