Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Created by Conner_36
- //
- //the extern ints are there because on my computer I have the functions in different files
- #include <stdio.h>
- #include <stdlib.h>
- int quittersFlag;
- int wait (void) {
- int c;
- extern int quittersFlag;
- printf("\n(Waiting politely for you to press the RETURN key...)");
- while ((c = getchar()) != '\n') {
- if (c == EOF) {
- return quittersFlag = 1;
- }
- }
- return 0;
- }
- int introduction (void) {
- extern int quittersFlag;
- printf("This is your character -> @\n\nSay hello!\n");
- if (wait()!=0) {
- return quittersFlag;
- }
- printf("\n@ is excited about his new master...\n");
- printf("\n@ needs some word food to complete his upcoming journey.\n");
- if (wait()!=0) {
- return quittersFlag;
- } printf("\nAny letter or number on your keyboard will do.\n");
- printf("I warn you though, @ hates numbers. If you feed him some...\nhe might just run back to the start.\n\nOr worse...\n\nHe may get lost.\n");
- if (wait()!=0) {
- return quittersFlag;
- } printf("\nIf this seems too great a responsibility you can always press (control-D)\n");
- if (wait()!=0) {
- return quittersFlag;
- } printf("\nI won't hold it against you.\n");
- if (wait()!=0) {
- return quittersFlag;
- } printf("\nStill here?\n");
- if (wait()!=0) {
- return quittersFlag;
- } printf("\nVery well then... its time you give some motivation to your character:\n");
- return quittersFlag;
- }
- int gamestate (void) {
- char characterSpace[80];
- char character = '@';
- char line = '_';
- char encouragement = 1;
- int counter;
- int externCounter = 0;
- int quit;
- extern int quittersFlag;
- while (quit != EOF) {
- for (counter = 0; counter < 80; counter++) {
- characterSpace[counter]=line;
- }
- characterSpace[counter]='\0';//sets the end of the array for string compatibility
- scanf("%c", &encouragement);
- if (encouragement >= 65) { // if a letter
- if (externCounter <= 60) {
- externCounter+=4;
- } else {
- externCounter+=3;
- }
- }
- if (encouragement <= 57 && encouragement >= 48) { // if a number
- if (externCounter <=5) {
- externCounter--;
- } else {
- externCounter-=5;
- }
- }
- if (encouragement == '\n') {
- printf("\n");
- printf("Sending motivation to @. He feels like going to position %d...\n", externCounter);
- if (externCounter > -1) {
- characterSpace[externCounter]=character;
- }
- if (externCounter >= 80 ) {
- characterSpace[79]='@';
- quittersFlag = 3;
- quit = EOF;
- } else if (externCounter <= -10) {
- quittersFlag = 2;
- quit = EOF;
- } else {
- printf("\n(care to tell him more words of wisdom?)\n");
- }
- printf("\n%s\n\n", characterSpace); // draws the characters world
- }
- if (encouragement >= 127 || encouragement <= 7) { //if not a good character
- quittersFlag = 1;
- quit = EOF;
- }
- encouragement = 0; //makes things happy so when I EOF or ^D in middle I don't loop forever.
- }
- return quittersFlag;
- }
- int exitState (int currentState) {
- extern int quittersFlag;
- if (quittersFlag == 3) {
- return
- printf("\n\nYay! Your character made it safely to the end. You win!\n");
- }
- if (quittersFlag == 2) {
- return
- printf("\n\nYou lost @, he couldn't find his way back!\n\n...\n\n...\n\nBut please play again.\nI'm sure he'll find his way back by the time you try again.\n");
- }
- if (quittersFlag == 1) {
- return
- printf("\n\nQUITTER!\n\nYOU FAILED MISERABLY!\n\n...\n\n...\n\nBut please don't give up, play again. @ misses you already.\n");
- }
- else return 0;
- }
- int main(void) {
- extern int quittersFlag;
- while (quittersFlag == 0) {
- introduction();
- gamestate();
- }
- exitState(quittersFlag);
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement