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

added images

parent 79f03a3f
No related branches found
No related tags found
No related merge requests found
Showing
with 199 additions and 68 deletions
No preview for this file type
File added
bin/de/deadlocker8/roadgame/resources/2.png

206 B

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

633 B

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

362 B

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

399 B

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

428 B

No preview for this file type
File added
No preview for this file type
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
<?import javafx.geometry.Insets?> <?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?> <?import javafx.scene.control.Button?>
<?import javafx.scene.layout.AnchorPane?> <?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.HBox?> <?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.StackPane?> <?import javafx.scene.layout.StackPane?>
<?import javafx.scene.layout.VBox?> <?import javafx.scene.layout.VBox?>
...@@ -14,20 +11,7 @@ ...@@ -14,20 +11,7 @@
<children> <children>
<HBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0"> <HBox layoutX="14.0" layoutY="14.0" AnchorPane.bottomAnchor="14.0" AnchorPane.leftAnchor="14.0" AnchorPane.rightAnchor="14.0" AnchorPane.topAnchor="14.0">
<children> <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>
<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"> <VBox alignment="TOP_CENTER" prefHeight="572.0" prefWidth="124.0">
<HBox.margin> <HBox.margin>
<Insets left="20.0" /> <Insets left="20.0" />
......
...@@ -64,39 +64,51 @@ public class Board ...@@ -64,39 +64,51 @@ public class Board
//North //North
if(!containsTileAtPosition(x, y-1)) if(!containsTileAtPosition(x, y-1))
{
if(!tile.getN().equals(EdgeType.GRASS))
{ {
if(tile.getN().equals(playerTile.getS())) if(tile.getN().equals(playerTile.getS()))
{ {
freeEdges.add(new Point2D(x, y-1)); freeEdges.add(new Point2D(x, y-1));
} }
} }
}
//East //East
if(!containsTileAtPosition(x+1, y)) if(!containsTileAtPosition(x+1, y))
{
if(!tile.getE().equals(EdgeType.GRASS))
{ {
if(tile.getE().equals(playerTile.getW())) if(tile.getE().equals(playerTile.getW()))
{ {
freeEdges.add(new Point2D(x+1, y));
}freeEdges.add(new Point2D(x+1, y)); }
}
} }
//South //South
if(!containsTileAtPosition(x, y+1)) if(!containsTileAtPosition(x, y+1))
{
if(!tile.getS().equals(EdgeType.GRASS))
{ {
if(tile.getS().equals(playerTile.getN())) if(tile.getS().equals(playerTile.getN()))
{ {
freeEdges.add(new Point2D(x, y+1)); freeEdges.add(new Point2D(x, y+1));
} }
} }
}
//West //West
if(!containsTileAtPosition(x-1, y)) if(!containsTileAtPosition(x-1, y))
{
if(!tile.getW().equals(EdgeType.GRASS))
{ {
if(tile.getW().equals(playerTile.getE())) if(tile.getW().equals(playerTile.getE()))
{ {
freeEdges.add(new Point2D(x-1, y)); freeEdges.add(new Point2D(x-1, y));
} }
} }
}
return freeEdges; return freeEdges;
} }
...@@ -113,10 +125,12 @@ public class Board ...@@ -113,10 +125,12 @@ public class Board
return possibleLocations; return possibleLocations;
} }
public int getWidth() public Dimension getDimension()
{ {
int minX = 0; int minX = 0;
int maxX = 0; int maxX = 0;
int minY = 0;
int maxY = 0;
for(Tile currentTile : tiles) for(Tile currentTile : tiles)
{ {
...@@ -129,18 +143,7 @@ public class Board ...@@ -129,18 +143,7 @@ public class Board
{ {
maxX = (int)currentTile.getPosition().getX(); maxX = (int)currentTile.getPosition().getX();
} }
}
return Math.abs(minX) + maxX + 1;
}
public int getHeight()
{
int minY = 0;
int maxY = 0;
for(Tile currentTile : tiles)
{
if((int)currentTile.getPosition().getY() < minY) if((int)currentTile.getPosition().getY() < minY)
{ {
minY = (int)currentTile.getPosition().getY(); minY = (int)currentTile.getPosition().getY();
...@@ -152,7 +155,7 @@ public class Board ...@@ -152,7 +155,7 @@ public class Board
} }
} }
return Math.abs(minY) + maxY + 1; return new Dimension(minX, maxX, minY, maxY);
} }
public void addTile(Tile tile) public void addTile(Tile tile)
......
package de.deadlocker8.roadgame.logic;
import javafx.geometry.Point2D;
public class Dimension
{
private int minX;
private int maxX;
private int minY;
private int maxY;
public Dimension(int minX, int maxX, int minY, int maxY)
{
this.minX = minX;
this.maxX = maxX;
this.minY = minY;
this.maxY = maxY;
}
public int getMinX()
{
return minX;
}
public int getMaxX()
{
return maxX;
}
public int getMinY()
{
return minY;
}
public int getMaxY()
{
return maxY;
}
public int getWidth()
{
return Math.abs(minX) + maxX + 1;
}
public int getHeight()
{
return Math.abs(minY) + maxY + 1;
}
public Point2D getCenterCoordinates()
{
return new Point2D(Math.abs(minX) + 1, Math.abs(minY) + 1);
}
@Override
public String toString()
{
return "Dimension [minX=" + minX + ", maxX=" + maxX + ", minY=" + minY + ", maxY=" + maxY + "]";
}
}
\ No newline at end of file
src/de/deadlocker8/roadgame/resources/2.png

