Skip to content
Snippets Groups Projects
Commit b92a91a3 authored by JimmyTheCat's avatar JimmyTheCat
Browse files
parents f997236e c5dd307d
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import javafx.scene.image.*;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.stage.Stage;
import java.util.Random;
public class GameUI extends Application{
Scene game, winningScene;
......@@ -15,6 +16,9 @@ public class GameUI extends Application{
private Label scoreLabelX = new Label("Player X: 0");
private Label scoreLabelO= new Label("Player O: 0");
private Button[] buttons = new Button[9];
/**Random for Images */
Random rnd = new Random();
/**
* Provides styles allignment and the scenes for labels, buttons and boxes.
......@@ -37,6 +41,17 @@ public class GameUI extends Application{
buttons[i] = new Button();
buttons[i].setPrefSize(150, 150);
buttons[i].setOnAction(e -> handleTurn(index, stage));
String imageSymbols = getClass().getResource("/textures/empty.png").toExternalForm();
Image image = new Image("" + imageSymbols);
ImageView imageView = new ImageView(image);
imageView.setFitWidth(135);
imageView.setFitHeight(135);
imageView.setPreserveRatio(true);
buttons[index].setGraphic(imageView);
gridPane.add(buttons[i], i % 3, i / 3);
}
......@@ -74,7 +89,25 @@ public class GameUI extends Application{
//reset button
Button reset = new Button("Reset");
reset.setStyle("-fx-font-size: 30px; -fx-font-family: 'Impact'; -fx-text-fill: black;");
reset.setOnAction(e -> stage.setScene(game));
reset.setOnAction(e -> {
board = new Board(board.players, board.firstPlayer);
for(int i = 0; i < 9; i++){
int index = i;
String imageSymbols = getClass().getResource("/textures/empty.png").toExternalForm();
Image image = new Image("" + imageSymbols);
ImageView imageView = new ImageView(image);
imageView.setFitWidth(135);
imageView.setFitHeight(135);
imageView.setPreserveRatio(true);
buttons[index].setGraphic(imageView);
}
updatePlayerTurn(board.currentPlayer);
stage.setScene(game);
});
//winning/tie screen
winnerLabel.setAlignment(Pos.CENTER);
......@@ -104,7 +137,8 @@ public class GameUI extends Application{
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();
String imageSymbols = board.currentPlayer == 0 ? getClass().getResource("/textures/1_" + rnd.nextInt(3) + ".png").toExternalForm() :
getClass().getResource("/textures/0_" + rnd.nextInt(3) + ".png").toExternalForm();
Image image = new Image(""+ imageSymbols);
ImageView imageView = new ImageView(image);
......
import java.util.Random;
public class Tile {
......@@ -11,18 +11,6 @@ public class Tile {
* -1 = no one; 0 = Player 1; 1 = Player 2
*/
int owner = -1;
/**Random for Images
*
*/
Random rnd = new Random();
/**Paths for the images
*
*/
String imagePathPlayer = "./textures/" + owner + "_" + rnd.nextInt(3);
String imagePathEmpty = "./textures/empty";
/**Initializer for Tile Objects
* @param size Sets the Size of the Image
......
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