KRUGSON
2 years ago
1 changed files with 76 additions and 14 deletions
-
90src/c/main.c
@ -1,27 +1,89 @@ |
|||||
//BIBs |
|
||||
|
// BIBs |
||||
#include <stdio.h> |
#include <stdio.h> |
||||
#include <stdlib.h> |
#include <stdlib.h> |
||||
#include <stdbool.h> |
#include <stdbool.h> |
||||
|
#include <string.h> |
||||
|
|
||||
bool gameRunning; |
bool gameRunning; |
||||
|
bool acceptedRules; |
||||
|
|
||||
|
// content |
||||
|
char *gameInstructionsFile = "../../src/content/game_instructions.txt"; |
||||
|
|
||||
|
// function declarations |
||||
|
void printInit(); |
||||
|
|
||||
int main() |
int main() |
||||
{ |
{ |
||||
//define variables |
|
||||
char userInput[20]; //maximum defined user input length |
|
||||
gameRunning = 1; |
|
||||
|
// define variables |
||||
|
char userInput[20]; // maximum defined user input length |
||||
|
gameRunning = 1; |
||||
|
|
||||
|
// init and instructions |
||||
|
printInit(); |
||||
|
|
||||
while (gameRunning == 1) //while running |
|
||||
|
if (acceptedRules == 1) |
||||
{ |
{ |
||||
// User Input |
|
||||
printf("User Input:"); |
|
||||
scanf(" %s", userInput); |
|
||||
printf("\n"); |
|
||||
|
|
||||
//NEXT STEP: |
|
||||
//Processing |
|
||||
//processInput(userInput); |
|
||||
} |
|
||||
|
while (gameRunning == 1) // while running |
||||
|
{ |
||||
|
// User Input |
||||
|
printf("User Input:"); |
||||
|
scanf(" %s", userInput); |
||||
|
printf("\n"); |
||||
|
|
||||
|
// NEXT STEP: |
||||
|
// Processing |
||||
|
// processInput(userInput); |
||||
|
} |
||||
|
} |
||||
return 0; |
return 0; |
||||
|
}; |
||||
|
|
||||
|
// init dialogue |
||||
|
void printInit() |
||||
|
{ |
||||
|
FILE *stream; |
||||
|
char *line = NULL; |
||||
|
size_t len = 0; |
||||
|
ssize_t read; |
||||
|
|
||||
|
stream = fopen(gameInstructionsFile, "r"); |
||||
|
if (stream == NULL) |
||||
|
{ |
||||
|
printf("ERROR: couldn't open or find file: INSTRUCTIONS !\n"); |
||||
|
exit(EXIT_FAILURE); // exit |
||||
|
} |
||||
|
|
||||
|
/* print line by line from file */ |
||||
|
while ((read = getline(&line, &len, stream)) != -1) |
||||
|
{ |
||||
|
// printf("Retrieved line of length %u :\n", read); |
||||
|
printf("%s", line); |
||||
|
} |
||||
|
|
||||
|
free(line); /* Deallocate allocated memory */ |
||||
|
fclose(stream); /* closing file */ |
||||
|
|
||||
|
char userInput[1]; |
||||
|
bool inputState = 0; |
||||
|
int acceptCounter = 0; |
||||
|
while (inputState == 0) |
||||
|
{ |
||||
|
scanf(" %c", userInput); |
||||
|
if (strcasecmp(userInput, "y") == 0) |
||||
|
{ |
||||
|
acceptedRules = 1; |
||||
|
inputState = 1; //break while |
||||
|
} |
||||
|
else if (strcasecmp(userInput, "n") == 0) |
||||
|
{ |
||||
|
printf("You didn't read our rules & instructions. The game will close now. \n\n"); |
||||
|
acceptedRules = 0; |
||||
|
inputState = 1; //break while |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
printf("Invalid Input!\n"); |
||||
|
} |
||||
|
} |
||||
}; |
}; |
Write
Preview
Loading…
Cancel
Save
Reference in new issue