Sale!

# CENG113 HOMEWORK 2 Solved

Original price was: \$40.00.Current price is: \$35.00.

Category:

## Description

5/5 - (1 vote)

You are expected to write a Python program for a single player game: The Monsters’ World.
The world is a cave that consists of rooms in a 4 × 4 grid. In this cave, there are 3 monsters
(M) and 1 chest of gold (G). The player (P) always starts in the square (1,1). See Figure1.
The world is randomly generated at the beginning of each game and saved into the file named
“monstersworld.txt”. See example file below. (This part is already implemented!)
Figure1:Illustration of a sample world and possible directions.

The aim of the game is to reach the chest of gold while avoiding the monsters. The player
wins the game when he/she reaches the gold, or loses when he/she enters a room with a
monster inside. If the player wins, the score is calculated as 100/number of movements
(Unsuccessful attempts are counted as well). Otherwise, the score is 0.
● If there is a wall in the direction the player moves, he/she gets a warning and stays in
the same room.
● In the squares directly adjacent to a monster, the player will hear a howl.
● At each step, the program should first ask the user for his/her next move.
● After the user enters a direction, the program should first give one of the following
outputs according to the result of the selected move and then, print the total number of
steps taken so far:
○ Yay! You have found the gold.
○ Oh no! You are eaten by a monster.
○ You just heard a howl. Be careful!
○ You are in a safe room. Don’t worry!
○ You hit the wall. Try another move!

○ There is no such direction! Choose right (d), left (a), up (w) or down (s).
● When the game ends, “Game Over!” and the score are printed. If the score is not an
integer, ignore the fractional part (e.g., if the score is 9.15, then print just 9).
● When an empty room is explored, the world is printed with updated info about the
rooms (S:safe, H:howl).
● At the beginning of the game, firstly the initial status is printed as shown in the
example scenario given below.

An example scenario for the given world (user inputs are highlighted):
You are in a safe room. Don’t worry!
Number of steps taken so far is 0.
P ? ? ?
? ? ? ?
? ? ? ?
? ? ? ?
You are in a safe room. Don’t worry!
Number of steps taken so far is 1.
S ? ? ?
P ? ? ?
? ? ? ?
? ? ? ?

You hit the wall. Try another move!
Number of steps taken so far is 2.
You are in a safe room. Don’t worry!
Number of steps taken so far is 3.
S ? ? ?
S ? ? ?
P ? ? ?
? ? ? ?

There is no such direction! Choose right (d), left (a), up (w) or down (s).
Number of steps taken so far is 4.
You just heard a howl. Be careful!
Number of steps taken so far is 5.
S ? ? ?
S ? ? ?
S P ? ?
? ? ? ?

You just heard a howl. Be careful!
Number of steps taken so far is 6.
S ? ? ?
S ? ? ?
S H P ?
? ? ? ?
Oh no! You are eaten by a monster.
Number of steps taken so far is 7.
Game Over!
Score: 0

P
0
0
M
0
G
M
0
0
0
0
0
0
M
0
0

## IMPORTANTNOTES:

– User inputs are case insensitive. (e.g., Wand ware both accepted.)
– Donotmodifythegivencode. Insert your code to the indicated section.
– Your program must consist of atmost400lines, including the given code and