Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program for a network version of the Battleships game. The game is played between two players, each on a separate computer. On each

Write a program for a network version of the Battleships game. The game is played between two players, each on a separate computer. On each computer there is a display which consists of two grids and a communication box. One grid is used the show the arrangement of the location of your ships and the other is used to record the shots by the opponent. You can use a square grid (for example 20 x 20) and each cell in the grid is identified by row number and a column label (using alphabets). The communication box is used to send and receive messages between the two players. Before play begins, each player will secretly arrange the ships on the grid for that player. Each ship must occupy the specified number of squares and must be placed on consecutive squares on the grid, arranged either horizontally or vertically. The number of squares for each ship is determined by the type of the ship. The ships cannot overlap (i.e., only one ship can occupy any given square in the grid). The types and numbers of ships allowed are the same for each player. These may vary depending on the rules. You can choose the complement of ships. For example, you can use the following complement of ships. You get 1 aircraft carrier of size 5, 2 battle ships, size 4, 2 submarines, size 3, 2 destroyers, size 3, and 4 patrol boat, size 2.

Rules of the game: After the ships have been positioned, each player will take turns firing a shot to attack enemy ships. On your turn, you will send a message with a letter and a number indicating a cell on the grid. The opponent will check that space on their lower grid, and reply "miss" if there are no ships on that cell, or "hit" if you guessed a space that contained a ship. You will mark the shots on the opponents grid (on your computer), with white squares for misses and red squares for hits, to keep track of your guesses. When one of your ships is hit, put a red square into that ship at the location of the hit. Whenever you any one of your ship is completely destroyed (has every slot filled with red squares), you must announce to your opponent that you have lost your ship. Victory: The first player to sink all opposing ships wins. Extra credit. Write a program that simulates the opponent, so that, instead of an opponent, you can play against the remote computer.

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

Recommended Textbook for

More Books

Students also viewed these Databases questions