Escape Room Code Decoding
An escape maze is comprised of multiple rooms. In each room, you will find a code to lead you to the next room. The code is comprised of a word representing the mission clue, followed by a dash(-), followed by a three-digit lock code, followed by a dash(-), followed by a clearance word. There are no spaces in the code.
For example,
TIME-415-CLOCK
The lock code will tell the team to go to the next room on the right if a positive value is returned when it is compared to the master lock code or to the left if a negative value is returned when it is compared to the master lock code. If 0 is returned when it is compared to the master lock code, the team has won and can exit the game.
Team's can also win if the clearance word matches the master clearance word.
They need to know the mission clue to aid in finding the code in the next room.
You will write a program to determine whether the team can exit based on the lock code and clearance word. Regardless, you will print a report that includes:
- the mission clue for the next room;
- the current rooms lock code;
- the current rooms clearance code;
- a positve, negative, or zero value based on the lock code that indicates going right, left, or exiting the escape room; and
- whether your team can exit based on the clearance code.
Code Generator
Master codes are represented by the CodeGenerator.java class. A master code is generated at the start of each game. This UML diagram provides you with the constructors, attributes, and methods you have access to when writing your code.
Class Name: CodeGenerator Class |
Constructors:
|
Data/Attributes:
|
Methods/Behaviors:
|
Algorithms and Planning
You will write a program to do the following:
- create a master code with
CodeGenerator. - create a room code of your choice following the rules for codes outlined above OR obtain this code from the user.
- identify the room mission clue, lock code, and clearance word and report these to the team.
- compare the room lock code and master lock code to let the team know if they should go to the right (if a positive value is returned when comparing the room lock code to the master lock code), to the left (if a negative value is returned when comparing the room lock code to the master lock code), or whether they can exit (if 0 is returned when comparing the room lock code to the master lock code). You do not need to use
ifstatements, as we haven't learned those yet. Just provide directions for how to interpret the value of comparing the room lock code to the master lock code. - check to see if they have the correct clearance word and will have escaped the maze by checking to see if the clearance word is equal to the master clearance word.
Develop Test Cases
Before you write your code, determine a set of test master codes and room codes as well as the results. Be sure to provide tests for all scenarios:
- turning right;
- turning left;
- exiting for getting the lock code correct; and
- exiting for having the same clearance code.
You will want to use the default constructor for CodeGenerator when testing your code.
Develop an Algorithm
Develop algorithms to address each task in this project:
- breaking the room code into it's individual pieces.
- testing to see which direction you should go when you leave the room.
- testing to see if you can exit the room because your clearance code matches.
Write Your Program in an IDE
Now that you have planned out your program, it's time to write it in your IDE. You will have two .java files for this program. It is best practice to create a project folder for both of these files to be stored together.
- The first file will be your main program file. You can name it
EscapeMazeMain.javaand add your algorithm to the body of themainmethod in the starter code provided.
- The second file will be the
CodeGenerator.javafile. Name the file as indicated and copy the code below directly into the file. This file contains numerous concepts we have yet to learn in this course, so don't be alarmed if you don't understand the Java code written.