added reset function

This commit is contained in:
Dorian Zedler 2020-02-25 11:29:23 +01:00
parent 16a6d49c77
commit 5a136f4c9b

View file

@ -21,7 +21,6 @@ package de.itsblue.ConnectFour;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.io.IOException; import java.io.IOException;
import java.io.StringReader;
import javax.swing.*; import javax.swing.*;
@ -166,6 +165,9 @@ public class ConnectFour extends JFrame implements ActionListener {
} }
private void gameOver(String gameOverType) { private void gameOver(String gameOverType) {
if (!this.gameState.equals(GameState.Running))
return;
if (gameOverType.equals("draw")) { if (gameOverType.equals("draw")) {
this.winnerPlayer = -1; this.winnerPlayer = -1;
this.statusLabel.setText("Game over. This was a draw!"); this.statusLabel.setText("Game over. This was a draw!");
@ -181,6 +183,18 @@ public class ConnectFour extends JFrame implements ActionListener {
this.setGameState(GameState.Over); 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 * Function to switch the current player
*/ */