If all the ships have been “hit” and sunk, draw the board one last time then print “game over!” and end the game

Published by Jeannie R. Ferrell

Dec 8, 2022

s

Struggling with a similar assignment? Don’t know where to start? Don’t have time to work on this? Get a high-quality paper written for you from scratch – PLAGIARISM FREE, guaranteed to get you a good grade. To get started, please click on the Submit Your Instructions at the bottom of the page.

implement a variation of the board game “Battleship”.1 You may have played this game as a kid (or an adult). In Battleship, 5 ships are placed on a 10 x 10 grid and then you and your opponent take turns calling out a row/column until all the ships on your opponent’s grid are “hit” and “sunk”. The first player to sink all of his/her opponent’s ships wins.
In this variation, we will use a two-dimensional array to represent your game board, randomly place 5 ships and then simulate an opponent trying to hit your ships by entering one column/row at a time from the keyboard until all your ships are sunk. For simplicity, each ship will fill a single square on the grid.
You will need to implement the following methods in addition to main:
A method ‘drawBoard’ that takes one parameter as input: a 10 x 10 array of chars that represents the board. The method then displays the contents of the array – columns to the right, rows down (see my sample output). The numbers 0-9 should be displayed along the top and left sides of the drawing to easily identify each column/row on the board. Each square should display one of four possible characters:
A dot ‘.‘ for any square that does not contain a ship and that has not yet been called out by the user at the keyboard
The letter ‘S’ to represent one of the 5 ships on the board
The letter ‘O’ to represent a row/column that was called out but did not contain a ship (i.e., a “miss”)
The letter ‘X’ to represent a row/column that was called out and there was a ship there (i.e., a “hit”)
You do NOT need to write any Unit tests for this method
A method ‘isGameOver’ that takes one parameter as input: a 10 x 10 array of chars that represents the board. The method should return ‘true’ if all the ships on the board have been hit/sunk (i.e., all of the ‘S’ squares have been replaced by ‘X’) and false otherwise. At least two Unit Tests should be written for this method. One that returns true and one that returns false for a given board.
A method ‘setupBoard’ that takes no parameters as input. The method should create a two-dimensional array that represents the board with each square initialized to a dot ‘.‘. Then there should be an ‘S’ for each of the number of ships specified by the ‘NUM_SHIPS’ constant. The ships should be placed on the board randomly using the ‘Random’ class to pick a random row and column. If the same row/column is picked more than once, the method should continue to loop until all the ships are placed on different squares. So, if NUM_SHIPS == 5, there should be 5 different squares with an ‘S’ and the rest of the squares should contain a dot ‘.‘ character. At least two Unit Tests should be written for this method. One that checks that the appropriate number of ships are present on the board and one that checks that the rest of squares have a blank space.
A method ‘checkHitOrMiss’ that takes three parameters as input: a 10 x 10 array of chars that represents the board, and the column and row. The column and row represent the column and row entered by the user on the keyboard. The method should check that column and row on the board and do the following:
If the square contains a ship ‘S’, that square on the board should be updated to an ‘X’ to represent a hit and return the String “HIT”
If the square already contains a sunk ship ‘X’, simply return the String “HIT”
Otherwise, that square on the board should be updated to an ‘O’ to represent a miss and return the String “MISS”
At least two Unit Tests should be written for this method. One test that returns “HIT” for a given board and one test that returns “MISS” for a given board.
Your main method should do the following:
Set up the game board
Draw the board and prompt the user to enter a column (X)
If the column is not a valid column on the board (i.e. less than 0 or greater than or equal to 10), display “Invalid column” and go back and ask the user to try again without checking the board
Draw the board and prompt the user to enter a row (Y)
If the row is not a valid row on the board (i.e. less than 0 or greater than or equal to 10), display “Invalid row” and go back and ask the user to try again without checking the board
If the column and row are valid, check if the column/row is a hit or miss and print out the result to the user (“MISS” or “HIT”)
Update the board with the appropriate character for the square that was entered (‘O’, ‘X’)
If all the ships have been “HIT” and sunk, draw the board one last time then print “GAME OVER!” and end the game
Otherwise, loop back to Step 2 and repeat until the game is over.
You do NOT need to write any Unit tests for main

