SteelGolem icon

text adventure game v0.0.1

SteelGolem | PRO | 08/25/15 07:09:12 PM UTC | 0 ⭐ | 426 👁️ | Never ⏰ | []
C |

2.93 KB

|

None

|

0 👍

/

0 👎

// v0.0.1
 
#include <stdio.h> // printf(), getchar()
#include <stdlib.h> // system()
#include <ctype.h> // tolower()
 
#define FALSE 0
#define TRUE 1
 
#define ITEM_ID_TORCH 1
 
int main(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;
 
    // temporary variables
    int command;
    int i;
 
    while (1)
    {
        system ("CLS");
        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());
        printf ("\n");
        
        // check room commands
        if (command == '1')
        {
            printf ("The King says, \"Please, take what we have provided from the treasure chest,\n");
            printf ("and save the kingdom!\"\n");
            printf ("\n");
            system ("PAUSE");
        }
        if (command == '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");
            system ("PAUSE");
        }
        if (command == '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");
            system ("PAUSE");
        }
        
        // check common commands
        if (command == 'm')
        {
            printf ("You have no magic spells.\n");
            printf ("\n");
            system ("PAUSE");
        }
        if (command == 'i')
        {
            printf ("You have:\n");
            printf ("\t%d Gold\n", gold);
            if (num_items > 0)
            {
                for (i = 0; i < num_items; i++)
                {
                    if (items[i] == ITEM_ID_TORCH) printf ("\tTorch\n");
                    // TODO: more item types
                }
            }
            else
            {
                printf ("\tNo items\n");
            }
            printf ("\n");
            system ("PAUSE");
        }
        if (command == '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");
            system ("PAUSE");
        }
        // TODO: this should be part of the room commands, shouldn't it?
        if (command == 'a')
        {
            printf ("You don't find anything else.\n");
            printf ("\n");
            system ("PAUSE");
        }
        if (command == 'q') return 0;
    }
    
    return 0;
}

Comments