Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // v0.0.3
- /*
- NEXT:
- - add new rooms: castle grounds, castle fields, castle town
- - add battling
- - add shopping
- - add item use submenu
- */
- #include <stdio.h> // printf(), getchar(), fflush()
- #include <ctype.h> // tolower()
- #define FALSE 0
- #define TRUE 1
- void pause (void);
- int game_over = FALSE;
- void show_common_commands (void);
- void check_common_commands (int command);
- // room stuff
- #define ROOM_ID_THRONE_ROOM 1
- int room_id = ROOM_ID_THRONE_ROOM;
- int throne_room_chest_empty = FALSE;
- void throne_room (void);
- // item stuff
- #define ITEM_ID_TORCH 1
- // hero stuff
- 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
- int main (void)
- {
- while (!game_over)
- {
- switch (room_id)
- {
- case ROOM_ID_THRONE_ROOM:
- throne_room();
- break;
- }
- }
- return 0;
- }
- void pause (void)
- {
- printf ("=========================== press ENTER to continue ===========================");
- getchar();
- fflush (stdin);
- }
- void show_common_commands (void)
- {
- printf ("[m] Magic [i] Inventory\n");
- printf ("[s] Status [a] Search area\n");
- printf ("[q] Quit\n");
- printf ("\n");
- }
- void check_common_commands (int command)
- {
- int i;
- 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;
- case 'q': game_over = TRUE;
- }
- }
- void throne_room (void)
- {
- // temporary variables
- int command;
- 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
- show_common_commands();
- // 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;
- case 'a':
- printf ("You don't find anything else.\n");
- printf ("\n");
- pause();
- break;
- }
- // check common commands
- check_common_commands (command);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement