Question: I need help writing a JavaFX tic tac toe code. I'm going to paste what I've gotten so far in each class. Any help would
I need help writing a JavaFX tic tac toe code. I'm going to paste what I've gotten so far in each class. Any help would be great! I've got the interface created, but I do not understand how I am to make the game play work from here. I was told I could utilize a boolean value to teeter between Player One and Player Two, but everything I have tried keeps throwing tons of compilation errors. :'( I'm including my code and the instructions below. The instructions are: Write a JavaFX program within IntelliJ that will allow two users to play a game of tic-tac-toe. The game area must consist of nine buttons for the play area, a reset button, and a label that will display the current players turn. When the program starts, the game area buttons should have no values in them (meaning, they should be blank). When player one clicks on a game area button, the button should get the value X. When player two clicks a button, the button should get the value O. Each time a player clicks on a button in the game area, the label displaying the current players turn should toggle to the other player (i.e. it should change from Player1 to Player2 or vice versa). When the reset button is clicked, all of the game area buttons should be returned to the blank state and the current players turn should be set to Player1. ___________________________ Main.java Class ___________________________
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("Tic Tac Toe"); primaryStage.setScene(new Scene(root, 300, 300)); primaryStage.show(); } public static void main(String[] args) { launch(args); } } ____________________________________________ Controller.java Class ____________________________________________ package sample; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.scene.control.Button; import javafx.scene.control.Label; public class Controller { @FXML private Label setPlayer; @FXML private Button button1, button2, button3, button4, button5, button6, button7, button8, button9, button0, button00; boolean player = true; public void exitButton(ActionEvent actionEvent) { Platform.exit(); } public void gamePlay (ActionEvent play) { if() } } ______________________________________________ sample.fxml Class ______________________________________________ Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
