Jayd Saucedo

Blog

MAZE: The World's Most Challenging Puzzle

Last semester I took a class titled “Graphical User Interfaces”, the platform we'd be using in the class was Android. Since we'd be collaborating in our groups using git it fulfilled the requirements for my “software engineering tools” class. Thus I was given a substitution while taking a far more interesting class. The way the class was structured was that there were no tests, about 7 smaller projects that were given in 1 week increments. And then halfway through the semester we were free to use the rest of the time in the semester to develop a project of our own.

I joined a group with Randy Ledbetter and Taylor Carrington. Randy had the idea to turn a book titled “Maze: The World's Most Challenging Puzzle” into an android application. The book was originally written by Christopher Manson in 1985. The book is no longer being published, but you can still find copies out there. The Maze uses the book as a medium, it takes place in a mansion and your goal is to find the shortest route to the center and back while solving the puzzle in the center room--if you can figure out what the puzzle is.

Our goals for this game was to not only link between the rooms, but to present the text as captions at the bottom of the screen, Present the user with a main menu where they could either restart the maze or continue. Allow the user the option to turn off the captions. Have an instructions page and a credits page. And in each room have a button to link back the main menu and a counter to show them how many steps into the maze they have gone. Here’s a mockup of what one of the rooms looks like:

You can see the rest of the mock images here

Randy, Taylor, and I split the work between us as best we could. Randy was able to find a key mechanism that would allow us to capture the event in which a person tapped on a door. We used a method in which we overlay an image map on top of the image of the room.

Here’s an example:

The room

The map

To detect that a certain color was touched we had a main “onTouch” event that fired whenever the screen was touched. We then tied into an existing library that is able to pull the color of the spot that was touched. This is how we link back to the image map. Using the libraries, our detection code looked like this:

We then sent that off to a function to recreate the view using the new room and image maps. In order to figure out which door linked where. Rather than creating a whole bunch of logic, such as: “if(room == 1 and color == cyan){ nextRoom = room3;}”, I thought it would be more efficient to throw everything into a map. That way our next room can be generated by simply running our queries through the map like this:

If you read the code, you’ll notice that the path is also kept track of in a separate array. This is to validate a win state and to resume your last room if you exit the application. This is how we access the data in our map, but the tedious part was putting the room relationships into the map. Here’s a sneak preview, but the actual “roomMap” class is hundreds of lines long. Keep in mind, there’s 45 rooms!

Not only did the last room you were in when you exited the application have to be saved, but so did the complete path of how you got to that room. This was needed to validate the win state. So part of my task was collecting this information as you navigated through the maze and then saving that before you exited the game. Collecting that information was easy enough, just keep adding the room number to an array as the “getCurRoom” event gets called. However, Java Android has no easy way to save an array of string data. I could have converted it to a blob and in hindsight that might have been cleaner. The method I chose at the time was to convert my array of strings into a json string. Again, Java Android has no easy way to do this but the library “gson” by google allows you to convert any Java data type into json. It’s quite amazing and easy to use. Here’s an example of some code using gson to convert my array of room strings into a json string:

The preferences you could set in the menu also had to be stored using sharedPreferences. There were so many other features in this app that I couldn't possibly talk about them all, but these are some of the things that I worked on. Randy did a lot of the overall design work with the main menu and the navigation , as well as the subtitle work and Taylor did a lot of coding for the interface and the linking between the views. It was actually the most pleasant group experience I have ever had, because of how well everyone contributed, and our project ended up being one of the most polished applications to come out of that class.

You can view the entire source and download the apk at our github: https://github.com/RandyLedbetter/maze