a bit cleaner withdraw
This commit is contained in:
parent
7fb19bfeac
commit
e85f151b33
|
@ -56,12 +56,9 @@ public class GameBoard extends JPanel {
|
|||
List<Ship> shipsP1 =p1.getBoard().getShips();
|
||||
List<Ship> shipsP2 =p2.getBoard().getShips();
|
||||
|
||||
giveUpButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
// TODO Hier könnte Ihr Backend Code stehen
|
||||
frame.showPanel("MainMenu");
|
||||
}
|
||||
giveUpButton.addActionListener((e) -> {
|
||||
frame.showPanel("MainMenu");
|
||||
p1.withdraw();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public class LocalPlayer extends Player {
|
|||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK -> this.myTurn = false;
|
||||
case MISS -> this.myTurn = true;
|
||||
case VICTORY -> GameController.getMainFrame().showPanelLose("LoseScreen", this);
|
||||
case VICTORY -> this.lose();
|
||||
}
|
||||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ public class LocalPlayer extends Player {
|
|||
switch (hitResponse.getType()) {
|
||||
case HIT, SUNK -> this.myTurn = true;
|
||||
case MISS -> this.myTurn = false;
|
||||
case VICTORY -> GameController.getMainFrame().showPanelWin("", this);
|
||||
case VICTORY -> this.win();
|
||||
}
|
||||
GameController.getMainFrame().refreshGameBoard();
|
||||
}
|
||||
|
|
|
@ -84,10 +84,7 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
break;
|
||||
|
||||
case "WITHDRAW":
|
||||
//Found funny cheese to do this without GUI Access
|
||||
HitResponse tmp_hit = new HitResponse(0, new Point(0,0));
|
||||
tmp_hit.setType(HitResponseType.VICTORY);
|
||||
this.receiveHit(tmp_hit);
|
||||
this.withdraw();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -160,4 +157,10 @@ public class OnlinePlayer_1_1_0 extends OnlinePlayer {
|
|||
// SHOULD NEVER BE CALLED ON ONLINE PLAYER. ONLY ON HUMAN PLAYER
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveWithdraw() {
|
||||
this.socket.send(new SocketPackage("WITHDRAW"));
|
||||
super.receiveWithdraw();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,6 +137,7 @@ public abstract class Player {
|
|||
* and players
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
@ -146,4 +147,20 @@ public abstract class Player {
|
|||
this.board = 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