Commit 223ab26a authored by Stefan Michel's avatar Stefan Michel

- View umgebaut, damit dependendies nicht in jede klasse injectet werden...

- View umgebaut, damit dependendies nicht in jede klasse injectet werden muessen, und da es abhaengigkeiten zwischen menubarfx und toolbarfx gab
parent 201cd447
package application;
import controller.IInputOutputController;
import controller.IOController;
import controller.ITerrainController;
import controller.TerrainController;
import controller.*;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
......@@ -17,6 +14,7 @@ public class Main extends Application {
private Terrain terrain;
private ITerrainController terrainController;
private IHamsterController hamsterController;
public static final List<String> activePrograms = new ArrayList<>();
private IInputOutputController ioController;
......@@ -24,27 +22,15 @@ public class Main extends Application {
launch(args);
}
@Override
public void init() {
terrain = new Terrain();
terrainController = new TerrainController(terrain);
ioController = new IOController(terrain);
//TEST-INIT
terrain.setHamsterPostion(0, 0);
terrain.addCorn(1, 2);
terrain.addCorn(1, 2);
terrain.addWall(3, 4);
}
public static void startNewStage(String name) {
Terrain terrain = new Terrain();
ITerrainController terrainController = new TerrainController(terrain);
IInputOutputController ioController = new IOController(terrain);
IHamsterController hamsterController = new HamsterController(terrain);
terrain.setName(name);
Stage newStage = new Stage();
Scene scene = new Scene(new MainViewCreationFX(terrain, terrainController, ioController), 1000, 500);
Scene scene = new Scene(new MainViewCreationFX(terrain, terrainController, ioController, hamsterController), 1000, 500);
newStage.setScene(scene);
newStage.setTitle(terrain.getName());
newStage.show();
......@@ -54,9 +40,23 @@ public class Main extends Application {
});
}
@Override
public void init() {
terrain = new Terrain();
terrainController = new TerrainController(terrain);
ioController = new IOController(terrain);
hamsterController = new HamsterController(terrain);
//TEST-INIT
terrain.setHamsterPostion(0, 0);
terrain.addCorn(1, 2);
terrain.addCorn(1, 2);
terrain.addWall(3, 4);
}
@Override
public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(new MainViewCreationFX(terrain, terrainController, ioController), 1000, 500);
Scene scene = new Scene(new MainViewCreationFX(terrain, terrainController, ioController, hamsterController), 1000, 500);
primaryStage.setScene(scene);
primaryStage.setTitle(terrain.getName());
primaryStage.show();
......
......@@ -3,7 +3,7 @@ package controller;
import model.Terrain;
public class HamsterController {
public class HamsterController implements IHamsterController {
private Terrain terrain;
......
package controller;
public interface IHamsterController {
public void pickUp();
public void putDown();
public void turnLeft();
public void forward();
public int getHamsterCorns();
}
......@@ -39,7 +39,7 @@ public class Hamster {
break;
}
if (!terrain.setHamsterPostion(nextRow, nextCol)) {
if (!terrain.setHamsterPostion(nextCol, nextRow)) {
throw new WallException("Hier steht eine Wand");
}
}
......
......@@ -2,10 +2,7 @@ package view;
import application.Main;
import controller.IInputOutputController;
import controller.ITerrainController;
import controller.SetFileNameDialogBox;
import controller.SetMapSizeDialogBox;
import controller.*;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
......@@ -40,12 +37,15 @@ public class MainViewCreationFX extends VBox {
private TerritoriumPanelFX territoriumPanel;
private ITerrainController terrainController;
private IInputOutputController ioController;
private IHamsterController hamsterController;
private Terrain terrain;
private TextArea textArea;
public MainViewCreationFX(Terrain terrain, ITerrainController terrainController, IInputOutputController ioController) {
public MainViewCreationFX(Terrain terrain, ITerrainController terrainController, IInputOutputController ioController,
IHamsterController hamsterController) {
this.terrainController = terrainController;
this.ioController = ioController;
this.hamsterController = hamsterController;
this.terrain = terrain;
//Territory Pane erstellen
......@@ -340,6 +340,12 @@ public class MainViewCreationFX extends VBox {
Button nimm = new Button(null, new ImageView(new Image("/HamsterPick24.png")));
Button gib = new Button(null, new ImageView(new Image("/HamsterPut24.png")));
// hamsterbutton funktionen werden gesetzt
linksUm.setOnAction(event -> this.hamsterController.turnLeft());
vor.setOnAction(event -> this.hamsterController.forward());
nimm.setOnAction(event -> this.hamsterController.pickUp());
gib.setOnAction(event -> this.hamsterController.putDown());
// Simulation
Button start = new Button(null, new ImageView(new Image("/Play24.gif")));
Button pause = new Button(null, new ImageView(new Image("/Pause24.gif")));
......
package view;
import javafx.scene.control.MenuBar;
/**
* Created by Stefan Michel on 18.10.17.
*/
class MenuBarFX extends MenuBar {
}
package view;
import controller.IInputOutputController;
import javafx.scene.control.ToolBar;
/**
* Created by Stefan Michel on 18.10.17.
*/
class ToolBarFX extends ToolBar {
private IInputOutputController ioController;
public IInputOutputController getIoController() {
return ioController;
}
public void setIoController(IInputOutputController ioController) {
this.ioController = ioController;
}
}
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