Introduction
Requirement
Final Project, Part 1
Read the last page first!
Grading: You will NOT be demonstrating your final project! This means you must spend
more time on the reflections, design and test documents. The grader will not be able to ask
you questions. If the grader has a question that is not answered in your supplied
documentation then you will likely lose points.
You will create a program that will enable the user to move through a maze. The maze
will contain locked doors that require keys to be opened. Guarding the maze are roving
killer swans. The player isn’t completely defenseless as swans aren’t able to harm a
player who has recently consumed an apple. To escape the maze, the player must
navigate through the maze, swans, and doors until they reach a ladder. Each maze level
contains one ladder that takes the player to the next level of the maze until the final level
is reached. On the final level there is an exit instead of a ladder.
Baba Yaga is back! She has captured the player. Her soulless minion didn’t lock the
door correctly so the player can try to escape. She uses killer swans as the guards. Each
level starts with one swan. Baba Yaga knows the player has left the cell but can only
summon one new swan at a time. For every 30 steps the player takes, a new swan will
randomly appear on the current level.
The player will also encounter apples lying around the maze. The player can pick up and
carry up to two apples at a time. As long as the player has an apple in their inventory,
they may stop and eat it in order to render them invulnerable to swans for the next 15
steps.
Your code will implement this game as follows:
You will start your game with a single command line argument. This will be an integer
value that indicates the number of levels. The floor files will be named floor_# where #
indicates which floor it holds. Your program will always start reading with the first floor.
An example of running the game with a maze that has 3 floors:
./maze 3 (assumes name of first floor is: floor_1)
The maze is defined by a set of text files, each of which contains a single level.
Whenever the game starts or the player reaches a new level, that data must be read from
the appropriate text file. The first line of each file will have two integer values which
describe the number of rows and columns for that level. You must use this to create a
dynamic array of that size and then read in the data for the level. Perform. input
validation on all characters in the file as you read them. Do not load the file and inform
the user there is a problem.
The following characters or symbols describe objects in the levels:
‘#’- walls
‘D’- door
‘L’- Ladder
‘P’- Player
‘S’- Swan (the starting location of the first swan)
‘K’ Key
‘A’- Apple
‘E’- Starting location for each level
‘X’- Exit(one way out)
‘ ‘- empty space (blank character)
You must concatenate the file name with the new floor number. You will not use an
array of filenames? HINT: This will require string streams.
You must display that level to the user. Then you will accept the following commands
from the user:
‘w’ move up
‘a’ move left
‘s’ move down
‘d’ move right
‘e’ eat apple
‘u’ use ladder
‘q’ quit
Each input from the user must be validated before any action takes place. After each
command, you will update the array, then print the current status of the game to the
screen. Each command is one “step” which you will use to coordinate movement and
summoning of the swans.
You will update the position of the player and all swans after every move entered by the
player. The K (key) and A (apple) symbols will be removed from the maze after the
player picks them up. The D (door) is removed once the player enters that space with a
key. To move between floors, the player must get to the space with the ladder. On the
final level the player must reach the X to exit the maze and make their escape.
The position of each Actor (Swan or Player) will not be stored in the array. It will be
stored in the Player or Swan object. When you read in the initial floor array the ‘S’
should be changed to a blank character. When you display the floor after each move you
will print the array, adding a ‘P’ or ‘S’ as appropriate for each Actor.
Movement- To move around a level the players must use the ‘W’, ‘A’. ‘S, and ‘D’ keys.
Your move function should prevent them from moving through walls, or a door if they
don’t have a key. If the player has a key then they can move through a door. Simply
remove a key from the player and convert the D space to an empty space assuming the
user has at least one.
When the player gets to a ladder space they climb it with a ‘U’ command. The E
character designates where the player starts on the new level. Time (i.e. the number of
steps) is reset on each new level. When the player moves from the starting space, the E
must remain. If a swan catches a player, their location must be changed to the E square.
After each move, the updated maze must be displayed for the user.
When the player moves into a space that contains a key (‘K’) they pick up the key to add
it to their inventory. When a player moves into a space with an apple (‘A’) they pick it
up. A player can hold no more than 3 keys and they can carry only 2 apples. If they enter
a space and cannot hold the key or apple it remains in that space. The player can use an
apple by eating it (‘E’). This makes the swans ignore the player for the next 15 turns,
decreases the apples the player has by 1, and takes an entire step/turn (i.e. they don’t
move that step).
Swans (10 points): The Swans will be similar to the Player, except they move randomly.
They cannot move through walls or doors. They will ignore apples on the ground. If a
swan is in a square adjacent to the player, the player will be moved back to the starting
space for that level. The swans cannot move between levels. For every 30 steps the player
takes, place a new swan at a random valid location in the current level.
Classes. You will need the following classes:
Game class- dynamic array for current floor, array of pointers to actors, int total#_floors,
int current_floor, function to read in floors from a file
Floor class- char [][] tiles, void print to screen, constructor
Actor class: ABSTRACT- int row, int column, char symbol, virtual move
Swan class (inherits Actor)- move (automated),
Player class (inherits Actor)- move (prompt for WASD), keys(s), hold up to 3 keys, hold
up to 2 apples
(You will need a function to send the player back to the start if a swan moves
adjacent to their position. Where do you put that function?)
You must include a makefile and put all files for your assignment in a zip file. Each
class must have separate source and header files. If you do not do this assignment will
NOT be graded.
Grading:
• programming style. and documentation (10%)
• read and create each maze level properly (5%)
• the player and swans move through the maze correctly (10%)
o the apples are picked up and used correctly (5%)
o the keys are picked up and used correctly with the doors (5%)
o the swans send the player back correctly (5%)
• create the Game class and object (5%)
• create the Actor class (5%)
• create the Swan class and object (10%)
• create the Player class and object (5%)
• input validation for commands and reading the files (10%)
• reflections document to include the design description, test plan, test results, and
comments about how you resolved problems while designing and implementing your
program (20%)
You must include a makefile put all files for your assignment in a zip file. If you do not
do this assignment will NOT be graded.
Each class must have separate source and header files. If you do not do this assignment
will NOT be graded.
If your program segfaults at anytime, you will lose 20 points.
Design your Program
As always you should sit down with pencil and paper and sketch out the design. Develop
the necessary algorithms. Do a desk test, i.e. walk through your algorithms and code to
look for logic errors.
Nope! No keyboard yet! Now design your incremental development. Your program
should be decomposed into functional units. If not, go back to the previous paragraph.
Look at the pieces and decide on the order you should use to implement and test each
part. Reading the floor into your program and then moving an actor are probably good
places to start. Then add a level to test using the ladder. Once you have the development
you are ready!
Nope! No keyboard yet. ? Design and organize the directories for your project. You
should have a working directory. Maybe you need a subdirectory to hold the your floor
plans. Have you designed your floor plans? What is there to design? Maybe you can
have a floor that allows you to test only one function or command at a time? Be careful
with file names. The default first file always has the same name. If you overwrite one
then you’ll need to create it again. Always have one directory to save a copy of your
code as you get each increment to compile. If you’re paranoid (I know I am) maybe you
have more than one stash and on different devices?
Now, you’re ready to code!
The moral is: Always plan ahead and make it as complete as you can!