@@ -28,15 +28,15 @@ public void start(Stage primaryStage) {
28
28
}
29
29
30
30
static class BeanMachinePane extends Pane {
31
- private final int triangleSize ;
31
+ private final int numberOfPins ;
32
32
private final int numberOfSlots ;
33
33
private Circle [] pins ;
34
34
35
35
public BeanMachinePane (double width , double height , int numberOfSlots ) {
36
36
setWidth (width );
37
37
setHeight (height );
38
38
this .numberOfSlots = numberOfSlots ;
39
- this .triangleSize = circleCount (numberOfSlots );
39
+ this .numberOfPins = getNumberOfPins (numberOfSlots );
40
40
paint ();
41
41
}
42
42
@@ -49,7 +49,7 @@ private void paint() {
49
49
paneHeight * 0.8 );
50
50
51
51
double distance = (lowerLine .getEndX () - lowerLine .getStartX ()) / numberOfSlots ;
52
- pins = new Circle [triangleSize ];
52
+ pins = new Circle [numberOfPins ];
53
53
int index = 0 ;
54
54
for (int i = 1 ; i < numberOfSlots ; i ++) {
55
55
double x = lowerLine .getStartX () + (i * distance * 0.50 ) + distance / 2 ;
@@ -97,12 +97,18 @@ private void paint() {
97
97
getChildren ().addAll (outlineShape );
98
98
}
99
99
100
- private int circleCount (int slots ) {
101
- int count = 0 ;
102
- while (slots -- > 1 ) {
103
- count += slots ;
104
- }
105
- return count ;
100
+ /**
101
+ * @param slots the number of slots in the bean machine
102
+ * @return the number of pins in the bean machine
103
+ */
104
+ int getNumberOfPins (int slots ) {
105
+ int numPins = 0 ;
106
+ do {
107
+ slots --;
108
+ numPins += slots ;
109
+ } while (slots > 1 );
110
+
111
+ return numPins ;
106
112
}
107
113
108
114
}
0 commit comments