Nur die besten Spiele ;3
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
861 B

  1. package TicTacToe;
  2. import java.awt.Color;
  3. import javax.swing.JLabel;
  4. public class Scoreboard extends JLabel{
  5. private static final long serialVersionUID = 1L;
  6. public int[] playerPoints;
  7. public Scoreboard(int _playerCount) {
  8. playerPoints = new int[_playerCount];
  9. setForeground(Color.white);
  10. updateScores();
  11. }
  12. public void addPoint(int playerID) {
  13. playerPoints[playerID]++;
  14. updateScores();
  15. }
  16. public void subPoint(int playerID) {
  17. playerPoints[playerID]--;
  18. updateScores();
  19. }
  20. public void updateScores() {
  21. int gamesPlayed = 0;
  22. for(int i = 0; i < playerPoints.length; i++){
  23. if(i == 0) {
  24. setText("Draws: " + playerPoints[0]);
  25. } else {
  26. setText(getText() + " Player " + i + ": " + playerPoints[i]);
  27. }
  28. gamesPlayed += playerPoints[i];
  29. }
  30. setText(getText() + " Games played: " + gamesPlayed);
  31. }
  32. }