For this homework assignment, we will begin building a text-based game where you wander a
maze until you encounter the exit. There will be monsters that you may encounter, at which time,
you will have to fight them and win to proceed. Losing to a monster means losing the game and
starting over. Players and monsters have a certain amount of health and are able to do a certain
amount of damage per hit. Fight mechanics are pretty straightforward. You take turns attacking
each other (monster and player) and the first person who’s health reaches 0 loses.
Part 1
For this portion of the assignment, we want to think about building two functions. I want ONLY
your algorithms this week. Next week, I would like you to follow your algorithms and submit the
matlab code that implements your algorithms.
1) Think about how you would create a function to do the following:
a. It accepts at least 2 parameters:
i. A size for the maze (maze should be square or NxN).
ii. A value representing if you want to include monsters in the maze or not.
b. It should return a complete maze with the following features:
i. The maze is actually an NxN array of strings
ii. “0” that’s the number 0 as a string, represents an empty space
iii. “P” represents the players current position (should be randomly assigned)
iv. “E” represents the exit (should be randomly assigned)
v. “M” represents monsters (should be randomly assigned, should be
between 1 and 3 monsters on map)
2) Think about how you would create a function to do the following:
a. It accepts at least 1 parameter
i. A complete maze, like the function described in #1
b. It returns a complete, possibly modified maze
c. The function should randomly move the player from their current x,y position to
either 0, +-1 for x and y.
i. If, as a result of the move, the player would move to the position marked
“E”, then the player wins the game. Set all elements in the array to “W”
and display a winning message
ii. If, as a result of the move, the player would move to a position with a
monster on it (“M”), the player should fight the monster.
1. For this week, the “fight” should just be rolling a random number
(you can choose the range of numbers you pick from), and then
asking the player to guess the number.
a. If the player can guess correctly, then they beat the monster.
The “M” should be replaced with “P” indicating that the
player now occupies that space, and the original element
that contained the “P” should be changed to “0”, and you
should notify the player of their new position.
b. Otherwise, every element in the maze should be replaced
with “L”, and you should display a message indicating that
the game is lost.
iii. If, as a result of the move, you simply land on an empty space, you should
change the previous location to “0”, change the new player position to “P”,
and inform. the player of their new coordinates.
Deliverables
Friday, 10-26-18
Two Algorithms ONLY, one for each function. I do NOT want ANY matlab code this week.
Submit only your algorithms to canvas in a word document. You will be graded on the
correctness of your algorithms.
Friday, 11-2-18
Two functions. I want the functions that correspond to your algorithms. You will be graded on
the correctness of your code AND whether or not your code follows what your algorithm
describes.