Jenkins
3 years ago
3 changed files with 59 additions and 6 deletions
-
4src/main/java/TicTacToe/Cell.java
-
42src/main/java/TicTacToe/Scoreboard.java
-
19src/main/java/TicTacToe/TicTacToeGame.java
@ -0,0 +1,42 @@ |
|||
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]; |
|||
updateScores(); |
|||
} |
|||
|
|||
public void addPoint(int playerID) { |
|||
playerPoints[playerID]++; |
|||
updateScores(); |
|||
} |
|||
|
|||
public void subPoint(int playerID) { |
|||
playerPoints[playerID]--; |
|||
updateScores(); |
|||
} |
|||
|
|||
public void updateScores() { |
|||
int gamesPlayed = 0; |
|||
for(int i = 0; i < playerPoints.length; i++){ |
|||
if(i == 0) { |
|||
setText("Draws: " + playerPoints[0]); |
|||
} else { |
|||
setText(getText() + " Player " + i + ": " + playerPoints[i]); |
|||
} |
|||
|
|||
gamesPlayed += playerPoints[i]; |
|||
} |
|||
setText(getText() + " Games played: " + gamesPlayed); |
|||
|
|||
} |
|||
|
|||
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue