Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write down the steps you follow and any rules you encounter a . To setup the game b . To play your turn in the

Write down the steps you follow and any rules you encounter
a. To setup the game
b. To play your turn in the game
c. For the computer to play its turn
4. What properties (things) does your game have? Start with a grid. Set the default size to 10 x10
but allow for larger sizes. A mod at the end would be to allow for more ships. What type of
data should your grid hold? Think ahead to how the game works.
5. The standard game has 5 ships. The next thing you can do is place your ships. The ships sizes
are:
Length 2 x 1 ship
Length 3 x 2 ships
Length 4 x 1 ship
Length 5 x 1 ship
This is a good place to use the switch statement inside a for loop to set the length and to
understand why we can sometimes leave the break; out.
One way to place them is have the user enter the bow location and the port location and fill all
the ones between. We must assume the user is entering valid data. A mod later would be to
validate that data.
What do we use to indicate there is a ship in that location? Which ship?
6. Now would be a good time for the computer to place its ships. For now, it may overwrite an
existing ship when placing one. We will fix this later.
Its ships will be the same sizes and can use the same switch and for loop.
Randomly choose vertical or horizontal.
Based upon the direction, choose a location that is valid. Dont let the ship fall off the ocean.
Then use the length to complete the ship.
7. Write a method to display your grids. Add row and column labels as shown in the figure above.
Use char.
8. Fix your computer grid so that all of its ship locations are valid. Use Boolean flags to assist you.
9. When you play the game you have 2 grids. One for your ships and one for your hitMiss values.
The computer will need to keep track of its guesses as well in compGuess. You need another
set of arrays for these. What will you store in them? What is a hit? Create constants HIT and
MISS. What could these values be?
Modify your display method to also display these 2 new grids. Label them so you know what
you are looking at.
10. Now it time to play the game. What is the sequence of steps to follow? Place these into a
playGame() method. This method is pretty short and calls other methods.
11. One of the methods your playGame() should call is playerMove(). You need to read in the
players guess. It will be in the format A and 5 and will have to be translated to row 4, column
0.
Check the computer grid for a HIT or MISS. Modify the hitMiss grid to represent the result.
If it is a hit, you should check to see if you sunk the boat. Remember the player doesnt know
which boat it hit, but the computer does. How can the computer check to see if all the parts of
this boat are now hit?
If the boat is sunk, you need to update some variables (create them first) so that you can check
if all boats are sunk (checkForWin)

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_2

Step: 3

blur-text-image_3

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

Beginning C# 2005 Databases

Authors: Karli Watson

1st Edition

0470044063, 978-0470044063

More Books

Students also viewed these Databases questions

Question

Identify three ways to manage an intergenerational workforce.

Answered: 1 week ago

Question

Prepare a Porters Five Forces analysis.

Answered: 1 week ago

Question

Analyze the impact of mergers and acquisitions on employees.

Answered: 1 week ago