-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgressBar.java
44 lines (33 loc) · 1.28 KB
/
ProgressBar.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
package com.codegym.games.racer;
import com.codegym.engine.cell.Color;
import com.codegym.engine.cell.Game;
import java.util.Arrays;
public class ProgressBar {
private GameObject progressBar;
private GameObject progressBarField;
private int maxValue;
public ProgressBar(int maxValue) {
this.maxValue = maxValue;
int[][] fieldMatrix = createColoredMatrix(1, maxValue, Color.BLACK);
int[][] indicatorMatrix = createColoredMatrix(1, 1, Color.WHITE);
int x = RacerGame.WIDTH - 5;
int y = RacerGame.HEIGHT / 2 - maxValue / 2;
progressBarField = new GameObject(x, y, fieldMatrix);
progressBar = new GameObject(x, y + maxValue, indicatorMatrix);
}
public void draw(Game game) {
progressBarField.draw(game);
progressBar.draw(game);
}
public void move(int currentValue) {
int dy = currentValue < maxValue - 1 ? currentValue : maxValue - 1;
progressBar.y = progressBarField.y + progressBarField.height - dy - 1;
}
private int[][] createColoredMatrix(int width, int height, Color color) {
int[] line = new int[width];
Arrays.fill(line, color.ordinal());
int[][] matrix = new int[height][width];
Arrays.fill(matrix, line);
return matrix;
}
}