Project 2: Sailing the Seas (Yar har deedle dee dee, you are a pirate!)
Implement a sailing game.
The Sailing Map
1) Create a two dimensional 10x10 character array.
2) Implement an initMap function:
- Populate the array with tilde ‘~’, period ‘.’ and the ‘S’ characters so that if you output the array (nested loop) it looks like this:
~ . . . . . . . . .
~ ~ . . . . . . . .
~ ~ ~ . . . . . . .
~ ~ ~ ~ . . . . . .
~ ~ ~ ~ ~ . . . . .
~ ~ ~ ~ ~ S . . . .
~ ~ ~ ~ ~ ~ ~ . . .
~ ~ ~ ~ ~ ~ ~ ~ . .
~ ~ ~ ~ ~ ~ ~ ~ ~ .
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
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 initially located in the middle of the map. 3) Implement a displayMap function: - Use a nested loop to outputs the updated map to console. - Pad the map image with coordinate values. - The initial display grid should appear exactly as follows:
0 ~ . . . . . . . . .
1 ~ ~ . . . . . . . .
2 ~ ~ ~ . . . . . . .
3 ~ ~ ~ ~ . . . . . .
4 ~ ~ ~ ~ ~ . . . . .
5 ~ ~ ~ ~ ~ S . . . .
6 ~ ~ ~ ~ ~ ~ ~ . . .
7 ~ ~ ~ ~ ~ ~ ~ ~ . .
8 ~ ~ ~ ~ ~ ~ ~ ~ ~ .
~ ~ ~ ~ ~ ~ ~ ~ ~ ~
0 1 2 3 4 5 6 7 8 9
The Option Menu
1) Implement a validate function:
- Accept 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.
2) Implement a menu function:
- Loop all code within this function until the ship sinks or is lost.
- Call the displayMap function.
- Display this option menu and handle it with the switch statement:
Example Output(input is bold and italicized) (n)orth (s)outh (e)ast (w)est
Which way, Captain? N
- Call the validate function to insure case consistency.
- Handle menu selection with a switch statement.
Options N/E/S/W - Valid inputs should call the moveShip function.
- If the ship moves into a land square ‘.’ the ship is sunk.
- If the ship sails off of the map the ship is lost.
- Boolean variables should be used to exchange isSunk/isLost status between the moveShip and menu functions.
- If the ship sinks, end the sailing loop and output: “CRASH!!! You boat begins to sink!”
- If ship is lost, end the sailing loop and output: "ARGGGH!!!...you have been lost at sea!!!"
- Invalid inputs (default case) output: "Pick a direction!".
3) Implement a moveShip function:
- Accept a direction as input, along with any other required parameters.
- Updates the map array, isSunk, isLost and any other necessary variables.
- Based upon the input, the ship should:
a) Move, if the move will be onto a ocean tile.
b) Crash, if the move will be onto a land tile.
c) Become lost, if the move will shift the ship off of the map.
* Possible directions are: N W E S
I am highly confident you misunderstand the purpose of the forum; however, if you place the code that you have worked on, people may offer to help. You may get lucky to find someone to do it for free. Worst case scenario, you may put the posting on the jobs section. Happy coding!