-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScoreBoard.java
More file actions
54 lines (46 loc) · 1.29 KB
/
Copy pathScoreBoard.java
File metadata and controls
54 lines (46 loc) · 1.29 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.awt.Graphics2D;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.awt.Font;
public class ScoreBoard {
private int prevScore;
private int score;
private int highScore;
public ScoreBoard(){
prevScore = 0;
score = 0;
highScore = 0;
}
public void reinitialize(){
prevScore = 0;
score = 0;
}
public void update(Map m, SpriteChicken c){
int count = 0;
for (int i = 0; i < 20; i++){
if (i*50 > c.getX()){
score = count;
return;
} else if (m.getStrip(i) instanceof RoadStrip){
count++;
}
}
}
public void addScores(){
prevScore += score;
}
public int getHighScore(){
return highScore;
}
public void checkHighScore(){
if (score+prevScore > highScore) highScore = score+prevScore;
}
public BufferedImage appear(BufferedImage img){
Graphics2D g = img.createGraphics();
g.setFont(new Font("FONT",Font.PLAIN,18));
g.drawString("Roads Crossed: "+(score+prevScore),10,20);
g.drawString("High Score: "+highScore,10,40);
g.dispose();
return img;
}
}