Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // v0.0.2
- #include <stdio.h> // printf(), getchar(), fflush()
- #include <stdlib.h> // system()
- #include <ctype.h> // tolower()
- #define FALSE 0
- #define TRUE 1
- #define ITEM_ID_TORCH 1
- void clear(void);
- void pause(void);
- // hero variables
- int level = 1;
- int hp = 10, max_hp = 10;
- int mp = 0, max_mp = 0;
- int atk = 1;
- int def = 0;
- int gold = 0;
- int num_items = 0;
- int items[8]; // array of IDs representing items
- // room variables
- int throne_room_chest_empty = FALSE;
- int main(void)
- {
- // temporary variables
- int command;
- int i;
- while (TRUE)
- {
- clear();
- printf ("\n");
- // room description
- printf ("You are in the King's throne room.\n");
- printf ("\n");
- // room commands
- printf ("[1] Speak to the King\n");
- printf ("[2] Speak to the guards\n");
- printf ("[3] Check treasure chest\n");
- printf ("[4] Leave throne room\n");
- printf ("\n");
- // common commands
- printf ("[m] Magic [i] Inventory\n");
- printf ("[s] Status [a] Search area\n");
- printf ("[q] Quit\n");
- printf ("\n");
- // user input retrieval
- printf ("Command? ");
- command = tolower(getchar());
- fflush(stdin);
- printf ("\n");
- // check room commands
- switch (command)
- {
- case '1':
- printf ("The King says, \"Please, take what we have provided from the treasure chest,\n");
- printf ("and save the kingdom!\"\n");
- printf ("\n");
- pause();
- break;
- case '2':
- printf ("One of the guards says, \"The Princess was kidnapped a week ago, and the King\n");
- printf ("is very worried about her... Please! Rescue the princess!\n");
- printf ("\n");
- pause();
- break;
- case '3':
- if (throne_room_chest_empty)
- {
- printf ("The chest is empty.\n");
- }
- else
- {
- printf ("You find a Torch and 180 Gold in the chest!\n");
- gold += 180;
- items[num_items++] = ITEM_ID_TORCH;
- throne_room_chest_empty = TRUE;
- }
- printf ("\n");
- pause();
- break;
- }
- // check common commands
- switch (command)
- {
- case 'm':
- printf ("You have no magic spells.\n");
- printf ("\n");
- pause();
- break;
- case 'i':
- printf ("You have:\n");
- printf ("\t%d Gold\n", gold);
- if (num_items > 0)
- {
- for (i = 0; i < num_items; i++)
- {
- switch (items[i])
- {
- case ITEM_ID_TORCH: printf ("\tTorch\n"); break;
- // TODO: more item types
- }
- }
- }
- else printf ("\tNo items\n");
- printf ("\n");
- pause();
- break;
- case 's':
- printf ("Level: %d\n", level);
- printf ("\tHP: %d/%d\n", hp, max_hp);
- printf ("\tMP: %d/%d\n", mp, max_mp);
- printf ("\tAtk: %d\n", atk);
- printf ("\tDef: %d\n", def);
- printf ("\n");
- pause();
- break;
- // TODO: this should be part of the room commands, shouldn't it?
- case 'a':
- printf ("You don't find anything else.\n");
- printf ("\n");
- pause();
- break;
- case 'q': return 0;
- }
- }
- return 0;
- }
- void clear(void)
- {
- #ifdef __GNUC__
- system ("CLEAR");
- #else
- system ("CLS");
- #endif
- }
- void pause(void)
- {
- printf ("--- press ENTER to continue ---");
- getchar();
- fflush(stdin);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement