Commit 219eb65d authored by Stefan Michel's avatar Stefan Michel

felder koennen nur noch per linksklick veraendert werden

parent a5f31b84
......@@ -23,8 +23,8 @@ public class Terrain extends Observable {
private Hamster hamster;
private String name = "DefaultHamster";
int maxCols = 20;
int maxRows = 15;
int maxCols = 10;
int maxRows = 10;
int hamsterRow = 0;
int hamsterCol = 0;
......@@ -114,8 +114,8 @@ public class Terrain extends Observable {
if (this.map[0][0] < 0) {
this.map[0][0] = 0;
}
this.hamsterRow = 0;
this.hamsterCol = 0;
this.hamsterRow = 0;
}
int[][] newMap = new int[maxCols][maxRows];
......@@ -129,8 +129,6 @@ public class Terrain extends Observable {
System.arraycopy(map[i], 0, newMap[i], 0, newMap[i].length);
}
}
this.maxRows = maxRows;
map = newMap;
setChanged();
......@@ -145,10 +143,9 @@ public class Terrain extends Observable {
if (this.map[0][0] < 0) {
this.map[0][0] = 0;
}
this.hamsterRow = 0;
this.hamsterCol = 0;
this.hamsterRow = 0;
}
int[][] newMap = new int[maxCols][maxRows];
if (this.maxCols < maxCols) {
......@@ -160,8 +157,6 @@ public class Terrain extends Observable {
System.arraycopy(map[i], 0, newMap[i], 0, newMap[i].length);
}
}
this.maxCols = maxCols;
map = newMap;
setChanged();
......
......@@ -3,12 +3,11 @@ package view;
import application.Main;
import controller.*;
import javafx.geometry.Side;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.input.*;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
......@@ -50,6 +49,15 @@ public class MainViewCreationFX extends VBox {
//Territory Pane erstellen
territoriumPanel = new TerritoriumPanelFX(terrain, terrainController);
// hamsterContextMenu
ContextMenu contextMenu = new ContextMenu();
contextMenu.getItems().add(new MenuItem("Moin"));
territoriumPanel.getHamster().setOnContextMenuRequested(event -> {
contextMenu.show(territoriumPanel.getHamster(), Side.RIGHT, 0, 0);
event.consume();
});
ScrollPane terrainPane = new ScrollPane(territoriumPanel);
terrainPane.setPrefSize(TerritoriumPanelFX.TILE_SIZE * terrain.getMaxCols(),
......@@ -196,19 +204,21 @@ public class MainViewCreationFX extends VBox {
deleteMenuItem = new RadioMenuItem("_Kachel löschen");
// Hier die Daten vom MouseEvent werden nur an den TerrainController geschickt je nach dem welcher Button aktiv ist
territoriumPanel.setOnMouseClicked(event -> {
if (hamsterMenuItem.isSelected())
terrainController.moveHamster((int) event.getY() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getX() / TerritoriumPanelFX.TILE_SIZE);
if (cornMenuItem.isSelected())
terrainController.addCorn((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (wallMenuItem.isSelected())
terrainController.addWall((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (deleteMenuItem.isSelected())
terrainController.deleteTile((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
territoriumPanel.setOnMouseClicked((MouseEvent event) -> {
if (event.getButton().equals(MouseButton.PRIMARY)) {
if (hamsterMenuItem.isSelected())
terrainController.moveHamster((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (cornMenuItem.isSelected())
terrainController.addCorn((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (wallMenuItem.isSelected())
terrainController.addWall((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (deleteMenuItem.isSelected())
terrainController.deleteTile((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
}
});
hamsterMenuItem.setToggleGroup(toggleGroup);
......@@ -228,15 +238,19 @@ public class MainViewCreationFX extends VBox {
MenuItem linksUm = new MenuItem("_linksUm");
linksUm.setAccelerator(new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
linksUm.setOnAction(event -> hamsterController.turnLeft());
MenuItem vor = new MenuItem("_vor");
vor.setAccelerator(new KeyCodeCombination(KeyCode.V, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
vor.setOnAction(event -> hamsterController.forward());
MenuItem nimm = new MenuItem("_nimm");
nimm.setAccelerator(new KeyCodeCombination(KeyCode.N, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
nimm.setOnAction(event -> hamsterController.pickUp());
MenuItem gib = new MenuItem("_gib");
gib.setAccelerator(new KeyCodeCombination(KeyCode.G, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN));
gib.setOnAction(event -> hamsterController.putDown());
return new Menu("_Hamster", null, koernerImMaul, linksUm, vor, nimm, gib);
}
......@@ -306,19 +320,21 @@ public class MainViewCreationFX extends VBox {
ToggleButton delete = new ToggleButton(null, new ImageView(new Image("/Delete24.gif")));
// Hier die Daten vom MouseEvent werden nur an den TerrainController geschickt je nach dem welcher Button aktiv ist
territoriumPanel.setOnMouseClicked(event -> {
if (hamster.isSelected())
terrainController.moveHamster((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (corn.isSelected())
terrainController.addCorn((int) event.getY() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getX() / TerritoriumPanelFX.TILE_SIZE);
if (wall.isSelected())
terrainController.addWall((int) event.getY() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getX() / TerritoriumPanelFX.TILE_SIZE);
if (delete.isSelected())
terrainController.deleteTile((int) event.getY() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getX() / TerritoriumPanelFX.TILE_SIZE);
territoriumPanel.setOnMouseClicked((MouseEvent event) -> {
if (event.getButton().equals(MouseButton.PRIMARY)) {
if (hamster.isSelected())
terrainController.moveHamster((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (corn.isSelected())
terrainController.addCorn((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (wall.isSelected())
terrainController.addWall((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
if (delete.isSelected())
terrainController.deleteTile((int) event.getX() / TerritoriumPanelFX.TILE_SIZE,
(int) event.getY() / TerritoriumPanelFX.TILE_SIZE);
}
});
// bind buttons to menubaritems
......
......@@ -25,7 +25,7 @@ public class TerritoriumPanelFX extends Region implements Observer {
private Image hamsterImage;
private List<Image> cornImages;
private Image wallImage;
ImageView hamster;
private ImageView hamster;
public static final int TILE_SIZE = 32;
......@@ -113,5 +113,7 @@ public class TerritoriumPanelFX extends Region implements Observer {
}
}
public ImageView getHamster() {
return hamster;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment