63 lines
1.8 KiB
Java
63 lines
1.8 KiB
Java
import java.util.Random;
|
|
|
|
public class LocalPlayer extends Player {
|
|
|
|
public LocalPlayer(){
|
|
super();
|
|
Random random = new Random();
|
|
this.myCoin = random.nextBoolean();
|
|
}
|
|
|
|
@Override
|
|
public synchronized void receiveShoot(Point point) {
|
|
HitResponse hitResponse = board.getHitResponseOnPoint(point);
|
|
if (!(hitResponse == null)){
|
|
enemy.receiveHit(hitResponse);
|
|
|
|
} else {
|
|
hitResponse = this.board.hit(point);
|
|
enemy.receiveHit(hitResponse);
|
|
}
|
|
|
|
switch (hitResponse.getType()) {
|
|
case HIT, SUNK -> this.myTurn = false;
|
|
case MISS -> this.myTurn = true;
|
|
case VICTORY -> System.out.println("Game Over"); //TODO Was halt bei victory passiert ist hier wurder verloheren
|
|
}
|
|
GameController.getMainFrame().refreshGameBoard();
|
|
}
|
|
|
|
@Override
|
|
public synchronized void receiveHit(HitResponse hitResponse) {
|
|
enemy.board.addHits(hitResponse);
|
|
switch (hitResponse.getType()) {
|
|
case HIT, SUNK -> this.myTurn = true;
|
|
case MISS -> this.myTurn = false;
|
|
case VICTORY -> System.out.println("Win"); // TODO was halt beim victory passier ist hier wurde gewonnen
|
|
}
|
|
GameController.getMainFrame().refreshGameBoard();
|
|
}
|
|
|
|
@Override
|
|
public synchronized void receiveCoin(boolean coin) {
|
|
if (!this.hasReceivedCoin) {
|
|
this.hasReceivedCoin = true;
|
|
this.determineCoinToss();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void shoot(Point point){
|
|
this.myTurn = false;
|
|
enemy.receiveShoot(point);
|
|
}
|
|
|
|
@Override
|
|
public synchronized void ready() {
|
|
for (Ship ship : this.board.getShips()) {
|
|
if (!ship.isPlaced()) return;
|
|
}
|
|
super.ready();
|
|
}
|
|
|
|
} |