Question: 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
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 whos health reaches 0 loses.
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.
Create maze algorithm
Function create_maze( maze_size: whole number, monsters: whole number) returns maze: [1..N][1..N] of Strings
maze = [maze_size][maze_size] array of strings, filled with 0
maze[random x] [random z] = P
tempx = random whole number between 1 and maze_size
tempy = random whole number between 1 and maze_size
if maze[tempx] [tempy] != P
maze[tempx] [tempy] = E
else if tempx < maze_size
maze[tempx+1] [tempy ] = E
else if tempy < maze_size
maze[tempx] [tempy+1] = E
else if tempx > 1
maze[tempx-1] [tempy] = E
else
maze[tempx] [tempy-1] = E
end if statement
if monsters > 0
tempx = random whole number between 1 and maze_size
tempy = random whole number between 1 and maze_size
if maze[tempx] [tempy] != P AND maze[tempx] [tempy] != E
i.maze[tempx] [tempy] = M
end if statement
tempx = random whole number between 1 and maze_size
tempy = random whole number between 1 and maze_size
if maze[tempx] [tempy] != P AND maze[tempx] [tempy] != E
i.maze[tempx] [tempy] = M
end if statement
tempx = random whole number between 1 and maze_size
tempy = random whole number between 1 and maze_size
if maze[tempx] [tempy] != P AND maze[tempx] [tempy] != E
i.maze[tempx] [tempy] = M
end if statement
end if statement
return maze
Random Move Algorithm
function random_move(maze: NxNarray of strings) returns maze
original_playerx = x coordinate for string P in maze
original_playery = y coordinate for string P in maze
playerx = x coordinate for string P in maze
playery = y coordinate for string P in maze
randomx_dir = random number between 1 and 3
randomy_dir = random number between 1 and 3
if randomx_dir == 1
playerx = playerx+1
if playerx > N
i.playerx = 1
end if statement
end if statement
if randomy_dir == 1
playery = playery + 1
if playery > N
i.playery = 1
end if statement
end if statement
if randomx_dir == 2
playerx = playerx 1
if playerx < 1
i.playerx = N
end if statement
end if statement
if randomy_dir == 2
playery = playery 1
if playery < 1
i.playery = N
end if statement
end if statement
if maze[playerx, playery] == M
print You encountered a monster!
print Rolling the dice!
pick_a_number = random # between 1 and 6
your_choice = user entered #
if your_choice == pick_a_number
i.print You win! You get to keep going!
ii.print Your new coordinates are
iii.print playerx
iv.print playery
v.maze[playerx] [playery] = P
vi.maze[original_playerx] [original_playery] = 0
else
i.print You lost. The monster kill you
ii.maze[1..N][1..N] = L
end if statement
else if maze[playerx] [playery] == E
print You win!
maze[1..N][1..N] = W
else
print Your new coordinates are
print playerx
print playery
maze[original_playerx] [original_playery] = 0
maze[playerx] [playery] = P
end if statement
return maze
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
