-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreboard.java
More file actions
34 lines (33 loc) · 806 Bytes
/
Scoreboard.java
File metadata and controls
34 lines (33 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import javax.swing.*;
import java.awt.*;
public class Scoreboard extends JPanel
{
private JLabel healthBar, scoreTitle;
private int score, health;
public Scoreboard()
{
setLayout(new GridLayout(1, 2));
score = 0;
health = 200;
scoreTitle = new JLabel("Score: " + score);
healthBar = new JLabel("HP: " + health + "/200");
}
public void updatehealthBar(int healths)
{
health = healths;
if(health > 200)
{
health = 200;
}
else if(health < 50)
{
healthBar.setForeground(Color.RED);
}
healthBar.setText("HP: " + health + "/200");
}
public void updateScore(int reward)
{
score = score + reward;
scoreTitle.setText("Score: " + score);
}
}