subject

Battleship. java

assignment:
in a simplified game of battleship, the computer places a single 4-unit-long ship at a random location in an 8 x 8 playing field, oriented either vertically or horizontally (at random). the player is given 15 torpedoes to fire at the field. after a torpedo is fired, the map of the field is updated to show whether it was a hit or a miss. the game continues until the player sinks the ship or runs out of torpedoes.
write a program to play this game.
sample run
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .
. . . .

15 torpedoes remain. fire where? 3 4
hit!

. . . .
. . . .
. . x . .
. . . .
. . . .
. . . .
. . . .
. . . .

14 torpedoes remain. fire where? 8 6
miss!

hint:
use a 2-dimensional array to represent the playing field, with different integers representing different states (0 = empty, no fire; 1 = contains ship, no fire; 2 = empty, fired upon; 3 = contains ship, fired upon). think about what you need to do to prevent the computer from placing parts of its ship outside the bounds of the playing field. multiple matrices may be necessary. don’t forget the api.

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 17:30
1. before plugging in a new device to a computer you should unplug all other devices turn off the computer turn on the computer 2. many of the maintenance tools for a computer can be found in the control panel under administrative tools display personalization
Answers: 1
question
Computers and Technology, 22.06.2019 19:10
How might the success of your campaign be affected if you haven’t carefully completed all field data or if you accidentally insert the wrong merge field in the document?
Answers: 1
question
Computers and Technology, 24.06.2019 04:30
What is the process in which the software development team compiles information to determine the final product
Answers: 1
question
Computers and Technology, 24.06.2019 10:20
Write a program that keeps asking the user for new values to be added to a list until the user enters 'exit' ('exit' should not be added to the list). these values entered by the user are added to a list we call 'initial_list'. then write a function that takes this initial_list as input and returns another list with 3 copies of every value in the initial_list. finally, inside print out all of the values in the new list. for example: input: enter value to be added to list: a enter value to be added to list: b enter value to be added to list: c enter value to be added to list: exit output: a b c a b c a b c note how 'exit' is not added to the list. also, your program needs to be able to handle any variation of 'exit' such as 'exit', 'exit' etc. and treat them all as 'exit'.
Answers: 2
You know the right answer?
Battleship. java

assignment:
in a simplified game of battleship, the computer pla...
Questions
question
History, 30.07.2019 06:00
Questions on the website: 13722362