#include #include // Helper function to handle input and show help void getInput(char *prompt, char *input) { while (1) { printf("%s", prompt); scanf("%s", input); if (strcmp(input, "help") == 0 || strcmp(input, "HELP") == 0) { printf("\n--- Available Commands ---\n"); printf("ENTER / LEAVE – Enter or exit the cave\n"); printf("LEFT / RIGHT – Choose a path\n"); printf("YES / NO – Confirm or decline actions\n"); printf("egg – Solve the puzzle (riddle answer)\n"); printf("help – Show this help message\n"); printf("---------------------------\n\n"); } else { break; } } } int main() { char choice[20]; char answer[20]; int hasTreasure = 0; int hasShamrock = 0; int hasSword = 0; int hasTorch = 1; // Player starts with a torch printf("Welcome, brave adventurer, to the Caverns of Mystery!\n"); getInput("Do you want to ENTER or LEAVE? ", choice); if (strcmp(choice, "ENTER") == 0 || strcmp(choice, "enter") == 0) { printf("You walk into the cave and find a hallway with two doors.\n"); getInput("Do you choose the LEFT or RIGHT door? ", choice); if (strcmp(choice, "LEFT") == 0 || strcmp(choice, "left") == 0) { printf("The room is dusty and filled with webs. You see a chest.\n"); getInput("Do you want to OPEN it? (YES/NO): ", choice); if (strcmp(choice, "YES") == 0 || strcmp(choice, "yes") == 0) { printf("You found a bag of gold coins! 🎉\n"); hasTreasure = 1; } else { printf("You leave the chest untouched.\n"); } printf("There is a narrow passage leading deeper into the chamber...\n"); getInput("Do you want to EXPLORE it? (YES/NO): ", choice); if (strcmp(choice, "YES") == 0 || strcmp(choice, "yes") == 0) { printf("You crawl through the passage... it is pitch black. You cannot see anything.\n"); if (hasTorch) { getInput("Do you want to LIGHT your torch? (YES/NO): ", choice); if (strcmp(choice, "YES") == 0 || strcmp(choice, "yes") == 0) { printf("You light the torch. The room glows with a warm light.\n"); printf("In the center, you find a glowing treasure chest.\n"); printf("Inside, you discover a sword labeled 'E.J.' – Excalibur Junior! 🗡️\n"); hasSword = 1; } else { printf("You choose not to use the torch. It is too dark to proceed safely.\n"); printf("You return to the hallway.\n"); } } else { printf("It is too dark to continue. You return to the hallway.\n"); } } else { printf("You return to the hallway, leaving the passage untouched.\n"); } } printf("You now enter the RIGHT door.\n"); printf("The room glows faintly. You see a pedestal with a lucky shamrock.\n"); getInput("Do you TAKE the shamrock? (YES/NO): ", choice); if (strcmp(choice, "YES") == 0 || strcmp(choice, "yes") == 0) { printf("The shamrock tingles in your hand. You feel lucky and protected! 🍀\n"); hasShamrock = 1; } else { printf("You leave the shamrock alone.\n"); } // Trap Room printf("\nAs you leave, a hidden door slides open and you step through...\n"); printf("Click! The floor gives way — you've fallen into a deep trap!\n"); printf("A stone door blocks your exit. There's a slot shaped like a coin.\n"); if (hasTreasure) { printf("You insert a gold coin into the slot... The door creaks open. You are free!\n"); } else { printf("You have no gold to offer. The trap seals shut forever. 😵\n"); printf("Game over.\n"); return 0; } // Puzzle Room printf("\nYou enter a chamber with ancient writing on the wall.\n"); printf("A stone door blocks the exit. A voice booms:\n"); printf("\"Answer this riddle to pass:\"\n"); printf("\"What has to be broken before you can use it?\"\n"); getInput("Type your answer: ", answer); if (strcmp(answer, "egg") == 0 || strcmp(answer, "Egg") == 0) { printf("The door slides open silently. Well done!\n"); } else { printf("The voice says, \"That is not correct. You are not ready.\"\n"); printf("You are trapped in the puzzle room forever. 💀\n"); return 0; } // E.J. Unlock Room printf("\nYou find a mysterious stone door with a strange sword-shaped slot.\n"); if (hasSword) { getInput("Do you want to insert 'E.J.' into the slot? (YES/NO): ", choice); if (strcmp(choice, "YES") == 0 || strcmp(choice, "yes") == 0) { printf("You insert E.J. into the slot... the stone door rumbles open!\n"); printf("Inside, you find a chamber filled with ancient books and enchanted scrolls. 📚✨\n"); } else { printf("You decide not to insert E.J. and walk away from the door.\n"); } } else { printf("You do not have the right item to open this door. Perhaps a special sword could fit...\n"); } // Final Wizard Room printf("\nYou emerge into the final chamber, where an old wizard awaits.\n"); printf("The wizard says:\n"); printf("\"Adventurer, the path forward is not always lit by courage alone.\n"); printf("Wisdom lies in choices made, and strength comes not just from treasures,\n"); printf("but from the trials you have overcome.\"\n"); if (hasShamrock) { printf("The shamrock glows softly, and the wizard smiles. \"You carry luck and virtue. You may enter.\"\n"); printf("Inside the room, you find the Legendary Sword of Code! 🗡️\n"); } else { printf("The wizard frowns slightly. \"Return when fortune favors you with the lucky shamrock.\"\n"); printf("You must turn back, but his words linger in your mind.\n"); } printf("\n--- Adventure Summary ---\n"); printf("Treasure found: %s\n", hasTreasure ? "Yes" : "No"); printf("Shamrock collected: %s\n", hasShamrock ? "Yes" : "No"); printf("Found 'E.J.': %s\n", hasSword ? "Yes" : "No"); } else { printf("You decide to leave. Maybe another day...\n"); } printf("\nThanks for playing!\n"); return 0; }