Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi, please help with this JavaFX project. I'm building a battleship game using javaFX. I have designed the GUI using anchor pane with background image

Hi, please help with this JavaFX project. I'm building a battleship game using javaFX. I have designed the GUI using anchor pane with background image named board.png. I also put a grid pane (7x7) on top of the background for the game to play out in. The grid rows are represented with letters from A to G and the columns are represented with numbers from 0 to 6. At the bottom right corner there will be a text field and button with text = "Fire!", player will enter their guess, for example "B1" and press Fire! button. If it hit, that grid position B1 will display "HIT" else it will display "MISS" if miss. I don't know how to write code to generate random ship, how to create a 7x7 grid and connect the random ship, grid, text field and button all together. Please help me. Thanks in advance! And please don't copy other old answers, this question is completely different, thanks. Below is my GUI code, the GUI and board.jpg image.

mainWindow.fxml

                                   

stylesheet.css in style package:

#mainAnchorPane { -fx-background-image: url("@../../../img/board.jpg"); -fx-background-repeat: no-repeat; width: 1024px; height: 863px; margin: auto; }

Controller.java

package sample; public class Controller { }

Main.java:

package sample; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.stage.Stage; public class Main extends Application { @Override public void start(Stage primaryStage) throws Exception{ Parent root = FXMLLoader.load(getClass().getResource("sample.fxml")); primaryStage.setTitle("Battleship Game"); primaryStage.setScene(new Scene(root, 1025, 865)); primaryStage.show(); } public static void main(String[] args) { launch(args); } }

GUI

image text in transcribed

board.png:

image text in transcribed

I Hello World Label A B C D E F G 2 3 4 5 6 | Fire! A B CI D E F G O 1 2 3 4 5 6 I Hello World Label A B C D E F G 2 3 4 5 6 | Fire! A B CI D E F G O 1 2 3 4 5 6

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

More Books

Students also viewed these Databases questions

Question

When would a packaged data model be useful?

Answered: 1 week ago

Question

Provide examples of Dimensional Tables.

Answered: 1 week ago