Browse Source

Add Scoreboard class with basic functions

feature_TicTacToe_Scoreboard
kfkama 3 years ago
parent
commit
30f5312440
  1. 36
      src/main/java/TicTacToe/Scoreboard.java

36
src/main/java/TicTacToe/Scoreboard.java

@ -0,0 +1,36 @@
package TicTacToe;
import javax.swing.JLabel;
public class Scoreboard extends JLabel{
private static final long serialVersionUID = 1L;
public int[] playerPoints;
public Scoreboard(int _playerCount) {
playerPoints = new int[_playerCount];
}
public void addPoint(int playerID) {
playerPoints[playerID]++;
updateScores();
}
public void subPoint(int playerID) {
playerPoints[playerID]--;
updateScores();
}
public void updateScores() {
for(int i = 0; i < playerPoints.length; i++){
if(i == 0) {
setText("Draws: " + playerPoints[0]);
} else {
setText(getText() + " Player " + i + ": " + playerPoints[i]);
}
}
}
}
Loading…
Cancel
Save