Compare commits
No commits in common. "626ae041e5e0508d87974870d0c4233bcf2f723f" and "f1adf060358fc8494e22fd19ca1477e366828f0a" have entirely different histories.
626ae041e5
...
f1adf06035
BIN
Sound/hit.mp3
BIN
Sound/hit.mp3
Binary file not shown.
BIN
Sound/plop.mp3
BIN
Sound/plop.mp3
Binary file not shown.
Binary file not shown.
|
@ -42,19 +42,6 @@ public class Board {
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void propagateSunk(Point p) {
|
|
||||||
HitResponse hit = this.getHitResponseOnPoint(p);
|
|
||||||
|
|
||||||
if (hit == null || hit.getType() != HitResponseType.HIT) return;
|
|
||||||
|
|
||||||
hit.setType(HitResponseType.SUNK);
|
|
||||||
|
|
||||||
propagateSunk(new Point(p.getX() + 1, p.getY()));
|
|
||||||
propagateSunk(new Point(p.getX() - 1, p.getY()));
|
|
||||||
propagateSunk(new Point(p.getX(), p.getY() + 1));
|
|
||||||
propagateSunk(new Point(p.getX(), p.getY() - 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createShip(int semester){
|
private void createShip(int semester){
|
||||||
List<ShipData> shipData = Ship.semeterList.get(semester -1);
|
List<ShipData> shipData = Ship.semeterList.get(semester -1);
|
||||||
for (int i = 0; i < shipData.size(); i++) {
|
for (int i = 0; i < shipData.size(); i++) {
|
||||||
|
@ -67,21 +54,14 @@ public class Board {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized boolean addHits(HitResponse hitResponse) {
|
public synchronized boolean addHits(HitResponse hitResponse) {
|
||||||
if (this.getHitResponseOnPoint(hitResponse.getPoint()) == null){
|
if (this.getHitResponsOnPoint(hitResponse.getPoint()) == null){
|
||||||
this.hits.add(hitResponse);
|
this.hits.add(hitResponse);
|
||||||
|
|
||||||
//Propagate sunk for display purposes
|
|
||||||
if (hitResponse.getType() == HitResponseType.SUNK) {
|
|
||||||
hitResponse.setType(HitResponseType.HIT);
|
|
||||||
propagateSunk(hitResponse.getPoint());
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized HitResponse getHitResponseOnPoint(Point point) {
|
public synchronized HitResponse getHitResponsOnPoint(Point point) {
|
||||||
for (int i = 0; i < this.hits.size(); i++){
|
for (int i = 0; i < this.hits.size(); i++){
|
||||||
if (this.hits.get(i).getPoint().equals(point)){
|
if (this.hits.get(i).getPoint().equals(point)){
|
||||||
return this.hits.get(i);
|
return this.hits.get(i);
|
||||||
|
|
|
@ -63,7 +63,7 @@ public class BoardDisplay extends JPanel {
|
||||||
add(rowLabel);
|
add(rowLabel);
|
||||||
} else {
|
} else {
|
||||||
// Spielfeld (interaktive Zellen)
|
// Spielfeld (interaktive Zellen)
|
||||||
JButton field = new JButton("");
|
JButton field = new JButton(x + ", " + y);
|
||||||
field.setBackground(Color.BLUE);
|
field.setBackground(Color.BLUE);
|
||||||
field.setOpaque(true);
|
field.setOpaque(true);
|
||||||
field.setBorderPainted(true);
|
field.setBorderPainted(true);
|
||||||
|
@ -102,7 +102,6 @@ public class BoardDisplay extends JPanel {
|
||||||
} else if (SwingUtilities.isLeftMouseButton(e)) {
|
} else if (SwingUtilities.isLeftMouseButton(e)) {
|
||||||
Point o = new Point(x, y);
|
Point o = new Point(x, y);
|
||||||
handleFieldClick(o);
|
handleFieldClick(o);
|
||||||
SoundHandler.playSound("plop");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -197,46 +196,30 @@ public class BoardDisplay extends JPanel {
|
||||||
fields[i][j].setEnabled(true);
|
fields[i][j].setEnabled(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.enemyBoard) {
|
|
||||||
fields[i][j].setBackground(Color.WHITE);
|
|
||||||
} else {
|
|
||||||
fields[i][j].setBackground(Color.BLUE);
|
fields[i][j].setBackground(Color.BLUE);
|
||||||
}
|
|
||||||
if (!this.player.isReady()) {
|
|
||||||
for(Point p : test) {
|
for(Point p : test) {
|
||||||
if(i==p.getX() && j==p.getY()) {
|
if(i==p.getX() && j==p.getY() && currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) {
|
||||||
if (currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) {
|
|
||||||
fields[i][j].setBackground(Color.GREEN);
|
fields[i][j].setBackground(Color.GREEN);
|
||||||
} else {
|
}else if(i==p.getX() && j==p.getY() && !currentShip.checkValidPlacement(mousePosition,horizontal,player.getBoard().getShips(),gridSize)) {
|
||||||
fields[i][j].setBackground(Color.RED);
|
fields[i][j].setBackground(Color.RED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
for(Ship ship: player.getBoard().getShips()) {
|
for(Ship ship: player.getBoard().getShips()) {
|
||||||
if(ship.isShipOnPos(new Point(i,j))) {
|
if(ship.isShipOnPos(new Point(i,j))) {
|
||||||
fields[i][j].setBackground(Color.LIGHT_GRAY);
|
fields[i][j].setBackground(Color.LIGHT_GRAY);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HitResponse hit = this.player.getBoard().getHitResponseOnPoint(new Point(i, j));
|
HitResponse hit = this.player.getBoard().getHitResponsOnPoint(new Point(i, j));
|
||||||
if (hit != null) {
|
if (hit != null) {
|
||||||
switch (hit.getType()) {
|
switch (hit.getType()) {
|
||||||
case HIT:
|
case HIT:
|
||||||
fields[i][j].setBackground(Color.ORANGE);
|
|
||||||
SoundHandler.playSound("hit");
|
|
||||||
break;
|
|
||||||
case SUNK:
|
case SUNK:
|
||||||
case VICTORY:
|
case VICTORY:
|
||||||
SoundHandler.playSound("destroyed");
|
fields[i][j].setBackground(Color.ORANGE);
|
||||||
fields[i][j].setBackground(Color.RED);
|
|
||||||
break;
|
break;
|
||||||
case MISS:
|
case MISS:
|
||||||
if (this.enemyBoard) {
|
|
||||||
SoundHandler.playSound("miss");
|
|
||||||
fields[i][j].setBackground(Color.BLUE);
|
|
||||||
} else {
|
|
||||||
fields[i][j].setBackground(Color.CYAN);
|
fields[i][j].setBackground(Color.CYAN);
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,8 +7,8 @@ public class HalloSchiffeVersenken {
|
||||||
System.out.println("HelloSchiffeVersenekn");
|
System.out.println("HelloSchiffeVersenekn");
|
||||||
|
|
||||||
|
|
||||||
//System.out.println("sound");
|
System.out.println("sound");
|
||||||
//SoundHandler.playSound("hit");
|
SoundHandler.playSound("hit");
|
||||||
|
|
||||||
Thread.sleep(10000);
|
Thread.sleep(10000);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.net.InetSocketAddress;
|
||||||
/**
|
/**
|
||||||
* Das JoinGame Panel dient zum setzten des Ports/IP-Adresse.
|
* Das JoinGame Panel dient zum setzten des Ports/IP-Adresse.
|
||||||
* Anschließend kann das Verbinden Panel gezeigt werden.
|
* Anschließend kann das Verbinden Panel gezeigt werden.
|
||||||
|
* 51525
|
||||||
|
* ssh.lgc.sh
|
||||||
*/
|
*/
|
||||||
public class JoinGame extends JPanel {
|
public class JoinGame extends JPanel {
|
||||||
// Grafiken
|
// Grafiken
|
||||||
|
|
|
@ -10,7 +10,7 @@ public class LocalPlayer extends Player {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void receiveShoot(Point point) {
|
public synchronized void receiveShoot(Point point) {
|
||||||
HitResponse hitResponse = board.getHitResponseOnPoint(point);
|
HitResponse hitResponse = board.getHitResponsOnPoint(point);
|
||||||
if (!(hitResponse == null)){
|
if (!(hitResponse == null)){
|
||||||
enemy.receiveHit(hitResponse);
|
enemy.receiveHit(hitResponse);
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ public class Point {
|
||||||
public Point (String str) {
|
public Point (String str) {
|
||||||
if (Point.isValidSyntax(str)) {
|
if (Point.isValidSyntax(str)) {
|
||||||
this.setX(str.charAt(0));
|
this.setX(str.charAt(0));
|
||||||
this.setY(Integer.parseInt(str.substring(1)) - 1);
|
this.setY(Integer.parseInt(str.substring(1)));
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalArgumentException("String ist keine gültige Koordinate");
|
throw new IllegalArgumentException("String ist keine gültige Koordinate");
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,7 @@ public class Point {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return (char) ('A' + this.x) + String.valueOf(this.y + 1);
|
return (char) ('A' + this.x) + String.valueOf(this.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
|
|
|
@ -16,10 +16,7 @@ public class SoundHandler {
|
||||||
|
|
||||||
// Wenn fehler beim erstellen von .jar mit sound hier gucken
|
// Wenn fehler beim erstellen von .jar mit sound hier gucken
|
||||||
private static HashMap<String, String> sounds = new HashMap<String, String>(Map.of(
|
private static HashMap<String, String> sounds = new HashMap<String, String>(Map.of(
|
||||||
"miss", "./Sound/water-drip.mp3",
|
"hit", "./Sound/water-drip.mp3"
|
||||||
"hit", "./Sound/hit.mp3",
|
|
||||||
"destroyed", "./Sound/hit.mp3",
|
|
||||||
"plop", "./Sound/plop.mp3"
|
|
||||||
));
|
));
|
||||||
|
|
||||||
public static void playSound(String soundName) {
|
public static void playSound(String soundName) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class SpecificAiPlayerMedium extends AiPlayer{
|
||||||
// Shoot at the enemy and receive the hit response
|
// Shoot at the enemy and receive the hit response
|
||||||
enemy.receiveShoot(nextShot);
|
enemy.receiveShoot(nextShot);
|
||||||
|
|
||||||
HitResponse hitResponse = enemy.board.getHitResponseOnPoint(nextShot);
|
HitResponse hitResponse = enemy.board.getHitResponsOnPoint(nextShot);
|
||||||
// If it's a hit or sunk, add adjacent cells to the hitsQueue
|
// If it's a hit or sunk, add adjacent cells to the hitsQueue
|
||||||
if (hitResponse.getHitResponse() == HitResponseType.HIT) {
|
if (hitResponse.getHitResponse() == HitResponseType.HIT) {
|
||||||
addAdjacentPoints(nextShot);
|
addAdjacentPoints(nextShot);
|
||||||
|
|
Loading…
Reference in New Issue