...
 
Commits (2)
......@@ -9,5 +9,14 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" exported="">
<library>
<CLASSES>
<root url="jar://$MODULE_DIR$/lib/derby.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>
\ No newline at end of file
#Wed Jan 31 12:32:00 CET 2018
#Wed Jan 31 12:45:06 CET 2018
tutorport=3579
tutorhost=localhost
language=en
role=student
language=de
package controller;
import application.Main;
import model.Terrain;
import model.exceptions.NoCornException;
public class HamsterController {
......@@ -12,11 +14,19 @@ public class HamsterController {
}
public void pickUp() {
terrain.getHamster().pickUp();
try {
terrain.getHamster().pickUp();
} catch (NoCornException e) {
Main.playDeathSound();
}
}
public void putDown() {
terrain.getHamster().putDown();
try {
terrain.getHamster().putDown();
} catch (RuntimeException e) {
Main.playDeathSound();
}
}
public void turnLeft() {
......@@ -24,10 +34,10 @@ public class HamsterController {
}
public void forward() {
terrain.getHamster().forward();
}
public int getHamsterCorns() {
return terrain.getHamsterCorns();
try {
terrain.getHamster().forward();
} catch (Exception e) {
Main.playDeathSound();
}
}
}
......@@ -76,10 +76,13 @@ public class SetFileNameDialogBox {
Optional<String> result = dialog.showAndWait();
result.ifPresent(res -> {
Main.startNewStage(res, terrain);
if (ioController != null)
Terrain newterrain = new Terrain();
newterrain.setUpTerrain(terrain);
if (ioController != null) {
ioController.saveFile(res);
}
Main.activePrograms.add(res);
Main.startNewStage(res, newterrain);
});
......
......@@ -40,21 +40,15 @@ public class TerrainController {
}
public void addWall(int col, int row) {
synchronized (this) {
terrain.addWall(col, row);
}
terrain.addWall(col, row);
}
public void moveHamster(int col, int row) {
synchronized (this) {
terrain.setHamsterPostion(col, row);
}
terrain.setHamsterPostion(col, row);
}
public void deleteTile(int col, int row) {
synchronized (this) {
terrain.deleteTile(col, row);
}
terrain.deleteTile(col, row);
}
public void serializeTerrain() {
......
......@@ -60,44 +60,21 @@ public class DerbyDatabase {
* @param conn
*/
private void createTables(Connection conn) {
PreparedStatement preparedStatement;
try {
conn.prepareStatement(createExampleTable).execute();
preparedStatement = conn.prepareStatement(insertExample);
preparedStatement.setString(1, "der Code");
preparedStatement.setString(2, "das Terrain");
preparedStatement.execute();
preparedStatement = conn.prepareStatement(insertExample);
preparedStatement.setString(1, "anderer Code");
preparedStatement.setString(2, "anderes Terrain");
preparedStatement.execute();
} catch (SQLException e) {
}
try {
conn.prepareStatement(createTagTable).execute();
preparedStatement = conn.prepareStatement(insertTag);
preparedStatement.setString(1, "berg");
preparedStatement.execute();
} catch (SQLException e) {
}
try {
conn.prepareStatement(createExampleTagsTable).execute();
preparedStatement = conn.prepareStatement(insertExampleTag);
preparedStatement.setInt(1, 1);
preparedStatement.setInt(2, 1);
preparedStatement.execute();
preparedStatement = conn.prepareStatement(insertExampleTag);
preparedStatement.setInt(1, 2);
preparedStatement.setInt(2, 1);
preparedStatement.execute();
} catch (SQLException e) {
}
}
......
......@@ -65,6 +65,10 @@ public class Hamster extends Thread {
return terrain.getCornAmount(nextCol, nextRow) != -1;
}
public boolean findCorn() {
return terrain.foundCorn() > 0;
}
@Invisible
private int getNextCol() {
switch (terrain.getHamsterDirection()) {
......@@ -106,6 +110,7 @@ public class Hamster extends Thread {
try {
main();
} catch (RuntimeException e) {
Main.playDeathSound();
this.stopHamster();
}
running = false;
......@@ -113,6 +118,7 @@ public class Hamster extends Thread {
terrain.notifyObservers();
}
@Invisible
public void stopHamster() {
running = false;
terrain.setChanged();
......@@ -120,6 +126,7 @@ public class Hamster extends Thread {
super.stop();
}
@Invisible
public boolean isRunning() {
return this.running;
}
......
......@@ -13,7 +13,10 @@ import javafx.scene.layout.VBox;
import javafx.stage.FileChooser;
import javafx.stage.FileChooser.ExtensionFilter;
import javafx.stage.Stage;
import model.*;
import model.DatabaseManager;
import model.Invisible;
import model.Terrain;
import model.ThreadManager;
import network.CodeTerrain;
import network.NetworkManager;
......@@ -107,7 +110,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
public void buildContextMenu() {
contextMenu = new ContextMenu();
setUpContextMenu(Hamster.class);
// setUpContextMenu(Hamster.class);
setUpContextMenu(terrain.getHamster().getClass());
}
......@@ -141,7 +144,7 @@ public class MainViewCreationFX extends BorderPane implements Observer {
e.printStackTrace();
}
});
if (method.getParameterCount() > 0)
if (method.getReturnType() != void.class)
menuItem.setDisable(true);
contextMenu.getItems().add(menuItem);
}
......