n

Need Writing Help? Our writing specialists are here 24/7, every day of the year, ready to support you! Instantly chat with an online tutor below or click here to submit your paper instructions to the writing team.

[jetpack-related-posts]

More than just an assignment.

GET THE GRADES YOU DESERVE | A OR A- GUARANTEED
NO MORE SLEEPLESS NIGHTS DOING RESEARCH
NO MORE LATE POINTS DEDUCTIONS 
GET A QUALITY PAPER SENT TO YOUR EMAIL
GET GOOD GRADES ON YOUR ASSIGNMENTS
Explore Now →

Who is this homework service for?

* If you are having a really hard class and want to get through it, then this is for you.

* If you have a medical emergency or someone close to you has a medical emergency and you don’t think you’ll be able to turn your assignment on time, this is definitely a service you could use.

* You can use us if you are having a tough Professor who won’t give you the grades you deserve.

* If you have a tight work schedule and you are getting points deducted for not submitting assignments on time.

* English might not be your first language and you feel like you are being left behind in class because of it.

* If you have a large project coming up and don’t think you have enough time to get it done well, definitely reach out to us.

TALK TO SUPPORT
{

Super stoked you are checking us out! We would like to help you with your assignment. We just need a few things from you:

* The full assignment instructions as they appear on your school account.

* If a Rubric is present, make sure to attach it.

* Any relevant weekly readings or learning resources.

* Include any special announcements or emails you might have gotten from your Professor regarding your assignment.

* Any templates or additional files required to complete the assignment.

If your assignment is somewhat complex and you need to explain it, please don’t hesitate to reach out to me via live chat. 

 

FAQ

Frequently asked questions

How soon can I get my paper done?

It depends with your deadline. If you need your paper completed in 3 hours, we will deliver it in that time. All you need to do is indicate your deadline in our custom order page here. Alternatively, if you are sending us your instructions via email, please be sure to indicate your deadline.

Will it be completely original? I don't want to be caught in a case of Academic Integrity Violation.

We are as paranoid as you are. Maybe even more! And we understand that the greatest sin you can commit in your academic journey is plagiarizing your academic work. To that end, we have made sure that we check and double-check our papers using high quality plagiarism detection tools such as SafeAssign and Turnitin before submitting the paper to you.

Who is my writer? Is he/she a native English Speaker?

All our writers are native English Speakers. That is not to say that ESL writers are not good, we just prefer hiring native writers because we want the very best people working on your paper. This might mean paying a little bit more for your paper as opposed to when you pay a foreign company whose writers are non-native English Speakers.

What if I need revisions? Will your charge additional for this?

Of course not! If you do happen to require a revision on your paper, our team will handle it for you free of charge. Matter of fact, we won’t rest till you are happy with your paper. So, ask for as many revisions as you need, it’s completely FREE!

Will you give me my money back if I don't like my paper?

We have very few instances where we delivered a paper that a client didn’t fall in love with. But if it so happens that you don’t like your paper for any reason whatsoever, we’ll refund your money back no questions asked.

I have more assignments after this, can you help me with those too?

Of course! And what’s even better is that we can reserve a writer permanently to work on your entire class. This comes in handy for projects which build up on each other and where you need just one writer, one writing style.

I got my order information wrong, can I change that?

Yes you can. Just reach out to our support team via email (support@essaynook.com) or live chat here and they’ll help you change the instructions.

Can I place an order via email instead of going through the order page?

Yes you can. Email Anna at anna@essaynook.com, she’s in charge of our sales team. Alternatively, you can talk to our Live Chat team here and request to speak to Anna.

Trusted by Thousands of Students

Delivering quality assignments since 2007