|
@@ -1,54 +1,43 @@
|
|
|
package view.tile.interactive;
|
|
package view.tile.interactive;
|
|
|
|
|
|
|
|
import model.Tile;
|
|
import model.Tile;
|
|
|
-import view.GamePanel;
|
|
|
|
|
-import view.popUpMenu.PopUpTile;
|
|
|
|
|
-import view.util.screenCoordinatesToWorld;
|
|
|
|
|
-
|
|
|
|
|
import java.awt.*;
|
|
import java.awt.*;
|
|
|
-import java.awt.event.MouseEvent;
|
|
|
|
|
-import java.util.function.Consumer;
|
|
|
|
|
-
|
|
|
|
|
-public class InteractiveTile extends Tile{
|
|
|
|
|
- private Consumer<Point> onClick;
|
|
|
|
|
-
|
|
|
|
|
- private screenCoordinatesToWorld converter;
|
|
|
|
|
-
|
|
|
|
|
- public static int xCoordinate1;
|
|
|
|
|
- public static int yCoordinate1;
|
|
|
|
|
- public static int xCoordinate2;
|
|
|
|
|
- public static int yCoordinate2;
|
|
|
|
|
- public Graphics2D g2;
|
|
|
|
|
-
|
|
|
|
|
- public InteractiveTile(int xCoordinateRandom, int yCoordinateRandom, Graphics2D g2){
|
|
|
|
|
- interactive = true;
|
|
|
|
|
- xCoordinate1 = xCoordinateRandom;
|
|
|
|
|
- yCoordinate1 = yCoordinateRandom;
|
|
|
|
|
- xCoordinate2 = xCoordinateRandom + GamePanel.static_TileSize;
|
|
|
|
|
- yCoordinate2 = yCoordinateRandom + GamePanel.static_TileSize;
|
|
|
|
|
-
|
|
|
|
|
- this.g2 = g2;
|
|
|
|
|
|
|
+import controller.GameController;
|
|
|
|
|
+
|
|
|
|
|
+public abstract class InteractiveTile extends Tile{
|
|
|
|
|
+ // This class is used to create interactive tiles that can be clicked on
|
|
|
|
|
+ private int worldX, worldY;
|
|
|
|
|
+ private int height;
|
|
|
|
|
+ private int width;
|
|
|
|
|
+ private Runnable runnable;
|
|
|
|
|
+ public GameController gameController;
|
|
|
|
|
+ private int screenX, screenY;
|
|
|
|
|
+
|
|
|
|
|
+ public InteractiveTile(int height, int width, int screenX, int screenY, Runnable c, GameController gc){
|
|
|
|
|
+ this.height = height;
|
|
|
|
|
+ this.width = width;
|
|
|
|
|
+ runnable = c;
|
|
|
|
|
+ this.gameController = gc;
|
|
|
|
|
+ this.screenX = screenX;
|
|
|
|
|
+ this.screenY = screenY;
|
|
|
|
|
+ this.worldX = gameController.getView().getWorldX(screenX);
|
|
|
|
|
+ this.worldY = gameController.getView().getWorldY(screenY);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public void setOnClick(Consumer<Point> pointConsumer){
|
|
|
|
|
- onClick = pointConsumer;
|
|
|
|
|
|
|
+ public void click(){
|
|
|
|
|
+ runnable.run();
|
|
|
}
|
|
}
|
|
|
- public void onClick(){
|
|
|
|
|
-
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- public void isLeftClicked(MouseEvent e){
|
|
|
|
|
- if(e.getButton() == MouseEvent.BUTTON1){
|
|
|
|
|
- int x = e.getX();
|
|
|
|
|
- int y = e.getY();
|
|
|
|
|
-
|
|
|
|
|
- x = converter.x(x);
|
|
|
|
|
- y = converter.y(y);
|
|
|
|
|
-
|
|
|
|
|
- if(x >= xCoordinate1 && x <= xCoordinate2 && y >= yCoordinate1 && y <= yCoordinate2){
|
|
|
|
|
- PopUpTile p = new PopUpTile(g2, 3, 3, 200, 200);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ public boolean wasClicked(int clickX, int clickY){
|
|
|
|
|
+ return clickX >= screenX && clickX <= screenX + width && clickY >= screenY && clickY <= screenY + height;
|
|
|
|
|
+ }
|
|
|
|
|
+ public abstract void draw(Graphics2D g2);
|
|
|
|
|
+ public void setDimensions(int height, int width){
|
|
|
|
|
+ this.height = height;
|
|
|
|
|
+ this.width = width;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ public void setScreenCoordinates(int x, int y){
|
|
|
|
|
+ this.worldX = x;
|
|
|
|
|
+ this.worldY = y;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|