DPA 4010 / 6010

Spring 2016

Load a Maze

Homework Assignment 3

Due: Midnight, Wednesday, February 24


This assignment is to prepare for the next assignment, which will be a very simple maze-based adventure game. The job this week is to load the maze that will support the game play, and display it on the screen.

Your program will need to be able to use a filename parameter from the command line. For example, if your program is named loadmaze, and your maze is stored in a text file named smallmaze.txt, then the command to run the program should be

./loadmaze smallmaze.txt

The program should get the filename from the command line, open the file, and then read its contents, building a 2D array to hold the maze. The format of the maze file will be as in the following example of a little maze containing 5 rows and 7 columns.

5 7
w w w w w w w
s c c c w h w
w w w c w c e
w b c c c c w
w w w w w w w

The first line of the file contains the number of rows and the number of columns. The subsequent lines contain characters indicating what should be placed in each cell of the 2D array holding the maze. The character codes are as follows: w - wall, c - corridor (these mark the path that the player must follow), s - starting position, e - ending goal position, b - evil boss cell, h - health cell. After reading in the maze, your program should display it using a color coding to mark the various cells. In the example below, the start cell is black, the goal cell is gold, the walls are yellow, the boss cells are red, and the health cells are green.

small maze image
Example small maze

Your program should automatically redraw the screen if the display is covered and then uncovered. The program should not quit until either the 'q' or 'esc' key is pressed on the keyboard.

In this zip file you will find two maze description files. You should debug your program on the small maze file: smallmaze.txt
When it is working, then you should make sure that it also works on the big maze in the file: maze.txt


Advanced Extension: You should not have to modify your program to handle different maze files. It should work on any maze, using malloc to allocate the needed space for the maze array, once you have read the number of rows and columns from the file. Also, you should size the viewport so that its proportions are consistent with the number of rows and columns.

Please submit your program using the standard handin procedure. You should include your program source code and a Makefile.