-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCake.java
More file actions
53 lines (46 loc) · 1.97 KB
/
Copy pathCake.java
File metadata and controls
53 lines (46 loc) · 1.97 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
public final class Cake extends Subject {
private static final int WIDTH_OF_CANDLE = 1;
private final int x;
private final int y;
private final int width;
private final int height;
private final int numberOfCandles;
private final int numberOfBreads;
private final float widthOfTopBread;
private final int heightOfLevel;
public Cake(int x, int y, int width, int height, int numberOfCandles, int numberOfBreads) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.numberOfCandles = numberOfCandles;
this.numberOfBreads = numberOfBreads;
components = new Drawable[numberOfCandles + numberOfBreads];
widthOfTopBread = (float) width / numberOfBreads;
final boolean isCandleExists = numberOfCandles > 0;
final boolean isBreadExists = numberOfBreads > 0;
heightOfLevel = (int) ((height - ((!isCandleExists && isBreadExists ? ((float) width / 2) / 2 : 0)
+ (isBreadExists ? ((float) width / 2) / 2 : 0))) / ((isCandleExists ? 1 : 0) + numberOfBreads));
setCandles();
setBreads();
}
private void setCandles() {
final float distanceBetweenCandles = (widthOfTopBread - (numberOfCandles * WIDTH_OF_CANDLE))
/ (numberOfCandles + 1);
final int startOfTopBread = (width - (int) widthOfTopBread) / 2;
for (int index = 0; index < numberOfCandles; index++) {
components[index] = new Candle((int) (startOfTopBread + distanceBetweenCandles
+ index * (WIDTH_OF_CANDLE + distanceBetweenCandles)), 0, WIDTH_OF_CANDLE, heightOfLevel);
}
}
private void setBreads() {
int widthOfCurrentBread;
final boolean isCandleExists = numberOfCandles > 0;
for (int index = 0; index < numberOfBreads; index++) {
widthOfCurrentBread = (int) ((1 + index) * widthOfTopBread);
components[numberOfCandles + index] = new Bread(x + ((width - widthOfCurrentBread) / 2),
y + (isCandleExists ? heightOfLevel : (width / 2) / 2) + index * heightOfLevel, widthOfCurrentBread,
heightOfLevel);
}
}
}