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

Fixed #6

parent 2899c79b
Branches
Tags
No related merge requests found
Showing
with 83 additions and 5 deletions
No preview for this file type
No preview for this file type
File added
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -169,6 +169,39 @@ public class Board
return possibleLocations;
}
public boolean tileCanBePlaced(Tile tile)
{
if(getPossibleLocations(tile).size() == 0)
{
return false;
}
tile.rotateRight();
if(getPossibleLocations(tile).size() == 0)
{
tile.rotateLeft();
return false;
}
tile.rotateRight();
if(getPossibleLocations(tile).size() == 0)
{
tile.rotateLeft();
tile.rotateLeft();
return false;
}
tile.rotateRight();
if(getPossibleLocations(tile).size() == 0)
{
tile.rotateRight();
return false;
}
tile.rotateRight();
return true;
}
public Dimension getDimension()
{
int minX = 0;
......
......@@ -46,6 +46,11 @@ public class Game
return board.getPossibleLocations(tile);
}
public boolean tileCanBePlaced(Tile tile)
{
return board.tileCanBePlaced(tile);
}
public void placeTile(Tile tile, Point2D position)
{
tile.setPosition(position);
......
package de.deadlocker8.roadgame.tilepacks;
import java.util.HashMap;
import de.deadlocker8.roadgame.logic.TileType;
public class TilePackTest2 extends TilePack
{
public TilePackTest2()
{
super("Test 2");
tiles = new HashMap<>();
tiles.put(TileType.ROAD_END, 1);
tiles.put(TileType.CASTLE_FULL, 1);
tiles.put(TileType.ROAD_CURVE, 1);
}
}
\ No newline at end of file
......@@ -319,6 +319,8 @@ public class Controller
game.setCurrentTile(nextTile);
if(game.tileCanBePlaced(game.getCurrentTile()))
{
stackPaneCurrentTile.getChildren().clear();
stackPaneCurrentTile.getChildren().add(createStackPaneForTile(game.getCurrentTile(), false, 0, 0));
......@@ -326,6 +328,24 @@ public class Controller
updateGrid(game.getBoard(), game.getPossibleLocations(game.getCurrentTile()));
}
else
{
Alert alert = new Alert(AlertType.INFORMATION);
alert.setTitle("Tile skipped");
alert.setHeaderText("");
alert.setContentText("The following tile has been skipped because it doesn't fit the current board:");
Stage dialogStage = (Stage)alert.getDialogPane().getScene().getWindow();
alert.getDialogPane().setExpandableContent(createStackPaneForTile(game.getCurrentTile(), false, 0, 0));
alert.getDialogPane().setExpanded(true);
dialogStage.getIcons().add(icon);
dialogStage.centerOnScreen();
alert.showAndWait();
labelTilesRemaining.setText(String.valueOf(game.getBoard().getTilePack().getNumberOfTiles()));
nextTile();
}
}
public void rotateRight()
{
......
......@@ -7,6 +7,7 @@ import de.deadlocker8.roadgame.tilepacks.TilePack;
import de.deadlocker8.roadgame.tilepacks.TilePackAllPossibleTiles;
import de.deadlocker8.roadgame.tilepacks.TilePackDefault;
import de.deadlocker8.roadgame.tilepacks.TilePackTest;
import de.deadlocker8.roadgame.tilepacks.TilePackTest2;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.fxml.FXML;
......@@ -50,6 +51,7 @@ public class SelectTilePackController
possibleTilePacks.add(new TilePackDefault());
possibleTilePacks.add(new TilePackTest());
possibleTilePacks.add(new TilePackAllPossibleTiles());
possibleTilePacks.add(new TilePackTest2());
for(TilePack currentPack : possibleTilePacks)
{
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment