Suppose you are in the middle of a perfectly square island jungle and are trying to escape to the shore, where there is a boat waiting to take you home. However, between you and the boat lie four life-threatening hazards at unknown (random) locations in the jungle -- an elephant, a lion, a snake, and a cliff -- as pictured below.
Initially, you are located at (0, 0) in the middle of the island, the boat is at (-3, 10) on the North shore, and the four hazards are at other locations unknown to you.
The purpose of this program is to randomly locate both the boat and the hazards in the jungle, and then monitor your progress as you take individual steps out of the jungle toward the boat. The program should initially tell you the location of the boat and fix your initial location at (0,0), the middle of the jungle. But the hidden locations of the hazards should be read from a separate file by the program and not displayed on the screen. Your progress toward the boat will be monitored by the program, which will record and display your new location after each move.
Each of your moves can be one step in either the North, South, East, or West direction. Each integer x or y coordinate value in the picture above represent a single step. For instance, if you take one step North from your starting location, your new location will be (0, 1); taking one step East would have left you at (1, 0); and so on. This program should have two major parts. One part initializes the game by reading the random locations of the four hazards and the boat from the separate file named 'unknowns' (this file is provided in the CS101/Tucker folder). You can assume that the x and y coordinates of the boat are the first two integers in the file, and each of the four hazards is located by a separate pair of integers in the file. Thus, the file will have 10 integers in all.
The second part of the program "plays" the game by asking you to take a series of steps in any of four directions (N, S, E, or W), keeping track of your location after each step, and reporting to you whether you have escaped the jungle or been consumed by one of the hazards along your route.
Thus, it is good to think of designing this program using a separate procedure, say Initialize, that initializes certain variables before the game begins. That procedure should open and read integers from the file 'unknowns' in order to obtain the initial locations of the boat and the hazards.
The second part of your program should include a while loop, in which each repetition will retrieve a single move (N, E, S, or W) that you take, record its effect on your position in the jungle, and display your new position. That display should also report any unusual outcome of that move (i.e., being consumed by a hazard, reaching the shore, or reaching the boat safely). The possibility of being consumed by a hazard should be separately defined by a function, say IsConsumed, whose parameters are your position and the positions of the four hazards. This function should return a Boolean result, true or false, depending on whether or not your current position is identical with that of one of the four hazards.
The Initialize procedure should have these locations as variable (VAR) parameters, and should handle all the file input that is required to fix these locations. It should also display to the user the location of the boat.
The function IsConsumed should also have these locations as parameters, as well as your location.
The second part of the program should be controlled by a while loop. What should occur at each repetition of that loop? That is, what is needed to model a single step in the jungle? Certainly the program needs to read an input move from the user (N, S, E, or W), interpret that move by changing the value of the x- or y-coordinate of their current location, checking whether the new location encounters either a hazard, the boat, or the ocean, and displaying that outcome to the user. Determine the condition under which this while loop will finally terminate.