Skip to content

jyolx/Escape-Room-Parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Escape Room Simulation : DO or DIE

Table of Contents

Overview

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.

How It Works

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.

Game Flow

  1. The player starts in a dangerous situation with multiple choices.
  2. Each decision leads to another challenge or results in a game-over scenario.
  3. The player progresses through multiple challenges to ultimately "survive" the game or face a quick demise based on their choices.

Setup

Before you start, make sure you have the following installed:

  • Flex (for Lex)
  • Bison (or Yacc)
  • GCC (GNU Compiler Collection)

Files in the Repository

Source Files

  • 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.

Generated Files

  • game.tab.h: Header file generated by Bison containing token definitions and YYSTYPE.
  • 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 the yylex() function that returns tokens to the parser.
  • After running the make command, these files will be generated in the build directory.

Executable

  • 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.

Input Files

Sample input files (e.g., input1.txt) are provided to demonstrate how to play the game using predefined inputs.

How to Run

  1. Compile the game:

    make 

    This will produce the executable file named game.

  2. Run the game:

    ./game
  3. Input from a file: If you want to play using a pre-defined input, you can redirect a file using:

    ./game < input1.txt

Gameplay

The game presents a series of challenges, each with different scenarios. Here are some of the challenges you’ll encounter:

Challenge 1:

  • Scenario: You're trapped in a dark cave with a bear approaching.
  • Options: flare or climb.

Challenge 2:

  • Scenario: Solve a math problem to unlock a treasure.
  • Input: 23 for correct answer.

Challenge 3:

  • Scenario: Choose whom to save in a burning building.
  • Options: option1, option2, option3, option4.

Challenge 4:

  • Scenario: Solve a riddle.
  • Input: Answer for the riddle, fire.

Bonus Challenge:

  • Scenario: Answer the ultimate question to survive.
  • Input: CLR.

What Happens on Wrong Answers

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 the flare 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.

Understanding the Code

Lex (game.l)

  • Tokenizes user input like flare, climb, 23, etc.
  • These inputs are mapped to tokens (e.g., a, b, c, etc.) that the parser understands.

Yacc (game.y)

  • 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.

Game Logic

  • 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.

Technologies Used

  • Lex: For lexical analysis of player inputs.
  • Yacc (Bison): For parsing and handling game logic.
  • C Language: For implementing the game mechanics and logic.

Contributors

Made with contrib.rocks.

About

Escape Room Game Simulation using Lex and Yacc

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 94.0%
  • Yacc 4.8%
  • Other 1.2%