Advertisement
Conner_36

sillyGame v2

Jun 30th, 2011
470
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.77 KB | None | 0 0
  1. //Created by Conner_36
  2. //
  3. //the extern ints are there because on my computer I have the functions in different files
  4.  
  5. #include <stdio.h>
  6. #include <stdlib.h>
  7.  
  8. int quittersFlag;
  9.  
  10. int wait (void) {
  11.    
  12.     int c;
  13.     extern int quittersFlag;
  14.    
  15.     printf("\n(Waiting politely for you to press the RETURN key...)");
  16.    
  17.     while ((c = getchar()) != '\n') {
  18.         if (c == EOF) {
  19.             return quittersFlag = 1;
  20.             }
  21.     }
  22.    
  23.     return 0;
  24. }
  25.    
  26. int introduction (void) {
  27.    
  28.     extern int quittersFlag;
  29.    
  30.     printf("This is your character -> @\n\nSay hello!\n");
  31.     if (wait()!=0) {
  32.         return quittersFlag;
  33.     }
  34.     printf("\n@ is excited about his new master...\n");
  35.     printf("\n@ needs some word food to complete his upcoming journey.\n");
  36.     if (wait()!=0) {
  37.         return quittersFlag;
  38.     }   printf("\nAny letter or number on your keyboard will do.\n");
  39.     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");
  40.     if (wait()!=0) {
  41.         return quittersFlag;
  42.     }   printf("\nIf this seems too great a responsibility you can always press (control-D)\n");
  43.     if (wait()!=0) {
  44.         return quittersFlag;
  45.     }   printf("\nI won't hold it against you.\n");
  46.     if (wait()!=0) {
  47.         return quittersFlag;
  48.     }   printf("\nStill here?\n");
  49.     if (wait()!=0) {
  50.         return quittersFlag;
  51.     }   printf("\nVery well then... its time you give some motivation to your character:\n");
  52.    
  53.     return quittersFlag;
  54. }
  55.  
  56. int gamestate (void) {
  57.    
  58.     char characterSpace[80];
  59.     char character = '@';
  60.     char line = '_';
  61.    
  62.     char encouragement = 1;
  63.    
  64.     int counter;
  65.     int externCounter = 0;
  66.    
  67.     int quit;
  68.     extern int quittersFlag;
  69.    
  70.     while (quit != EOF) {
  71.         for (counter =  0; counter < 80; counter++) {
  72.             characterSpace[counter]=line;
  73.         }
  74.        
  75.         characterSpace[counter]='\0';//sets the end of the array for string compatibility
  76.        
  77.         scanf("%c", &encouragement);
  78.        
  79.         if (encouragement >= 65) { // if a letter
  80.             if (externCounter <= 60) {
  81.                 externCounter+=4;
  82.             } else {
  83.                 externCounter+=3;
  84.             }
  85.         }
  86.        
  87.         if (encouragement <= 57 && encouragement >= 48) { // if a number
  88.             if (externCounter <=5) {
  89.                 externCounter--;
  90.             } else {
  91.                 externCounter-=5;
  92.             }
  93.         }
  94.        
  95.         if (encouragement == '\n') {
  96.             printf("\n");
  97.             printf("Sending motivation to @. He feels like going to position %d...\n", externCounter);
  98.            
  99.             if (externCounter > -1) {
  100.                  characterSpace[externCounter]=character;
  101.             }
  102.            
  103.             if (externCounter >= 80 ) {
  104.                 characterSpace[79]='@';
  105.                 quittersFlag = 3;
  106.                 quit = EOF;
  107.                
  108.             } else if (externCounter <= -10) {
  109.                 quittersFlag = 2;
  110.                 quit = EOF;
  111.                
  112.             } else {
  113.                 printf("\n(care to tell him more words of wisdom?)\n");
  114.             }
  115.            
  116.             printf("\n%s\n\n", characterSpace); // draws the characters world
  117.            
  118.         }
  119.        
  120.         if (encouragement >= 127 || encouragement <= 7) { //if not a good character
  121.             quittersFlag = 1;
  122.             quit = EOF;
  123.         }
  124.        
  125.         encouragement = 0; //makes things happy so when I EOF or ^D in middle I don't loop forever.
  126.     }
  127.    
  128.     return quittersFlag;
  129.    
  130. }
  131.  
  132. int exitState (int currentState) {
  133.     extern int quittersFlag;
  134.    
  135.     if (quittersFlag == 3) {
  136.         return
  137.         printf("\n\nYay! Your character made it safely to the end. You win!\n");
  138.     }
  139.    
  140.     if (quittersFlag == 2) {
  141.         return
  142.         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");
  143.     }
  144.    
  145.     if (quittersFlag == 1) {
  146.         return
  147.         printf("\n\nQUITTER!\n\nYOU FAILED MISERABLY!\n\n...\n\n...\n\nBut please don't give up, play again. @ misses you already.\n");
  148.     }
  149.    
  150.     else return 0;
  151. }
  152.  
  153. int main(void) {
  154.    
  155.     extern int quittersFlag;
  156.    
  157.     while (quittersFlag == 0) {
  158.        
  159.         introduction();
  160.         gamestate();
  161.        
  162.     }
  163.    
  164.     exitState(quittersFlag);
  165.    
  166.     return EXIT_SUCCESS;
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement