Question: a) Create a two dimensional 10x10 character array. b) Create two global Boolean variables, isLost and isSunk. b) Create an initMap function that does the
a) Create a two dimensional 10x10 character array. b) Create two global Boolean variables, isLost and isSunk.
b) Create an initMap function that does the following: - Populates the array with tilde ~, period . and the S character so that if you output the array (nested loop) it looks like this: This display is a map, where ~ represents the ocean, . Represents land and the S represents a ship that is sailing on the ocean. - The S should be at located in array 6 at position 6 (5,5). Note that coordinate 5,5 on this display is location 6,6 in the array. There is an offset that you need to account for.
c) Create a displayMap function that does the following: - Uses a nested loop to outputs the updated map to console. - Pads the map image with coordinate values. - The initial display grid should appear exactly as follows:
d) Create a validate function that does the following: - Accepts a character as input. - If the char is a lower case letter return the input value. - If the char is an upper case letter, return the lowercase value
. e) Create a menu function that does the following: - Implements a looping switch menu that accepts a letter as input. - Use the validate function to handle input values. - If the input is not a letter use the default case of the switch menu to output "Pick a direction!". - a valid input value should call the moveShip function. - The program should loop if and only if the ship is not sunk or lost. - if ship has sunk, end the loop and output: CRASH!!! You boat begins to sink! - if ship is lost, end the loop and output: "ARGGGH!!!...you have been lost at sea!!!" - as long as the ship S is moved onto an ocean tile (~) the program should continue to loop endlessly. - The menu should output as follows (n is the input): (n)orth (s)outh (e)ast (w)est Which way, Captain? n
f) Create a moveShip function that does the following: - Accepts a character as input which specifies direction. - Based upon the input value, the ship should do the following: - If the ship sails into another ocean square (~) update the S position in the array so that when the program loops displays S at its new location. - If the ship sails off of the map, it is lost. Represent this by setting the isLost variable to true. - If the ship sails onto land, it sinks. Represent this by setting the isSunk variable to true. * Possible directions are:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
