Skip to content
Snippets Groups Projects
Commit 469da8f0 authored by David Reiser's avatar David Reiser
Browse files

comments added

parent 288d68cf
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,9 @@ public class GameUI extends Application{
private Label scoreLabelO= new Label("Player O: 0");
private Button[] buttons = new Button[9];
/** Provides styles allignment and the scenes for labels, buttons and boxes.
* @param stage starts the scene and is the main stage for the application
*/
@Override
public void start(Stage stage){
playerLabel.setStyle("-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: blue;");
......@@ -35,16 +38,19 @@ public class GameUI extends Application{
borderPane.setCenter(gridPane);
//HBox for the labels
HBox Box = new HBox(20);
Box.setAlignment(Pos.CENTER);
playerLabel.setAlignment(Pos.TOP_CENTER);
playerLabel.setPadding(new Insets(10, 0, 15, 15));
Box.getChildren().add(playerLabel);
//space between the labels
Region spacer = new Region();
HBox.setHgrow(spacer, Priority.ALWAYS);
Box.getChildren().add(spacer);
//score labels design
scoreLabelX.setAlignment(Pos.TOP_CENTER);
scoreLabelO.setAlignment(Pos.TOP_CENTER);
VBox scoreBox = new VBox(15);
......@@ -55,58 +61,78 @@ public class GameUI extends Application{
Box.getChildren().add(scoreBox);
borderPane.setTop(Box);
//board allignment
gridPane.setPadding(new Insets(10));
gridPane.setHgap(30);
gridPane.setVgap(30);
gridPane.setAlignment(Pos.CENTER);
//main Scene
Scene scene = new Scene(borderPane, 1500, 850);
stage.setScene(scene);
stage.setTitle("Tick-Tack-Trauma");
stage.show();
}
/** method for the game updating its state including changing turn of the player and check for win or tie. Images are set as symbols.
*
* @param index of the selectet tile
*/
private void handleTurn(int index){
if (board.tiles[index].exist_owner()) {
return;
}
board.tiles[index].set_owner(board.currentPlayer);
//Replace symbols with images
String imageSymbols = board.currentPlayer == 0 ? getClass().getResource("/textures/1_0.png").toExternalForm() : getClass().getResource("/textures/0_0.png").toExternalForm();
Image image = new Image(""+ imageSymbols);
ImageView imageView = new ImageView(image);
//size of the image
imageView.setFitWidth(135);
imageView.setFitHeight(135);
imageView.setPreserveRatio(true);
buttons[index].setGraphic(imageView);
board.turnEnd();
updatePlayerTurn(board.currentPlayer);
//changes label state for the winning player and updates its score
if (board.victoryCheck()) {
playerLabel.setText("Player " + (board.currentPlayer == 0 ? "X" : "O") + " wins!");
updatePlayerScore();
return;
}
//changes label state to draw
if (board.marks == 9) {
playerLabel.setText("It's a draw!");
return;
}
}
/** updates the label of the current player
*
* @param currentPlayer player whose turn it is
*/
private void updatePlayerTurn(int currentPlayer) {
String playerSymbol = (currentPlayer == 0) ? "X" : "O";
playerLabel.setText("Player " + playerSymbol + "'s turn");
}
/** updates the score of a player who won
*
*/
private void updatePlayerScore(){
scoreLabelX.setText("Player X: " + board.players[0].getPlayerScore());
scoreLabelO.setText("Player O: " + board.players[1].getPlayerScore());
}
/** starts the javafx application
*
* @param args
*/
public void call(String[] args){
launch(args);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment