Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Java 2D Battle Ship pseudo-code help: I am developing a Java game which uses a 2D String array for the Grid Objects First user gets

Java 2D Battle Ship pseudo-code help:

I am developing a Java game which uses a 2D String array for the Grid Objects First user gets to pick a spot to place its Boat objects, first by placing a part of the boat (using one grid tile, and extending it in either up, down, left, right directions) And I need the appropriate conditions (using if-statements) regarding the relative location of the boat (the x-position, y-position, its length, and the direction chosen). Something like: if user decides to extend upwards but its length is too long and/or the grid is out of bounds, return false;

(SEE EXAMPLE OUTPUT BELOW)

image text in transcribed

Case: Correct 0 1 2 3 4567 0~~~ 4~ 5 ~~ 6 ~~ Enter a coordinate to place your Carrier: 2 5 0 1 2 3 4567 7~ ~ ~ Enter a direction to place extend other parts (2-up, 4 -left, 6 - right, 8 - down): 2 01 2 3 456 7 0~~ 1 ~ ~~ 4C~ 5~~?". ~ ~ ~ ~ 6 ~~ Enter a direction to place extend other parts (2 up, 4-left, 6 right, 8 down): 2 0 1 2 3 4567 0~~~ 4C~ 6 ~ Enter a direction to place extend other parts (2 up, 4 left, 6 right, 8-down) 2 0 1 2 3 456 7 2C~~~ ~ 4~C Enter a direction to place extend other parts (2 up, 4 - left, 6 -right, 8 down): 2 0 1 2 3 4567 0 5 C~ 6~~ ~ Carrier succesfully placed! //Case: Up 01 234567 0~ Enter a coordinate to place your Carrier:0 0 0 1 2 3 4567 6 ~~ Enter a direction to place extend other parts (2 up, 4 -left, 6 right, 8-down) 2 Error, invalid move! //case: Right 0123 4567 0 1 ~ ~~ 2~ ~ 7~ ~~ Enter a coordinate to place your Carrier: 7 0 0 1 2 3 4567 0~~~C 4~~~ 5 Enter a direction to place extend other parts (2 up, 4 left, 6 right, 8 - down): 6 Error, invalid move! //Case: Left 0 1 2 3 4567 0~~~ ~ 2 6 ~~ 7~ Enter a coordinate to place your Carrier: 0 0 0 1 2 3 4567 0C~ Enter a direction to place extend other parts (2 up, 4 left, 6 - right, 8 - down): 4 Error, invalid move! //Case: Down 01 2 3 456 7 0~ 4~~~ 5 Enter a coordinate to place your Carrier: 0 7 01 2 3 456 7 0 2~~ 7 C~~~ ~ Enter a direction to place extend other parts (2 up, 4 left, 6 - right, 8 down): 8 Error, invalid move! Case: Correct 0 1 2 3 4567 0~~~ 4~ 5 ~~ 6 ~~ Enter a coordinate to place your Carrier: 2 5 0 1 2 3 4567 7~ ~ ~ Enter a direction to place extend other parts (2-up, 4 -left, 6 - right, 8 - down): 2 01 2 3 456 7 0~~ 1 ~ ~~ 4C~ 5~~?". ~ ~ ~ ~ 6 ~~ Enter a direction to place extend other parts (2 up, 4-left, 6 right, 8 down): 2 0 1 2 3 4567 0~~~ 4C~ 6 ~ Enter a direction to place extend other parts (2 up, 4 left, 6 right, 8-down) 2 0 1 2 3 456 7 2C~~~ ~ 4~C Enter a direction to place extend other parts (2 up, 4 - left, 6 -right, 8 down): 2 0 1 2 3 4567 0 5 C~ 6~~ ~ Carrier succesfully placed! //Case: Up 01 234567 0~ Enter a coordinate to place your Carrier:0 0 0 1 2 3 4567 6 ~~ Enter a direction to place extend other parts (2 up, 4 -left, 6 right, 8-down) 2 Error, invalid move! //case: Right 0123 4567 0 1 ~ ~~ 2~ ~ 7~ ~~ Enter a coordinate to place your Carrier: 7 0 0 1 2 3 4567 0~~~C 4~~~ 5 Enter a direction to place extend other parts (2 up, 4 left, 6 right, 8 - down): 6 Error, invalid move! //Case: Left 0 1 2 3 4567 0~~~ ~ 2 6 ~~ 7~ Enter a coordinate to place your Carrier: 0 0 0 1 2 3 4567 0C~ Enter a direction to place extend other parts (2 up, 4 left, 6 - right, 8 - down): 4 Error, invalid move! //Case: Down 01 2 3 456 7 0~ 4~~~ 5 Enter a coordinate to place your Carrier: 0 7 01 2 3 456 7 0 2~~ 7 C~~~ ~ Enter a direction to place extend other parts (2 up, 4 left, 6 - right, 8 down): 8 Error, invalid move

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

Transactions On Large Scale Data And Knowledge Centered Systems Vi Special Issue On Database And Expert Systems Applications Lncs 7600

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2012th Edition

3642341780, 978-3642341786

More Books

Students also viewed these Databases questions

Question

=+6. How have their tactics changed?

Answered: 1 week ago