206 B

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

633 B

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

362 B

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

399 B

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

428 B

...@@ -4,9 +4,8 @@ import java.util.ArrayList; ...@@ -4,9 +4,8 @@ import java.util.ArrayList;
import java.util.Locale; import java.util.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import com.sun.org.apache.bcel.internal.generic.IfInstruction;
import de.deadlocker8.roadgame.logic.Board; import de.deadlocker8.roadgame.logic.Board;
import de.deadlocker8.roadgame.logic.EdgeType;
import de.deadlocker8.roadgame.logic.Game; import de.deadlocker8.roadgame.logic.Game;
import de.deadlocker8.roadgame.logic.Tile; import de.deadlocker8.roadgame.logic.Tile;
import javafx.event.EventHandler; import javafx.event.EventHandler;
...@@ -17,6 +16,9 @@ import javafx.scene.control.Alert.AlertType; ...@@ -17,6 +16,9 @@ import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button; import javafx.scene.control.Button;
import javafx.scene.control.Label; import javafx.scene.control.Label;
import javafx.scene.image.Image; import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane; import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.GridPane; import javafx.scene.layout.GridPane;
import javafx.scene.layout.StackPane; import javafx.scene.layout.StackPane;
...@@ -70,59 +72,137 @@ public class Controller ...@@ -70,59 +72,137 @@ public class Controller
{ {
grid.getChildren().clear(); grid.getChildren().clear();
int width = board.getWidth(); int width = board.getDimension().getWidth();
int height = board.getHeight(); int height = board.getDimension().getHeight();
Point2D center = board.getDimension().getCenterCoordinates();
//fill outer rim with void
for(int x = 0; x < width + 2; x++) for(int x = 0; x < width + 2; x++)
{ {
for(int y = 0; y < height + 2; y++) for(int y = 0; y < height + 2; y++)
{ {
if(x == 0 || y == 0 || x == width + 1 || y == height + 1) if(x == 0 || y == 0 || x == width + 1 || y == height + 1)
{ {
Label label = new Label("X");
if(possibleLocations != null) if(possibleLocations != null)
{ {
//TODO x , y is alwasy positive, but possible locations can be negative --> transform coordinates if(isInPossibleLocations(possibleLocations, center, x, y))
if(isInPossibleLocations(possibleLocations, x, y))
{ {
label.setStyle("-fx-background-color: red"); grid.add(createStackPaneForTile(null, true, -((int)center.getX() - x), -((int)center.getY() - y)), x, y);
} }
else
{
grid.add(createStackPaneForTile(null, false, 0, 0), x, y);
} }
grid.add(label, y, x);
} }
else else
{ {
Tile tile = board.getTile(x-1, y-1); grid.add(createStackPaneForTile(null, false, 0, 0), x, y);
}
}
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) if(tile != null)
{ {
grid.add(new Label(board.getTile(x-1, y-1).toShortString()), y, x); grid.add(createStackPaneForTile(tile, false, 0, 0), x, y);
} }
else else
{ {
Label label = new Label("X");
if(possibleLocations != null) if(possibleLocations != null)
{ {
if(isInPossibleLocations(possibleLocations, x, y)) if(isInPossibleLocations(possibleLocations, center, x, y))
{
grid.add(createStackPaneForTile(null, true, x - (int)center.getX(), y - (int)center.getY()), x, y);
}
else
{
grid.add(createStackPaneForTile(null, false, 0, 0), x, y);
}
}
else
{
grid.add(createStackPaneForTile(null, false, 0, 0), x, y);
}
}
}
}
}
}
private void placeTile(int x, int y)
{
System.out.println(x + " " + y);
game.placeTile(game.getCurrentTile(), new Point2D(x, y));
nextTile();
}
private StackPane createStackPaneForTile(Tile tile, boolean possible, int x, int y)
{
StackPane stack = new StackPane();
stack.getChildren().add(new ImageView(new Image("de/deadlocker8/roadgame/resources/empty.png")));
if(tile == null)
{
if(possible)
{ {
label.setStyle("-fx-background-color: red"); stack.getChildren().add(new ImageView(new Image("de/deadlocker8/roadgame/resources/border.png")));
stack.setOnMouseClicked(new EventHandler<MouseEvent>()
{
@Override
public void handle(MouseEvent event)
{
if(event.getButton().equals(MouseButton.PRIMARY))
{
placeTile(x, y);
}
}
});
} }
} }
else
{
stack.getChildren().add(new ImageView(new Image("de/deadlocker8/roadgame/resources/green.png")));
grid.add(label, y, x); if(tile.getN().equals(EdgeType.ROAD))
{
ImageView imageViewRoadNorth = new ImageView(new Image("de/deadlocker8/roadgame/resources/road.png"));
stack.getChildren().add(imageViewRoadNorth);
} }
if(tile.getE().equals(EdgeType.ROAD))
{
ImageView imageViewRoadEast = new ImageView(new Image("de/deadlocker8/roadgame/resources/road.png"));
imageViewRoadEast.setRotate(90);
stack.getChildren().add(imageViewRoadEast);
} }
if(tile.getS().equals(EdgeType.ROAD))
{
ImageView imageViewRoadSouth = new ImageView(new Image("de/deadlocker8/roadgame/resources/road.png"));
imageViewRoadSouth.setRotate(180);
stack.getChildren().add(imageViewRoadSouth);
}
if(tile.getW().equals(EdgeType.ROAD))
{
ImageView imageViewRoadWest = new ImageView(new Image("de/deadlocker8/roadgame/resources/road.png"));
imageViewRoadWest.setRotate(270);
stack.getChildren().add(imageViewRoadWest);
} }
} }
return stack;
} }
private boolean isInPossibleLocations(ArrayList<Point2D> possibleLocations, int x, int y) private boolean isInPossibleLocations(ArrayList<Point2D> possibleLocations, Point2D center, int x, int y)
{ {
for(Point2D currentPoint : possibleLocations) for(Point2D currentPoint : possibleLocations)
{ {
if((int)currentPoint.getX() == x && (int)currentPoint.getY() == y) int currentX = (int)center.getX() + (int)currentPoint.getX();
int currentY = (int)center.getY() + (int)currentPoint.getY();
if(currentX == x && currentY == y)
{ {
return true; return true;
} }
...@@ -136,15 +216,19 @@ public class Controller ...@@ -136,15 +216,19 @@ public class Controller
game.setCurrentTile(game.getNextTile()); game.setCurrentTile(game.getNextTile());
stackPaneCurrentTile.getChildren().clear(); stackPaneCurrentTile.getChildren().clear();
stackPaneCurrentTile.getChildren().add(new Label(game.getCurrentTile().toShortString())); stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0));
System.out.println(game.getBoard());
System.out.println(game.getPossibleLocations(game.getCurrentTile()));
updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile())); updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile()));
} }
public void rotateRight() public void rotateRight()
{ {
game.getCurrentTile().rotateRight();
stackPaneCurrentTile.getChildren().clear();
stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0));
updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile()));
} }
public void about() public void about()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment