- Overview
- How It Works
- Game Flow
- Setup
- Files in the Repository
- How to Run
- Gameplay
- Understanding the Code
- Technologies Used
- Contributors
Welcome to Escape Room: DO or DIE, a text-based adventure game where your choices determine the outcome. This project is built using Lex and Yacc (Bison) to demonstrate the use of lexical analysis and parsing. The game challenges the player with various scenarios where they must make quick decisions to survive.
The game is implemented using:
- Lex (lexical analyzer): Breaks down user inputs into tokens.
- Yacc/Bison (parser): Uses these tokens to navigate the game's decision tree based on predefined grammar.
- The player starts in a dangerous situation with multiple choices.
- Each decision leads to another challenge or results in a game-over scenario.
- The player progresses through multiple challenges to ultimately "survive" the game or face a quick demise based on their choices.
Before you start, make sure you have the following installed:
- Flex (for Lex)
- Bison (or Yacc)
- GCC (GNU Compiler Collection)
game.y
: The Yacc (Bison) file containing the grammar rules and game logic.game.l
: The Lex file that defines the tokens based on user input patterns.- These files are present in the src directory.
game.tab.h
: Header file generated by Bison containing token definitions andYYSTYPE
.game.tab.c
: The parser file generated by Bison that includes the logic for grammar parsing.lex.yy.c
: The lexical analyzer file generated by Lex, containing theyylex()
function that returns tokens to the parser.- After running the make command, these files will be generated in the build directory.
game
: The compiled executable file of the game (produced after building the project). Final executable file is present in the root directory after running the make command.
Sample input files (e.g., input1.txt
) are provided to demonstrate how to play the game using predefined inputs.
-
Compile the game:
make
This will produce the executable file named
game
. -
Run the game:
./game
-
Input from a file: If you want to play using a pre-defined input, you can redirect a file using:
./game < input1.txt
The game presents a series of challenges, each with different scenarios. Here are some of the challenges you’ll encounter:
- Scenario: You're trapped in a dark cave with a bear approaching.
- Options:
flare
orclimb
.
- Scenario: Solve a math problem to unlock a treasure.
- Input:
23
for correct answer.
- Scenario: Choose whom to save in a burning building.
- Options:
option1
,option2
,option3
,option4
.
- Scenario: Solve a riddle.
- Input: Answer for the riddle,
fire
.
- Scenario: Answer the ultimate question to survive.
- Input:
CLR
.
If you make an incorrect choice or input a wrong answer:
- The game will provide a context-specific failure message, explaining the consequences of your decision.
- Your game will end, displaying a "GAME OVER" message that reflects the scenario where you failed.
- Each incorrect choice in the game leads to a unique description of how you failed, adding to the narrative aspect of the game.
- After displaying the failure message, the game terminates automatically. You’ll need to restart the game to try again.
Here’s a breakdown of the outcomes for wrong answers:
- Challenge 1: Choosing to
climb
instead of using theflare
results in a bear attack. - Challenge 2: Inputting the wrong number leads to a math-related taunt and ends the game.
- Challenge 3: Selecting options other than
option1
results in a humorous critique of your priorities. - Challenge 4: Providing an incorrect answer to the riddle makes the old lady angrier, leading to game over.
- Bonus Challenge: A wrong answer to the final question results in disappointment, ending the game with a humorous jab at your knowledge.
- Tokenizes user input like
flare
,climb
,23
, etc. - These inputs are mapped to tokens (e.g.,
a
,b
,c
, etc.) that the parser understands.
- Defines grammar rules to handle different scenarios in the game.
- Executes actions based on the token stream received from Lex.
- Uses
yylval
to manage token data, such as numbers or strings.
- Each challenge has a success and failure path, represented by the tokens returned by Lex.
- If the player chooses an incorrect option, the game ends with a descriptive failure message.
- The player's progress is tracked, and
result
is updated to reflect their status.
- Lex: For lexical analysis of player inputs.
- Yacc (Bison): For parsing and handling game logic.
- C Language: For implementing the game mechanics and logic.
Made with contrib.rocks.