diff --git a/bin/de/deadlocker8/roadgame/logic/Board.class b/bin/de/deadlocker8/roadgame/logic/Board.class index 67c2f435d1d683a1649aed224b3d0b63b7b447c8..bc6431984802150d760a1933700b1e41077c6048 100644 Binary files a/bin/de/deadlocker8/roadgame/logic/Board.class and b/bin/de/deadlocker8/roadgame/logic/Board.class differ diff --git a/bin/de/deadlocker8/roadgame/logic/Game.class b/bin/de/deadlocker8/roadgame/logic/Game.class index 44f929ab90a24829c036ba5aa5cab17c2606bf18..1b7aa0c47a98c7a231997e703bd1be0a04c04cee 100644 Binary files a/bin/de/deadlocker8/roadgame/logic/Game.class and b/bin/de/deadlocker8/roadgame/logic/Game.class differ diff --git a/bin/de/deadlocker8/roadgame/logic/Tile.class b/bin/de/deadlocker8/roadgame/logic/Tile.class index 92941ac05dd70be679e86675dcf9ce735231ae5b..5347d9b7f579065c7f814af569c2ae146b3adc09 100644 Binary files a/bin/de/deadlocker8/roadgame/logic/Tile.class and b/bin/de/deadlocker8/roadgame/logic/Tile.class differ diff --git a/bin/de/deadlocker8/roadgame/ui/Controller$1.class b/bin/de/deadlocker8/roadgame/ui/Controller$1.class index 6489cff44a9491fc482bbe5eddc63c26ad3efa3d..5e27e9312bd188b813fcce42367f59a46350480a 100644 Binary files a/bin/de/deadlocker8/roadgame/ui/Controller$1.class and b/bin/de/deadlocker8/roadgame/ui/Controller$1.class differ diff --git a/bin/de/deadlocker8/roadgame/ui/Controller.class b/bin/de/deadlocker8/roadgame/ui/Controller.class index fe9c35711b75ca7ca7d52b80ea86f37e5c539782..36f07da706d31af0c70cae8682b27df53499c715 100644 Binary files a/bin/de/deadlocker8/roadgame/ui/Controller.class and b/bin/de/deadlocker8/roadgame/ui/Controller.class differ diff --git a/bin/de/deadlocker8/roadgame/ui/GUI.fxml b/bin/de/deadlocker8/roadgame/ui/GUI.fxml index 8dff3935991e6454312e44182378a04721fce1a5..466a0007d9317dd19e294380e1ffe0383c5c46bc 100644 --- a/bin/de/deadlocker8/roadgame/ui/GUI.fxml +++ b/bin/de/deadlocker8/roadgame/ui/GUI.fxml @@ -1,6 +1,47 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> <?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.ColumnConstraints?> +<?import javafx.scene.layout.GridPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.RowConstraints?> +<?import javafx.scene.layout.StackPane?> +<?import javafx.scene.layout.VBox?> - -<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.roadgame.ui.Controller" /> +<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.roadgame.ui.Controller"> + <children> + <HBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> + <children> + <AnchorPane fx:id="anchorPaneGame" prefHeight="572.0" prefWidth="599.0" HBox.hgrow="ALWAYS"> + <children> + <GridPane AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0"> + <columnConstraints> + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> + <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" /> + </columnConstraints> + <rowConstraints> + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> + <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" /> + </rowConstraints> + </GridPane> + </children></AnchorPane> + <VBox alignment="TOP_CENTER" prefHeight="572.0" prefWidth="124.0"> + <HBox.margin> + <Insets left="20.0" /> + </HBox.margin> + <children> + <StackPane fx:id="stackPaneCurrentTile" prefHeight="137.0" prefWidth="124.0" /> + <Button fx:id="buttonRotate" mnemonicParsing="false" onAction="#rotateRight" text="rotate right"> + <VBox.margin> + <Insets top="14.0" /> + </VBox.margin> + </Button> + </children> + </VBox> + </children> + </HBox> + </children> +</AnchorPane> diff --git a/src/de/deadlocker8/roadgame/logic/Board.java b/src/de/deadlocker8/roadgame/logic/Board.java index 784dd28b4f6f8d6d0db4e0aee4e68378dbd75508..c384a7eaa840b0695dd279f514751c7782840368 100644 --- a/src/de/deadlocker8/roadgame/logic/Board.java +++ b/src/de/deadlocker8/roadgame/logic/Board.java @@ -29,6 +29,19 @@ public class Board return tiles; } + public Tile getTile(int x, int y) + { + for(Tile currentTile : tiles) + { + if((int)currentTile.getPosition().getX() == x && (int)currentTile.getPosition().getY() == y) + { + return currentTile; + } + } + + return null; + } + public boolean containsTileAtPosition(int x, int y) { for(Tile currentTile : tiles) diff --git a/src/de/deadlocker8/roadgame/logic/Game.java b/src/de/deadlocker8/roadgame/logic/Game.java index 73e77070a990b0034ad3bd4ffc7916141f193fa4..ced0539be9f49c92cd93c03390a45828acdb9558 100644 --- a/src/de/deadlocker8/roadgame/logic/Game.java +++ b/src/de/deadlocker8/roadgame/logic/Game.java @@ -8,12 +8,17 @@ public class Game { private Board board; private PossibleTiles possibleTiles; + private Tile currentTile; public Game() { board = new Board(); - possibleTiles = new PossibleTiles(); - System.out.println(board); + possibleTiles = new PossibleTiles(); + } + + public Board getBoard() + { + return board; } public Tile getNextTile() @@ -21,6 +26,16 @@ public class Game return possibleTiles.getRandomTile(); } + public void setCurrentTile(Tile currentTile) + { + this.currentTile = currentTile; + } + + public Tile getCurrentTile() + { + return currentTile; + } + public ArrayList<Point2D> getPossibleLocations(Tile tile) { return board.getPossibleLocations(tile); @@ -31,20 +46,4 @@ public class Game tile.setPosition(position); board.addTile(tile); } - - public static void main(String[] args) - { - Game g = new Game(); - Tile t = g.getNextTile(); - System.out.println(t); - System.out.println(g.getPossibleLocations(t)); - System.out.println(g.board.getWidth()); - System.out.println(g.board.getHeight()); - - g.placeTile(t, g.getPossibleLocations(t).get(0)); - System.out.println(g.board); - - System.out.println(g.board.getWidth()); - System.out.println(g.board.getHeight()); - } } \ No newline at end of file diff --git a/src/de/deadlocker8/roadgame/logic/Tile.java b/src/de/deadlocker8/roadgame/logic/Tile.java index 297fed9f4fe75d7a179c3063a0b17ac5d318c438..b78a6b770cb7a578860e9d82730266b2641e6146 100644 --- a/src/de/deadlocker8/roadgame/logic/Tile.java +++ b/src/de/deadlocker8/roadgame/logic/Tile.java @@ -81,4 +81,32 @@ public class Tile { return "Tile [N=" + N + ", E=" + E + ", S=" + S + ", W=" + W + ", position=" + position + "]"; } + + public String toShortString() + { + String result = ""; + + + if(N.equals(EdgeType.ROAD)) + { + result += "N"; + } + + if(E.equals(EdgeType.ROAD)) + { + result += "E"; + } + + if(S.equals(EdgeType.ROAD)) + { + result += "S"; + } + + if(W.equals(EdgeType.ROAD)) + { + result += "W"; + } + + return result; + } } \ No newline at end of file diff --git a/src/de/deadlocker8/roadgame/ui/Controller.java b/src/de/deadlocker8/roadgame/ui/Controller.java index 3b04b6f15bcf6253ce7da2a3fe49c58e81764842..0efae05e388087cfd8303e68c275ff2460aa5b60 100644 --- a/src/de/deadlocker8/roadgame/ui/Controller.java +++ b/src/de/deadlocker8/roadgame/ui/Controller.java @@ -1,26 +1,45 @@ package de.deadlocker8.roadgame.ui; +import java.util.ArrayList; import java.util.Locale; import java.util.ResourceBundle; +import com.sun.org.apache.bcel.internal.generic.IfInstruction; + +import de.deadlocker8.roadgame.logic.Board; +import de.deadlocker8.roadgame.logic.Game; +import de.deadlocker8.roadgame.logic.Tile; import javafx.event.EventHandler; +import javafx.fxml.FXML; +import javafx.geometry.Point2D; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; +import javafx.scene.control.Button; +import javafx.scene.control.Label; import javafx.scene.image.Image; +import javafx.scene.layout.AnchorPane; +import javafx.scene.layout.GridPane; +import javafx.scene.layout.StackPane; import javafx.stage.Stage; import javafx.stage.WindowEvent; import tools.Worker; public class Controller { - public Stage stage; - public Image icon = new Image("de/deadlocker8/roadgame/resources/icon.png"); - public final ResourceBundle bundle = ResourceBundle.getBundle("de/deadlocker8/roadgame/main/", Locale.GERMANY); - + @FXML private AnchorPane anchorPaneGame; + @FXML private StackPane stackPaneCurrentTile; + @FXML private Button buttonRotate; + + private Stage stage; + private Image icon = new Image("de/deadlocker8/roadgame/resources/icon.png"); + private final ResourceBundle bundle = ResourceBundle.getBundle("de/deadlocker8/roadgame/main/", Locale.GERMANY); + private GridPane grid; + private Game game; + public void init(Stage stage) { this.stage = stage; - + stage.setOnCloseRequest(new EventHandler<WindowEvent>() { public void handle(WindowEvent event) @@ -29,8 +48,105 @@ public class Controller System.exit(0); }; }); + + anchorPaneGame.setStyle("-fx-border-color: #333333; -fx-border-width: 2px"); + stackPaneCurrentTile.setStyle("-fx-border-color: #333333; -fx-border-width: 2px"); + + grid = new GridPane(); + anchorPaneGame.getChildren().add(grid); + AnchorPane.setTopAnchor(grid, 0.0); + AnchorPane.setRightAnchor(grid, 0.0); + AnchorPane.setBottomAnchor(grid, 0.0); + AnchorPane.setLeftAnchor(grid, 0.0); + + game = new Game(); + + updateGrid(game.getBoard(), null); + + nextTile(); + } + + private void updateGrid(Board board, ArrayList<Point2D> possibleLocations) + { + grid.getChildren().clear(); + + int width = board.getWidth(); + int height = board.getHeight(); + + //fill outer rim with void + for(int x = 0; x < width + 2; x++) + { + for(int y = 0; y < height + 2; y++) + { + if(x == 0 || y == 0 || x == width + 1 || y == height + 1) + { + Label label = new Label("X"); + if(possibleLocations != null) + { + //TODO x , y is alwasy positive, but possible locations can be negative --> transform coordinates + if(isInPossibleLocations(possibleLocations, x, y)) + { + label.setStyle("-fx-background-color: red"); + } + } + + grid.add(label, y, x); + + } + else + { + Tile tile = board.getTile(x-1, y-1); + if(tile != null) + { + grid.add(new Label(board.getTile(x-1, y-1).toShortString()), y, x); + } + else + { + Label label = new Label("X"); + if(possibleLocations != null) + { + if(isInPossibleLocations(possibleLocations, x, y)) + { + label.setStyle("-fx-background-color: red"); + } + } + + grid.add(label, y, x); + } + } + } + } + } + + private boolean isInPossibleLocations(ArrayList<Point2D> possibleLocations, int x, int y) + { + for(Point2D currentPoint : possibleLocations) + { + if((int)currentPoint.getX() == x && (int)currentPoint.getY() == y) + { + return true; + } + } + + return false; + } + + private void nextTile() + { + game.setCurrentTile(game.getNextTile()); + + stackPaneCurrentTile.getChildren().clear(); + stackPaneCurrentTile.getChildren().add(new Label(game.getCurrentTile().toShortString())); + + System.out.println(game.getPossibleLocations(game.getCurrentTile())); + updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile())); } + public void rotateRight() + { + + } + public void about() { Alert alert = new Alert(AlertType.INFORMATION); diff --git a/src/de/deadlocker8/roadgame/ui/GUI.fxml b/src/de/deadlocker8/roadgame/ui/GUI.fxml index 8dff3935991e6454312e44182378a04721fce1a5..c1199ad145a9e673ae262f6cd2f07790d0f19e30 100644 --- a/src/de/deadlocker8/roadgame/ui/GUI.fxml +++ b/src/de/deadlocker8/roadgame/ui/GUI.fxml @@ -1,6 +1,31 @@ <?xml version="1.0" encoding="UTF-8"?> +<?import javafx.geometry.Insets?> +<?import javafx.scene.control.Button?> <?import javafx.scene.layout.AnchorPane?> +<?import javafx.scene.layout.HBox?> +<?import javafx.scene.layout.StackPane?> +<?import javafx.scene.layout.VBox?> - -<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.roadgame.ui.Controller" /> +<AnchorPane prefHeight="600.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8.0.60" xmlns:fx="http://javafx.com/fxml/1" fx:controller="de.deadlocker8.roadgame.ui.Controller"> + <children> + <HBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> + <children> + <AnchorPane fx:id="anchorPaneGame" prefHeight="572.0" prefWidth="599.0" HBox.hgrow="ALWAYS" /> + <VBox alignment="TOP_CENTER" prefHeight="572.0" prefWidth="124.0"> + <HBox.margin> + <Insets left="20.0" /> + </HBox.margin> + <children> + <StackPane fx:id="stackPaneCurrentTile" prefHeight="137.0" prefWidth="124.0" /> + <Button fx:id="buttonRotate" mnemonicParsing="false" onAction="#rotateRight" text="rotate right"> + <VBox.margin> + <Insets top="14.0" /> + </VBox.margin> + </Button> + </children> + </VBox> + </children> + </HBox> + </children> +</AnchorPane>