You will build a simplified, one-player version of the classic board game Battleship! In this version of the game, there will be a single ship hidden in a random location on a 5 × 5 grid. The player will have 4 guesses at most to try to sink the ship. At each guess, the player names an attacking coordinate, that is (“guess row”, “guess col”). The game ends in two conditions: (1) the player is out of guesses; (2) the player hits the ship. Examples are given in Figure 1. The 5 × 5 board is shown every time the player inputs a guess entry. The ship takes only one entry of the board and it is randomly given before the player’s guesses. The player inputs guessing entries in the Python console. Entries missed the ship are replaced by “X” in the board. You must use loop in your code. Please submit your code and console screenshots to bartleby. Code contain- ing syntax error will be graded zero.
-
You will build a simplified, one-player version of the classic board game Battleship! In this version of the game, there will be a single ship hidden in a random location on a 5 × 5 grid. The player will have 4 guesses at most to try to sink the ship. At each guess, the player names an attacking coordinate, that is (“guess row”, “guess col”). The game ends in two conditions: (1) the player is out of guesses; (2) the player hits the ship. Examples are given in Figure 1.
-
The 5 × 5 board is shown every time the player inputs a guess entry.
-
The ship takes only one entry of the board and it is randomly given before the
player’s guesses.
-
The player inputs guessing entries in the Python console.
-
Entries missed the ship are replaced by “X” in the board.
-
You must use loop in your code.
-
Please submit your code and console screenshots to bartleby. Code contain- ing syntax error will be graded zero.
-
Hints:
1
-
Create a variable board and set it equal to an empty list and create a 5 × 5 grid initialized to all ‘O’s and store it in board.
-
Define two functions, random row and random col. Each takes the board as input.
-
Create new variables called guess row and guess col and set them to input("Guess Row:")andinput("Guess Col:")respectively.
-
If your guess misses the target, set the entry of the board at (guess row, guess col) to ”X”.
-
The game should check if guess row is not in range(5) or guess col is notinrange(5).Ifthatisthecase,printout"Oops, that’s not even in the ocean."
-
Thoroughly test your game. Make sure you try a variety of different guesses and look for any errors in the syntax or logic of your program.
-
Add a break under the win condition to end the loop after a win.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps