Create a Python program that allows the user to input coordinates onto a 5x5 2D
ID: 3929908 • Letter: C
Question
Create a Python program that allows the user to input coordinates onto a 5x5 2D list in order to
locate and destroy a hidden enemy ship. Make a game board similar to the one below:
A B C D E
1 - - - - -
2 - - - - -
3 - - - - -
4 - - - - -
5 - - - - -
The game begins with a blank board. Randomly
create
the location of a 2x2 enemy ship
but do not display it on the board (Hint:
create a list that stores the location of the upper
left
corner of the ship,
you can calculates the
location of the rest of the ship from that).
The user fires a shot by specifying the row (1
-
5) and column (A
-
E) values. Check to
make sure that the input is a valid entry, within the bounds of the
list
, and that it is not a
location that has already been
chosen. If the shot hits the ship then display a ‘*’ symbol
in that location to designate a ‘hit’. If the shot does not hit the ship, then display an ‘x’ in
that location to designate a ‘miss’.
When the user has hit all four spots that the ship
occupi
es
then the user has won. Reset
the board and re
-
randomize the ship so that the user can play again. Give the user the
option to give up, which reveal
s
the location of the enemy ship. Once the user has seen
the solution, you
should
reset the game.
Cre
ate the following functions at the top of your program:
1.
displayBoard
–
display the board with row and column headings.
2.
resetBoard
–
clear the board and reset position of ship [(0
-
3),(0
-
3)].
3.
displayMenu
–
display the menu.
4.
getMenuInput
–
get the menu inpu
t, return the valid input.
5.
getRow/getColumn
–
get the row/col input, return valid input (0
-
4).
6.
fireShot
–
using the user’s input, and ship location, place an x or * on the board.
Check all user inputs for validity.
Do not create global variables, instead,
pass the
lists
and other
v
ariables to functions as needed, return values back to where they were calle