Skip to content
Snippets Groups Projects
Commit e87d9156 authored by Robert Goldmann's avatar Robert Goldmann
Browse files

fixed ui, fixed edgecases

parent fe7b1566
Branches
Tags
No related merge requests found
Showing
with 130 additions and 73 deletions
No preview for this file type
No preview for this file type
File deleted
File added
No preview for this file type
bin/de/deadlocker8/roadgame/resources/2.png

206 B

bin/de/deadlocker8/roadgame/resources/empty.png

362 B | W: | H:

bin/de/deadlocker8/roadgame/resources/empty.png

206 B | W: | H:

bin/de/deadlocker8/roadgame/resources/empty.png
bin/de/deadlocker8/roadgame/resources/empty.png
bin/de/deadlocker8/roadgame/resources/empty.png
bin/de/deadlocker8/roadgame/resources/empty.png
  • 2-up
  • Swipe
  • Onion skin
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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" />
......
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();
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();
}
......
......@@ -7,13 +7,11 @@ import javafx.geometry.Point2D;
public class Game
{
private Board board;
private PossibleTiles possibleTiles;
private Tile currentTile;
public Game()
{
board = new Board();
possibleTiles = new PossibleTiles();
}
public Board getBoard()
......@@ -23,7 +21,7 @@ public class Game
public Tile getNextTile()
{
return possibleTiles.getRandomTile();
return board.getRandomTile();
}
public void setCurrentTile(Tile currentTile)
......
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
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
......@@ -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);
......
src/de/deadlocker8/roadgame/resources/2.png

206 B

src/de/deadlocker8/roadgame/resources/empty.png

362 B | W: | H:

src/de/deadlocker8/roadgame/resources/empty.png

206 B | W: | H:

src/de/deadlocker8/roadgame/resources/empty.png
src/de/deadlocker8/roadgame/resources/empty.png
src/de/deadlocker8/roadgame/resources/empty.png
src/de/deadlocker8/roadgame/resources/empty.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -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();
......@@ -101,7 +98,6 @@ 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)
{
......@@ -132,7 +128,6 @@ public class Controller
private void placeTile(int x, int y)
{
System.out.println(x + " " + y);
game.placeTile(game.getCurrentTile(), new Point2D(x, y));
nextTile();
}
......@@ -217,7 +212,6 @@ public class Controller
stackPaneCurrentTile.getChildren().clear();
stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0));
System.out.println(game.getBoard());
updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile()));
}
......
......@@ -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" />
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment