added reset function
This commit is contained in:
parent
16a6d49c77
commit
5a136f4c9b
1 changed files with 23 additions and 9 deletions
|
@ -21,7 +21,6 @@ package de.itsblue.ConnectFour;
|
|||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
|
@ -166,21 +165,36 @@ public class ConnectFour extends JFrame implements ActionListener {
|
|||
}
|
||||
|
||||
private void gameOver(String gameOverType) {
|
||||
if (!this.gameState.equals(GameState.Running))
|
||||
return;
|
||||
|
||||
if (gameOverType.equals("draw")) {
|
||||
this.winnerPlayer = -1;
|
||||
this.statusLabel.setText("Game over. This was a draw!");
|
||||
} else {
|
||||
PlateType winnerPlateType = PlateType.valueOf(gameOverType);
|
||||
this.winnerPlayer = this.players[0].getUsedPlateType().equals(winnerPlateType) ? 0 : 1;
|
||||
if(!this.gameType.equals(GameType.Local) && this.players[this.winnerPlayer] instanceof LocalPlayer)
|
||||
this.statusLabel.setText("Game over. You won the game!");
|
||||
if (!this.gameType.equals(GameType.Local) && this.players[this.winnerPlayer] instanceof LocalPlayer)
|
||||
this.statusLabel.setText("Game over. You won the game!");
|
||||
else
|
||||
this.statusLabel.setText("Game over. " + this.players[this.winnerPlayer].getName() + " won the game!");
|
||||
this.statusLabel.setText("Game over. " + this.players[this.winnerPlayer].getName() + " won the game!");
|
||||
}
|
||||
|
||||
this.setGameState(GameState.Over);
|
||||
}
|
||||
|
||||
public void resetGame() {
|
||||
if (!this.gameState.equals(GameState.Over))
|
||||
return;
|
||||
|
||||
this.players[0] = null;
|
||||
this.players[1] = null;
|
||||
this.currentPlayer = -1;
|
||||
this.winnerPlayer = -1;
|
||||
this.gameBoard.clearBoard();
|
||||
this.setGameState(GameState.Idle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to switch the current player
|
||||
*/
|
||||
|
@ -216,11 +230,11 @@ public class ConnectFour extends JFrame implements ActionListener {
|
|||
if (this.gameType != GameType.RemoteClient && this.gameState.equals(GameState.Running))
|
||||
switchPlayer();
|
||||
} else if (e.getActionCommand().startsWith("isMyTurnChanged")) {
|
||||
if(e.getActionCommand().split(" ")[1].equals("true")) {
|
||||
if(!this.gameType.equals(GameType.Local) && src instanceof LocalPlayer)
|
||||
this.statusLabel.setText("Running, it's your turn!'");
|
||||
if (e.getActionCommand().split(" ")[1].equals("true")) {
|
||||
if (!this.gameType.equals(GameType.Local) && src instanceof LocalPlayer)
|
||||
this.statusLabel.setText("Running, it's your turn!'");
|
||||
else
|
||||
this.statusLabel.setText("Running, it's " + src.getName() + "'s turn!'");
|
||||
this.statusLabel.setText("Running, it's " + src.getName() + "'s turn!'");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Reference in a new issue