Kommentare und Withdraw #24
|
@ -56,12 +56,9 @@ public class GameBoard extends JPanel {
|
||||||
List<Ship> shipsP1 =p1.getBoard().getShips();
|
List<Ship> shipsP1 =p1.getBoard().getShips();
|
||||||
List<Ship> shipsP2 =p2.getBoard().getShips();
|
List<Ship> shipsP2 =p2.getBoard().getShips();
|
||||||
|
|
||||||
giveUpButton.addActionListener(new ActionListener() {
|
giveUpButton.addActionListener((e) -> {
|
||||||
@Override
|
|
||||||
public void actionPerformed(ActionEvent e) {
|
|
||||||
// TODO Hier könnte Ihr Backend Code stehen
|
|
||||||
frame.showPanel("MainMenu");
|
frame.showPanel("MainMenu");
|
||||||
}
|
p1.withdraw();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public class LocalPlayer extends Player {
|
||||||
switch (hitResponse.getType()) {
|
switch (hitResponse.getType()) {
|
||||||
case HIT, SUNK -> this.myTurn = false;
|
case HIT, SUNK -> this.myTurn = false;
|
||||||
case MISS -> this.myTurn = true;
|
case MISS -> this.myTurn = true;
|
||||||
case VICTORY -> GameController.getMainFrame().showPanelLose("LoseScreen", this);
|
case VICTORY -> this.lose();
|
||||||
}
|
}
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
GameController.getMainFrame().refreshGameBoard();
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class LocalPlayer extends Player {
|
||||||
switch (hitResponse.getType()) {
|
switch (hitResponse.getType()) {
|
||||||
case HIT, SUNK -> this.myTurn = true;
|
case HIT, SUNK -> this.myTurn = true;
|
||||||
case MISS -> this.myTurn = false;
|
case MISS -> this.myTurn = false;
|
||||||
case VICTORY -> GameController.getMainFrame().showPanelWin("", this);
|
case VICTORY -> this.win();
|
||||||
}
|
}
|
||||||
GameController.getMainFrame().refreshGameBoard();
|
GameController.getMainFrame().refreshGameBoard();
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,10 +84,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "WITHDRAW":
|
case "WITHDRAW":
|
||||||
//Found funny cheese to do this without GUI Access
|
this.withdraw();
|
||||||
HitResponse tmp_hit = new HitResponse(0, new Point(0,0));
|
|
||||||
tmp_hit.setType(HitResponseType.VICTORY);
|
|
||||||
this.receiveHit(tmp_hit);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -160,4 +157,10 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
||||||
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
|
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void receiveWithdraw() {
|
||||||
|
this.socket.send(new SocketPackage("WITHDRAW"));
|
||||||
|
super.receiveWithdraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,6 +137,7 @@ public abstract class Player {
|
||||||
* and players
|
* and players
|
||||||
*
|
*
|
||||||
* This method should be called at the end of a game
|
* This method should be called at the end of a game
|
||||||
|
* This method should be called at the end of a game
|
||||||
*
|
*
|
||||||
* @author Luca Conte
|
* @author Luca Conte
|
||||||
*/
|
*/
|
||||||
|
@ -146,4 +147,20 @@ public abstract class Player {
|
||||||
this.board = null;
|
this.board = null;
|
||||||
this.enemy = null;
|
this.enemy = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void win() {
|
||||||
|
GameController.getMainFrame().showPanelWin("", this);
|
||||||
|
}
|
||||||
|
public void lose() {
|
||||||
|
GameController.getMainFrame().showPanelLose("", this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void withdraw() {
|
||||||
|
this.enemy.receiveWithdraw();
|
||||||
|
this.lose();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void receiveWithdraw(){
|
||||||
|
this.win();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue