Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a c++ program Battleship You will write a program that plays the game Battleship . In this program, you will be graded on having

image text in transcribed

image text in transcribed

Write a c++ program

Battleship You will write a program that plays the game Battleship. In this program, you will be graded on having functions, as well as the ability to play the game correctly. The one requirement for using functions is that your functions, including main(), must not have over 15 lines of code, this doesnt include comments or blank lines.

Some example functions you might want to include are an initialize_board(), which initializes the boards to spaces, a determine_player_choice() that allows players to pick their spot on their opponents grid, fill_board(), which fills the board with the players choice, a print_board() that prints the board to the screen after each users turn, a check_for_winner(), which checks to see if there is a winner, and a print_winner_results() that prints the results of the game to the screen.

This is traditionally a 2-person game, where each play picks where to put their ships on a 10 x 10 matrix, and the ships can only be arranged horizontally or vertically on the board, and they can't hang over the grid!!! Ships can touch each other, but can't both occupy the same spot. Your computer game will simulate this process by first asking player 1 where he/she wants to put the ships, and then asking player 2. You can clear the screen after each player chooses their positions for their ships by using system(clear) from #include . Each player is given the following ships, and each ship takes up a specific number of spots on the 10 x 10 grid:

1 Aircraft Carrier, 5 spots 1 Battleship, 4 spots 1 Destroyer, 3 spots 1 Submarine, 3 spots

1 Patrol Boat, 2 spots

After you determine where each player wants to put their ships, then you can prompt each player to choose a position on the opponents board. If there is a boat in the corresponding position on the opponents board, then it was a hit, and you can use whatever you want to symbolize that it was a hit, i.e. X, 1, etc., in your own board.

You can even turn the Xs or 1s red by using the following code:

cout

\033[22;31m turns your text red, and \033[01;37m turns your text back to white.

In the case of a hit, the other player must mark the hit on his setup board containing the ships. Whenever a ship is sunk, you must announce to your opponent that he/she has sunk your ship. If there isnt a boat in the opponents position, then it is a miss, and you can use whatever you want to symbolize a miss on your board, i.e. 0, N, etc.

The player who sinks all of his/her opponents ships first is the winner!!!!

(10 pts) Extra Credit:

Play a one player Battleship, where the user can play the computer. The algorithm you use doesnt have to be smart, it just needs to work!!!

Example Battleship 2 Rounds B CDE F G H IJ 10 Player 1: What position do you choose? 8 A Hit!!! You sunk my ship!!! B CDE F G H I J 10 I I Player 2: What position do you choose? 4 C Hit!!! You sunk my ship

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

What is the difference between venue and jurisdiction?

Answered: 1 week ago