The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | May 2017 |
| Last Sign in: | 398 Weeks Ago, 4 Days Ago |
| Questions Answered: | 66690 |
| Tutorials Posted: | 66688 |
MCS,PHD
Argosy University/ Phoniex University/
Nov-2005 - Oct-2011
Professor
Phoniex University
Oct-2001 - Nov-2016
Please us the following library only
Â
Library Functions To Use:
Â
From simpleio: get_char()
Â
Standard Library: rand(), srand()
Â
Do not need to use Arrays and so no 2d gride is required. Just need to be like the below example.
This program implements a primitive game in which the player tries to find a pot of gold.
Behavior: the game is played on an implicit grid of 2D coordinates. The grid boundaries
are:
Left: 0
Right: 10
Bottom: 0
Top: 10
Initially, the player is placed at coordinate (5,5).
The program places the pot of gold at a random location on the grid that is distinct from
(5,5). (The player has to do at least some work to get rich).
Behavior:
The program prompts the user to enter a direction to move as a single char
n (north)
s (south)
e (east)
w (west)
If any other letter is entered, an error message is printed and the user is
reprompted.
If a valid direction is entered, the following happens:
If the move would result in the player leaving the board, the program
prints A????1OUCH!A????1 and the player remains at his/her current location.
If the move places the player on top of the gold, the program prints
A????1HOORAY!A????1, reports the number of moves the player made and
terminates.Otherwise, the player is moved to the new location and the program
prints:
A????1GETTING WARMER!A????1 if player has gotten closer to the gold.
A????1GETTING COLDER!A????1 if the player is farther from the gold.
Example:
% ./search
Direction: n
GETTING WARMER!
Direction: w
GETTING COLDER!
Direction: e
GETTING WARMER!
Direction: e
GETTING WARMER!
Direction: n
GETTING COLDER!
Direction: e
GETTING WARMER!
Direction: s
HORRAY!
Total Moves: 7
Goodbye!
Hel-----------lo -----------Sir-----------/Ma-----------dam-----------Tha-----------nk -----------You----------- fo-----------r u-----------sin-----------g o-----------ur -----------web-----------sit-----------e a-----------nd -----------and----------- ac-----------qui-----------sit-----------ion----------- of----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n.P-----------lea-----------se -----------pin-----------g m-----------e o-----------n c-----------hat----------- I -----------am -----------onl-----------ine----------- or----------- in-----------box----------- me----------- a -----------mes-----------sag-----------e I----------- wi-----------ll