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, 21.06.2019 16:00
In a cellular network each cell is controlled by a tower what are these towers called?
Answers: 3
question
Computers and Technology, 24.06.2019 02:10
Aspeed limit sign that says "night" indicates the legal speed between sunset and sunrise.
Answers: 2
question
Computers and Technology, 24.06.2019 10:20
Identify the publisher in this citation: carter,alan.a guide to entrepreneurship.new york: river’2008.print.
Answers: 3
question
Computers and Technology, 24.06.2019 11:30
What does the https: // mean when you type in a website
Answers: 1
You know the right answer?
Battleship. java

assignment:
in a simplified game of battleship, the computer pla...
Questions
question
SAT, 18.02.2021 01:00
question
Arts, 18.02.2021 01:00
question
Chemistry, 18.02.2021 01:00
question
Physics, 18.02.2021 01:00
question
Mathematics, 18.02.2021 01:00
Questions on the website: 13722363