Commit 44e6ce48 authored by Stefan Michel's avatar Stefan Michel

- es wird nun ein ton abgespielt wenn der hamster gegen eine wand rennt oder das feld verlaesst

parent f7537e79
......@@ -7,6 +7,9 @@ import javafx.stage.Stage;
import model.Terrain;
import view.MainViewCreationFX;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import java.util.ArrayList;
import java.util.List;
......@@ -68,4 +71,21 @@ public class Main extends Application {
ioController.compile(terrain.getName());
}
// von https://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java
public static synchronized void playDeathSound() {
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
new Thread(() -> {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(
Main.class.getResourceAsStream("/death.wav"));
clip.open(inputStream);
clip.start();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}).start();
}
}
......@@ -13,23 +13,23 @@ public class TerrainController implements ITerrainController {
this.terrain = terrain;
}
public void addCorn(int row, int col) {
public void addCorn(int col, int row) {
try {
terrain.addCorn(row, col);
terrain.addCorn(col, row);
} catch (RuntimeException e) {
}
}
public void addWall(int row, int col) {
terrain.addWall(row, col);
public void addWall(int col, int row) {
terrain.addWall(col, row);
}
public void moveHamster(int row, int col) {
terrain.setHamsterPostion(row, col);
public void moveHamster(int col, int row) {
terrain.setHamsterPostion(col, row);
}
public void deleteTile(int row, int col) {
terrain.deleteTile(row, col);
public void deleteTile(int col, int row) {
terrain.deleteTile(col, row);
}
}
package model;
import application.Main;
import model.exceptions.NoCornException;
import model.exceptions.WallException;
import view.Invisible;
......@@ -21,27 +22,32 @@ public class Hamster {
public void main() {
}
public void forward() throws WallException {
int nextRow = terrain.hamsterRow;
int nextCol = terrain.hamsterCol;
public void forward() {
try {
switch (terrain.getHamsterDirection()) {
case (Terrain.NORTH):
nextRow--;
break;
case (Terrain.EAST):
nextCol++;
break;
case (Terrain.SOUTH):
nextRow++;
break;
case (Terrain.WEST):
nextCol--;
break;
}
int nextRow = terrain.hamsterRow;
int nextCol = terrain.hamsterCol;
switch (terrain.getHamsterDirection()) {
case (Terrain.NORTH):
nextRow--;
break;
case (Terrain.EAST):
nextCol++;
break;
case (Terrain.SOUTH):
nextRow++;
break;
case (Terrain.WEST):
nextCol--;
break;
}
if (!terrain.setHamsterPostion(nextCol, nextRow)) {
throw new WallException("Hier steht eine Wand");
if (!terrain.setHamsterPostion(nextCol, nextRow)) {
throw new WallException("Hier steht eine Wand");
}
} catch (RuntimeException e) {
Main.playDeathSound();
}
}
......
......@@ -81,7 +81,7 @@ public class Terrain extends Observable {
}
// entfernt ein Feld
public void deleteTile(int row, int col) {
public void deleteTile(int col, int row) {
if (row > 0 || col > 0 || row > maxCols || col > maxRows) {
this.map[col][row] = 0;
setChanged();
......
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