Advertisement
SteelGolem

text adventure game v0.0.1

Aug 25th, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.93 KB | None | 0 0
  1. // v0.0.1
  2.  
  3. #include <stdio.h> // printf(), getchar()
  4. #include <stdlib.h> // system()
  5. #include <ctype.h> // tolower()
  6.  
  7. #define FALSE 0
  8. #define TRUE 1
  9.  
  10. #define ITEM_ID_TORCH 1
  11.  
  12. int main(void)
  13. {
  14.     // hero variables
  15.     int level = 1;
  16.     int hp = 10, max_hp = 10;
  17.     int mp = 0, max_mp = 0;
  18.     int atk = 1;
  19.     int def = 0;
  20.     int gold = 0;
  21.     int num_items = 0;
  22.     int items[8]; // array of IDs representing items
  23.    
  24.     // room variables
  25.     int throne_room_chest_empty = FALSE;
  26.  
  27.     // temporary variables
  28.     int command;
  29.     int i;
  30.  
  31.     while (1)
  32.     {
  33.         system ("CLS");
  34.         printf ("\n");
  35.        
  36.         // room description
  37.         printf ("You are in the King's throne room.\n");
  38.         printf ("\n");
  39.        
  40.         // room commands
  41.         printf ("[1] Speak to the King\n");
  42.         printf ("[2] Speak to the guards\n");
  43.         printf ("[3] Check treasure chest\n");
  44.         printf ("[4] Leave throne room\n");
  45.         printf ("\n");
  46.        
  47.         // common commands
  48.         printf ("[m] Magic   [i] Inventory  \n");
  49.         printf ("[s] Status  [a] Search area\n");
  50.         printf ("[q] Quit\n");
  51.         printf ("\n");
  52.        
  53.         // user input retrieval
  54.         printf ("Command? ");
  55.         command = tolower(getchar());
  56.         printf ("\n");
  57.        
  58.         // check room commands
  59.         if (command == '1')
  60.         {
  61.             printf ("The King says, \"Please, take what we have provided from the treasure chest,\n");
  62.             printf ("and save the kingdom!\"\n");
  63.             printf ("\n");
  64.             system ("PAUSE");
  65.         }
  66.         if (command == '2')
  67.         {
  68.             printf ("One of the guards says, \"The Princess was kidnapped a week ago, and the King\n");
  69.             printf ("is very worried about her... Please! Rescue the princess!\n");
  70.             printf ("\n");
  71.             system ("PAUSE");
  72.         }
  73.         if (command == '3')
  74.         {
  75.             if (throne_room_chest_empty)
  76.             {
  77.                 printf ("The chest is empty.\n");
  78.             }
  79.             else
  80.             {
  81.                 printf ("You find a Torch and 180 Gold in the chest!\n");
  82.  
  83.                 gold += 180;
  84.                 items[num_items++] = ITEM_ID_TORCH;
  85.                
  86.                 throne_room_chest_empty = TRUE;
  87.             }
  88.             printf ("\n");
  89.             system ("PAUSE");
  90.         }
  91.        
  92.         // check common commands
  93.         if (command == 'm')
  94.         {
  95.             printf ("You have no magic spells.\n");
  96.             printf ("\n");
  97.             system ("PAUSE");
  98.         }
  99.         if (command == 'i')
  100.         {
  101.             printf ("You have:\n");
  102.             printf ("\t%d Gold\n", gold);
  103.             if (num_items > 0)
  104.             {
  105.                 for (i = 0; i < num_items; i++)
  106.                 {
  107.                     if (items[i] == ITEM_ID_TORCH) printf ("\tTorch\n");
  108.                     // TODO: more item types
  109.                 }
  110.             }
  111.             else
  112.             {
  113.                 printf ("\tNo items\n");
  114.             }
  115.             printf ("\n");
  116.             system ("PAUSE");
  117.         }
  118.         if (command == 's')
  119.         {
  120.             printf ("Level: %d\n", level);
  121.             printf ("\tHP:  %d/%d\n", hp, max_hp);
  122.             printf ("\tMP:  %d/%d\n", mp, max_mp);
  123.             printf ("\tAtk: %d\n", atk);
  124.             printf ("\tDef: %d\n", def);
  125.             printf ("\n");
  126.             system ("PAUSE");
  127.         }
  128.         // TODO: this should be part of the room commands, shouldn't it?
  129.         if (command == 'a')
  130.         {
  131.             printf ("You don't find anything else.\n");
  132.             printf ("\n");
  133.             system ("PAUSE");
  134.         }
  135.         if (command == 'q') return 0;
  136.     }
  137.    
  138.     return 0;
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement