Package a6
Class GameComponent.Target
java.lang.Object
a6.GameComponent.Target
- Enclosing class:
- GameComponent
Represents a dot to be clicked. Maintains current position and size and whether it has
already been "hit" in its current location. Able to check clicks for hits, move to a new
location, and paint itself.
-
Field Summary
Modifier and TypeFieldDescriptionprivate boolean
Whether this has been "hit" in its current location.(package private) int
Radius of circular dot representing the target [px].private Random
Generate random numbers to use when choosing new location.(package private) int
x-coordinate of current center position [px].(package private) int
y-coordinate of current center position [px]. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescription(package private) boolean
checkHit
(int cx, int cy) Return true and set state to "hit" if coordinates (cx,cy) are within this target's circular area and it was not already "hit"; return false otherwise.(package private) int
clip
(int coord, int max) Clip `coord` to be within `[radius, max - radius]`, if possible.(package private) void
Paint dot on provided Graphics `g`.(package private) void
respawn
(int xMax, int yMax) Move target to a random location and reset "hit" state.
-
Field Details
-
x
int xx-coordinate of current center position [px]. -
y
int yy-coordinate of current center position [px]. -
radius
int radiusRadius of circular dot representing the target [px]. -
isHit
private boolean isHitWhether this has been "hit" in its current location. -
rng
Generate random numbers to use when choosing new location.
-
-
Constructor Details
-
Target
private Target()
-
-
Method Details
-
paintDot
Paint dot on provided Graphics `g`. Dot is a circle with our current radius, centered at our current position. Circle is filled red if we have been hit, otherwise blue. -
clip
int clip(int coord, int max) Clip `coord` to be within `[radius, max - radius]`, if possible. Otherwise, return `coord` unchanged. -
respawn
void respawn(int xMax, int yMax) Move target to a random location and reset "hit" state. xMax and yMax are the (inclusive) upper bounds of the x- and y-coordinates of the bounding box of the new position [px]; lower bound is 0 (inclusive). -
checkHit
boolean checkHit(int cx, int cy) Return true and set state to "hit" if coordinates (cx,cy) are within this target's circular area and it was not already "hit"; return false otherwise.
-