From 2d12421d4da02755916c85d2f463ec451ad24878 Mon Sep 17 00:00:00 2001 From: Josua Oppermann <josua.oppermann@gmail.com> Date: Thu, 9 Jan 2025 15:01:08 +0100 Subject: [PATCH] Tile update --- Tile.java | 46 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/Tile.java b/Tile.java index 0560f57..651c4b8 100644 --- a/Tile.java +++ b/Tile.java @@ -1,6 +1,14 @@ +import java.io.FileInputStream; +import java.io.IOException; import java.util.Random; +import javax.imageio.ImageIO; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; -public class Tile { +import java.awt.image.BufferedImage; + + +public class Tile extends ImageView{ /**These Values are being set when initialized @@ -10,7 +18,7 @@ public class Tile { /**The Value of this Integer determines who owns this Tile * -1 = no one; 0 = Player 1; 1 = Player 2 */ - int owner = 0; + int owner = -1; /**Random for Images * @@ -20,19 +28,39 @@ public class Tile { /**Paths for the images * */ - String imagePathPlayer = "./textures/" + owner + "_" + rnd.nextInt(3); - String imagePathEmpty = "./textures/empty"; - + BufferedImage Image; + Board board; + + /**Initializer for Tile Objects * @param size Sets the Size of the Image * @param posx Sets the x-Position of the Image * @param posy Sets the y-Position of the Image */ - public Tile(int size, int posx, int posy){ - size = this.size; - posx = this.posx; - posy = this.posy; + public Tile(Board board, int size, int posx, int posy){ + super(); + setImage(new Image(Tile.class.getClassLoader().getResourceAsStream("textures/empty.png"))); + this.size = size; + this.posx = posx; + this.posy = posy; + setOnMouseClicked( e -> clicked() ); + + this.board = board; + + + //super(Tile.class.getClassLoader().getResourceAsStream("textures/empty.png")); + + /*try { + Image = ImageIO.read(Tile.class.getClassLoader().getResourceAsStream("textures/empty.png")); + } catch (IOException e) { + e.printStackTrace(); + } //"/textures/" + owner + "_" + rnd.nextInt(3)*/ + } + + private void clicked() { + owner = board.currentPlayer; + board.turnEnd(); } /**Lets you set a new owner; -- GitLab