|
|
@ -10,24 +10,23 @@ |
|
|
|
bool gameRunning; |
|
|
|
bool acceptedRules; |
|
|
|
|
|
|
|
//declare needed variables |
|
|
|
// declare needed variables |
|
|
|
Room *map; |
|
|
|
|
|
|
|
// content |
|
|
|
char *gameInstructionsFile = "../../src/content/game_instructions.txt"; |
|
|
|
char *gameMapFile = "../../src/content/game.map"; |
|
|
|
|
|
|
|
//navigation |
|
|
|
// navigation |
|
|
|
int playerPosition = 0; |
|
|
|
int lastPlayerPosition = 0; |
|
|
|
|
|
|
|
|
|
|
|
// function declarations |
|
|
|
void printInit(); |
|
|
|
void acceptInstructions(); |
|
|
|
void processInput(); |
|
|
|
int checkExit(); |
|
|
|
|
|
|
|
int checkMove(); |
|
|
|
|
|
|
|
int main() |
|
|
|
{ |
|
|
@ -38,7 +37,7 @@ int main() |
|
|
|
// init and instructions |
|
|
|
printInit(); |
|
|
|
|
|
|
|
//get Content |
|
|
|
// get Content |
|
|
|
map = getMap(gameMapFile); |
|
|
|
|
|
|
|
if (acceptedRules == 1) |
|
|
@ -58,7 +57,6 @@ int main() |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// init dialogue |
|
|
|
void printInit() |
|
|
|
{ |
|
|
@ -117,13 +115,34 @@ void acceptInstructions() |
|
|
|
// process user input |
|
|
|
void processInput(char userInput[20]) |
|
|
|
{ |
|
|
|
Room r = map[playerPosition]; |
|
|
|
if (checkExit(userInput) == 1) |
|
|
|
{ |
|
|
|
gameRunning = 0; |
|
|
|
printf("!GAME EXIT!\n"); |
|
|
|
} |
|
|
|
else if (strcmp(userInput, "north") == 0) |
|
|
|
else if (checkMove(userInput) == 1) |
|
|
|
{ |
|
|
|
printf("Wrong Input!\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// function for checking user input of exit |
|
|
|
int checkExit(char userInput[20]) |
|
|
|
{ |
|
|
|
if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
int checkMove(char userInput[20]) |
|
|
|
{ |
|
|
|
|
|
|
|
Room r = map[playerPosition]; |
|
|
|
|
|
|
|
if (strcmp(userInput, "north") == 0) |
|
|
|
{ |
|
|
|
printf("->N\n"); |
|
|
|
lastPlayerPosition = playerPosition; |
|
|
@ -135,6 +154,8 @@ void processInput(char userInput[20]) |
|
|
|
{ |
|
|
|
playerPosition = r.successor; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
else if (strcmp(userInput, "south") == 0) |
|
|
|
{ |
|
|
@ -148,21 +169,11 @@ void processInput(char userInput[20]) |
|
|
|
{ |
|
|
|
printf("You have reached the border. You have to go in the other direction!\n"); |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
printf("Wrong Input!\n"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//function for checking user input of exit |
|
|
|
int checkExit(char userInput[20]) |
|
|
|
{ |
|
|
|
if (strcmp(userInput, "esc") == 0 || strcmp(userInput, "exit") == 0 || strcmp(userInput, "quit") == 0) |
|
|
|
{ |
|
|
|
return 1; |
|
|
|
} |
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|