diff --git a/bin/de/deadlocker8/roadgame/logic/Board.class b/bin/de/deadlocker8/roadgame/logic/Board.class index a3c7421f9e5d58f240e377c05ec3cd170f44c50e..2f0a0796736ad3f2612c019aacdb82b891f6fa83 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 1b7aa0c47a98c7a231997e703bd1be0a04c04cee..20a792026f1a3a7feb2fbf39d3855e87f54a0d37 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/PossibleTiles.class b/bin/de/deadlocker8/roadgame/logic/PossibleTiles.class deleted file mode 100644 index 62a871ec775db2b0725cba3a1219ed35a6d928ae..0000000000000000000000000000000000000000 Binary files a/bin/de/deadlocker8/roadgame/logic/PossibleTiles.class and /dev/null differ diff --git a/bin/de/deadlocker8/roadgame/logic/TileTypes.class b/bin/de/deadlocker8/roadgame/logic/TileTypes.class new file mode 100644 index 0000000000000000000000000000000000000000..1f5d338e94bfeabd7e7e574f7a079394c99f1994 Binary files /dev/null and b/bin/de/deadlocker8/roadgame/logic/TileTypes.class differ diff --git a/bin/de/deadlocker8/roadgame/main/Main.class b/bin/de/deadlocker8/roadgame/main/Main.class index 4c6811def543a78de34c8986fb4e6eda16dc321a..21285c4b3198c6dfb578579917e75d7aad60f1a4 100644 Binary files a/bin/de/deadlocker8/roadgame/main/Main.class and b/bin/de/deadlocker8/roadgame/main/Main.class differ diff --git a/bin/de/deadlocker8/roadgame/resources/2.png b/bin/de/deadlocker8/roadgame/resources/2.png deleted file mode 100644 index 8d8cea35f9b801e5f39132e92b07a3630a5fedaa..0000000000000000000000000000000000000000 Binary files a/bin/de/deadlocker8/roadgame/resources/2.png and /dev/null differ diff --git a/bin/de/deadlocker8/roadgame/resources/empty.png b/bin/de/deadlocker8/roadgame/resources/empty.png index 0b624ce13d73f787120c3997e3836566e212cfba..8d8cea35f9b801e5f39132e92b07a3630a5fedaa 100644 Binary files a/bin/de/deadlocker8/roadgame/resources/empty.png and b/bin/de/deadlocker8/roadgame/resources/empty.png differ diff --git a/bin/de/deadlocker8/roadgame/ui/Controller$1.class b/bin/de/deadlocker8/roadgame/ui/Controller$1.class index 3e40e28222964a2d6c131b6f57c2d5debbc147b1..7eb98de5811738aeca0d5152a2424949583efdc8 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$2.class b/bin/de/deadlocker8/roadgame/ui/Controller$2.class index 4dfed642988740f411ddfbb691d4a912c2022182..4655d134e5b719203dab9a37d493518fd11d6a38 100644 Binary files a/bin/de/deadlocker8/roadgame/ui/Controller$2.class and b/bin/de/deadlocker8/roadgame/ui/Controller$2.class differ diff --git a/bin/de/deadlocker8/roadgame/ui/Controller.class b/bin/de/deadlocker8/roadgame/ui/Controller.class index ccfff9e08e168ea162b7b262544400e30de5a5b3..a729147f0a18ac72a3028e9479a690640cc6dbab 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 c1199ad145a9e673ae262f6cd2f07790d0f19e30..074c8a73b5520082a50e9b8513d0ec25dba8ac33 100644 --- a/bin/de/deadlocker8/roadgame/ui/GUI.fxml +++ b/bin/de/deadlocker8/roadgame/ui/GUI.fxml @@ -2,6 +2,7 @@ <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> +<?import javafx.scene.control.ScrollPane?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.StackPane?> @@ -11,7 +12,10 @@ <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" /> + <AnchorPane fx:id="anchorPaneGame" prefHeight="572.0" prefWidth="599.0" HBox.hgrow="ALWAYS"> + <children> + <ScrollPane fx:id="scrollPane" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> + </children></AnchorPane> <VBox alignment="TOP_CENTER" prefHeight="572.0" prefWidth="124.0"> <HBox.margin> <Insets left="20.0" /> diff --git a/src/de/deadlocker8/roadgame/logic/Board.java b/src/de/deadlocker8/roadgame/logic/Board.java index 5b260498b4d3ac41df91dc7e368d78c63251aa94..3a7dacc505cf92a09e8634fbd2aa12502f250332 100644 --- a/src/de/deadlocker8/roadgame/logic/Board.java +++ b/src/de/deadlocker8/roadgame/logic/Board.java @@ -1,24 +1,23 @@ package de.deadlocker8.roadgame.logic; import java.util.ArrayList; +import java.util.Random; import javafx.geometry.Point2D; public class Board { private ArrayList<Tile> tiles; - private PossibleTiles possibleTiles; public Board() { - this.tiles = new ArrayList<>(); - this.possibleTiles = new PossibleTiles(); + this.tiles = new ArrayList<>(); initBoard(); } private void initBoard() { - Tile startTile = possibleTiles.getRandomTile(); + Tile startTile = getRandomTile(); startTile.setPosition(new Point2D(0, 0)); tiles.add(startTile); @@ -42,6 +41,23 @@ public class Board return null; } + public Tile getRandomTile() + { + Random random = new Random(); + int index = random.nextInt(TileTypes.values().length); + TileTypes tileType = TileTypes.values()[index]; + Tile tile = new Tile(tileType.getN(), tileType.getE(), tileType.getS(), tileType.getW()); + + //random rotation + int rotate = random.nextInt(3); + for(int i = 0; i < rotate; i++) + { + tile.rotateRight(); + } + + return tile; + } + public boolean containsTileAtPosition(int x, int y) { for(Tile currentTile : tiles) @@ -67,7 +83,7 @@ public class Board { if(!tile.getN().equals(EdgeType.GRASS)) { - if(tile.getN().equals(playerTile.getS())) + if(isCrossCheckValid(playerTile, x, y-1)) { freeEdges.add(new Point2D(x, y-1)); } @@ -79,7 +95,7 @@ public class Board { if(!tile.getE().equals(EdgeType.GRASS)) { - if(tile.getE().equals(playerTile.getW())) + if(isCrossCheckValid(playerTile, x+1, y)) { freeEdges.add(new Point2D(x+1, y)); } @@ -91,7 +107,7 @@ public class Board { if(!tile.getS().equals(EdgeType.GRASS)) { - if(tile.getS().equals(playerTile.getN())) + if(isCrossCheckValid(playerTile, x, y+1)) { freeEdges.add(new Point2D(x, y+1)); } @@ -103,7 +119,7 @@ public class Board { if(!tile.getW().equals(EdgeType.GRASS)) { - if(tile.getW().equals(playerTile.getE())) + if(isCrossCheckValid(playerTile, x-1, y)) { freeEdges.add(new Point2D(x-1, y)); } @@ -113,6 +129,47 @@ public class Board return freeEdges; } + private boolean isCrossCheckValid(Tile tile, int x, int y) + { + //North + if(containsTileAtPosition(x, y-1)) + { + if(!tile.getN().equals(getTile(x, y-1).getS())) + { + return false; + } + } + + //East + if(containsTileAtPosition(x+1, y)) + { + if(!tile.getE().equals(getTile(x+1, y).getW())) + { + return false; + } + } + + //South + if(containsTileAtPosition(x, y+1)) + { + if(!tile.getS().equals(getTile(x, y+1).getN())) + { + return false; + } + } + + //West + if(containsTileAtPosition(x-1, y)) + { + if(!tile.getW().equals(getTile(x-1, y).getE())) + { + return false; + } + } + + return true; + } + public ArrayList<Point2D> getPossibleLocations(Tile tile) { ArrayList<Point2D> possibleLocations = new ArrayList<>(); @@ -149,7 +206,7 @@ public class Board minY = (int)currentTile.getPosition().getY(); } - if((int)currentTile.getPosition().getX() > maxY) + if((int)currentTile.getPosition().getY() > maxY) { maxY = (int)currentTile.getPosition().getY(); } diff --git a/src/de/deadlocker8/roadgame/logic/Game.java b/src/de/deadlocker8/roadgame/logic/Game.java index ced0539be9f49c92cd93c03390a45828acdb9558..99005205e43e3baad4f605886893b0d9b61b0843 100644 --- a/src/de/deadlocker8/roadgame/logic/Game.java +++ b/src/de/deadlocker8/roadgame/logic/Game.java @@ -6,14 +6,12 @@ import javafx.geometry.Point2D; public class Game { - private Board board; - private PossibleTiles possibleTiles; + private Board board; private Tile currentTile; public Game() { - board = new Board(); - possibleTiles = new PossibleTiles(); + board = new Board(); } public Board getBoard() @@ -23,7 +21,7 @@ public class Game public Tile getNextTile() { - return possibleTiles.getRandomTile(); + return board.getRandomTile(); } public void setCurrentTile(Tile currentTile) @@ -45,5 +43,5 @@ public class Game { tile.setPosition(position); board.addTile(tile); - } + } } \ No newline at end of file diff --git a/src/de/deadlocker8/roadgame/logic/PossibleTiles.java b/src/de/deadlocker8/roadgame/logic/PossibleTiles.java deleted file mode 100644 index 4bb50b1954358fa673f56739953b85737f7397c7..0000000000000000000000000000000000000000 --- a/src/de/deadlocker8/roadgame/logic/PossibleTiles.java +++ /dev/null @@ -1,41 +0,0 @@ -package de.deadlocker8.roadgame.logic; - -import java.util.ArrayList; -import java.util.Random; - -public class PossibleTiles -{ - private ArrayList<Tile> possibleTiles; - - public PossibleTiles() - { - possibleTiles = new ArrayList<>(); - //curve - possibleTiles.add(new Tile(EdgeType.ROAD, EdgeType.ROAD, EdgeType.GRASS, EdgeType.GRASS)); - //straight - possibleTiles.add(new Tile(EdgeType.ROAD, EdgeType.GRASS, EdgeType.ROAD, EdgeType.GRASS)); - //T-tile - possibleTiles.add(new Tile(EdgeType.ROAD, EdgeType.ROAD, EdgeType.ROAD, EdgeType.GRASS)); - } - - public ArrayList<Tile> getPossibleTiles() - { - return possibleTiles; - } - - public Tile getRandomTile() - { - Random random = new Random(); - int index = random.nextInt(possibleTiles.size()); - Tile tile = possibleTiles.get(index); - - //random rotation - int rotate = random.nextInt(3); - for(int i = 0; i < rotate; i++) - { - tile.rotateRight(); - } - - return tile; - } -} \ No newline at end of file diff --git a/src/de/deadlocker8/roadgame/logic/TileTypes.java b/src/de/deadlocker8/roadgame/logic/TileTypes.java new file mode 100644 index 0000000000000000000000000000000000000000..fe1811958302429ff496cab615f437704729e03f --- /dev/null +++ b/src/de/deadlocker8/roadgame/logic/TileTypes.java @@ -0,0 +1,41 @@ +package de.deadlocker8.roadgame.logic; + +public enum TileTypes +{ + STRAIGHT(EdgeType.ROAD, EdgeType.GRASS, EdgeType.ROAD, EdgeType.GRASS), + CURVE(EdgeType.ROAD, EdgeType.ROAD, EdgeType.GRASS, EdgeType.GRASS), + T_JUNCTION(EdgeType.ROAD, EdgeType.ROAD, EdgeType.ROAD, EdgeType.GRASS); + + private EdgeType N; + private EdgeType E; + private EdgeType S; + private EdgeType W; + + private TileTypes(EdgeType n, EdgeType e, EdgeType s, EdgeType w) + { + N = n; + E = e; + S = s; + W = w; + } + + public EdgeType getN() + { + return N; + } + + public EdgeType getE() + { + return E; + } + + public EdgeType getS() + { + return S; + } + + public EdgeType getW() + { + return W; + } +} \ No newline at end of file diff --git a/src/de/deadlocker8/roadgame/main/Main.java b/src/de/deadlocker8/roadgame/main/Main.java index 11e8636748894a5a731bc255ca53f9316f56db35..4557da8c979fba0b1273d0d28daab1f1dc5649a1 100644 --- a/src/de/deadlocker8/roadgame/main/Main.java +++ b/src/de/deadlocker8/roadgame/main/Main.java @@ -28,7 +28,7 @@ public class Main extends Application ((Controller)loader.getController()).init(stage); - stage.setResizable(false); + stage.setResizable(true); stage.getIcons().add(new Image("de/deadlocker8/roadgame/resources/icon.png")); stage.setTitle("RoadGame"); stage.setScene(scene); diff --git a/src/de/deadlocker8/roadgame/resources/2.png b/src/de/deadlocker8/roadgame/resources/2.png deleted file mode 100644 index 8d8cea35f9b801e5f39132e92b07a3630a5fedaa..0000000000000000000000000000000000000000 Binary files a/src/de/deadlocker8/roadgame/resources/2.png and /dev/null differ diff --git a/src/de/deadlocker8/roadgame/resources/empty.png b/src/de/deadlocker8/roadgame/resources/empty.png index 0b624ce13d73f787120c3997e3836566e212cfba..8d8cea35f9b801e5f39132e92b07a3630a5fedaa 100644 Binary files a/src/de/deadlocker8/roadgame/resources/empty.png and b/src/de/deadlocker8/roadgame/resources/empty.png differ diff --git a/src/de/deadlocker8/roadgame/ui/Controller.java b/src/de/deadlocker8/roadgame/ui/Controller.java index e29638ccc9530e4b4c050c9d32af8116c35b229f..a87371ce6fd2d5b764f8a1b319543bb441bbecee 100644 --- a/src/de/deadlocker8/roadgame/ui/Controller.java +++ b/src/de/deadlocker8/roadgame/ui/Controller.java @@ -14,7 +14,7 @@ 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.control.ScrollPane; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseButton; @@ -31,6 +31,7 @@ public class Controller @FXML private AnchorPane anchorPaneGame; @FXML private StackPane stackPaneCurrentTile; @FXML private Button buttonRotate; + @FXML private ScrollPane scrollPane; private Stage stage; private Image icon = new Image("de/deadlocker8/roadgame/resources/icon.png"); @@ -55,11 +56,7 @@ public class Controller 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); + scrollPane.setContent(grid); game = new Game(); @@ -100,8 +97,7 @@ public class Controller } } else - { - System.out.println("�hm: " +( x - (int)center.getX() )+" "+ (y - (int)center.getY() )); + { Tile tile = board.getTile(x - (int)center.getX(), y - (int)center.getY()); if(tile != null) { @@ -127,12 +123,11 @@ public class Controller } } } - } + } } private void placeTile(int x, int y) - { - System.out.println(x + " " + y); + { game.placeTile(game.getCurrentTile(), new Point2D(x, y)); nextTile(); } @@ -216,15 +211,14 @@ public class Controller game.setCurrentTile(game.getNextTile()); stackPaneCurrentTile.getChildren().clear(); - stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0)); - System.out.println(game.getBoard()); + stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0)); updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile())); } public void rotateRight() { - game.getCurrentTile().rotateRight(); + game.getCurrentTile().rotateRight(); stackPaneCurrentTile.getChildren().clear(); stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0)); diff --git a/src/de/deadlocker8/roadgame/ui/GUI.fxml b/src/de/deadlocker8/roadgame/ui/GUI.fxml index c1199ad145a9e673ae262f6cd2f07790d0f19e30..074c8a73b5520082a50e9b8513d0ec25dba8ac33 100644 --- a/src/de/deadlocker8/roadgame/ui/GUI.fxml +++ b/src/de/deadlocker8/roadgame/ui/GUI.fxml @@ -2,6 +2,7 @@ <?import javafx.geometry.Insets?> <?import javafx.scene.control.Button?> +<?import javafx.scene.control.ScrollPane?> <?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.StackPane?> @@ -11,7 +12,10 @@ <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" /> + <AnchorPane fx:id="anchorPaneGame" prefHeight="572.0" prefWidth="599.0" HBox.hgrow="ALWAYS"> + <children> + <ScrollPane fx:id="scrollPane" prefHeight="200.0" prefWidth="200.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0" /> + </children></AnchorPane> <VBox alignment="TOP_CENTER" prefHeight="572.0" prefWidth="124.0"> <HBox.margin> <Insets left="20.0" />