-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNumericDisplay.java
62 lines (57 loc) · 1.65 KB
/
NumericDisplay.java
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
55
56
57
58
59
60
61
62
/**
* The NumericDisplay class represents on-screen numeric displays in the
* Asteroid Adventure Game. It is used to show the player's score and remaining
* lives, among other numerical information.
*
* @version 1.0
* @since 2023-04-04
*/
public class NumericDisplay implements Drawable {
private String prefix;
private int value;
private Point location;
/**
* Constructs a new NumericDisplay object at a specified location with a prefix and initial value.
*
* @param xPos X-coordinate of the display's location.
* @param yPos Y-coordinate of the display's location.
* @param prefix Text prefix to display before the numeric value.
* @param value Initial numeric value to display.
*/
public NumericDisplay(int xPos, int yPos, String prefix, int value) {
this.location = new Point(xPos, yPos);
this.prefix = prefix;
this.value = value;
}
/**
* Gets the location of the numeric display.
*
* @return The location as a Point object.
*/
public Point getLocation() {
return this.location;
}
/**
* Gets the current value of the numeric display.
*
* @return The current value.
*/
public int getValue() {
return this.value;
}
/**
* Sets a new value for the numeric display.
*
* @param value The new value to be displayed.
*/
public void setValue(int value) {
this.value = value;
}
/**
* Draws the numeric display on the game screen.
*/
@Override
public void draw() {
StdDraw.textLeft(location.getX(), location.getY(), prefix + value);
}
}