-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoard.java
More file actions
134 lines (114 loc) · 5.14 KB
/
Copy pathBoard.java
File metadata and controls
134 lines (114 loc) · 5.14 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
package coloris;
import javafx.animation.FadeTransition;
import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.input.KeyCode;
import javafx.scene.paint.ImagePattern;
import javafx.scene.shape.Rectangle;
import javafx.util.Duration;
public class Board extends Group implements Sprite
{
private final GameInfo gameInfo;
private final NumberDisplayer scoreDisplayer;
private final NumberDisplayer lastDisplayer;
private final NumberDisplayer breakDisplayer;
private final TileMatrix tileMatrix;
private Figure moving;
private Figure nextMoving;
private boolean gameover;
public Board(GameInfo gameInfo)
{
this.gameInfo = gameInfo;
gameover = false;
scoreDisplayer = new NumberDisplayer(gameInfo.getScoreNoDigits(), gameInfo.getDigitWidth(), gameInfo.getDigitHeight(), gameInfo.getDigitSpacing());
scoreDisplayer.setTranslateX(gameInfo.getScoreXCoord());
scoreDisplayer.setTranslateY(gameInfo.getScoreYCoord());
lastDisplayer = new NumberDisplayer(gameInfo.getLastNoDigits(), gameInfo.getDigitWidth(), gameInfo.getDigitHeight(), gameInfo.getDigitSpacing());
lastDisplayer.setTranslateX(gameInfo.getLastXCoord());
lastDisplayer.setTranslateY(gameInfo.getLastYCoord());
breakDisplayer = new NumberDisplayer(gameInfo.getBreakNoDigits(), gameInfo.getDigitWidth(), gameInfo.getDigitHeight(), gameInfo.getDigitSpacing());
breakDisplayer.setTranslateX(gameInfo.getBreakXCoord());
breakDisplayer.setTranslateY(gameInfo.getBreakYCoord());
tileMatrix = new TileMatrix(gameInfo, scoreDisplayer);
moving = new Figure(gameInfo.getTileDimension(), gameInfo.getMinVelocity(), gameInfo.getMaxVelocity(), gameInfo.getVelocityIncrement());
moving.setTranslateX(gameInfo.getMovingXCoord());
moving.setTranslateY(0);//- moving.getHeight());
nextMoving = new Figure(gameInfo.getTileDimension(), gameInfo.getMinVelocity(), gameInfo.getMaxVelocity(), gameInfo.getVelocityIncrement());
nextMoving.setTranslateX(gameInfo.getNextXCoord());
nextMoving.setTranslateY(gameInfo.getNextYCoord());
getChildren().add(scoreDisplayer);
getChildren().add(lastDisplayer);
getChildren().add(breakDisplayer);
getChildren().addAll(moving.getTiles());
getChildren().addAll(nextMoving.getTiles());
}
public void keyPressed(KeyCode code)
{
if (moving != null && moving.isAwake() == true)
{
if (Figure.MOVES_LEFT.contains(code))
moving.moveLeft();
else if (Figure.MOVES_RIGHT.contains(code))
moving.moveRight();
else if (Figure.SLIDES_UP.contains(code))
moving.slideUp();
else if (Figure.INCREMENTS_VELOCITY.contains(code))
moving.incrementVelocity();
else if (Figure.DECREMENTS_VELOCITY.contains(code))
moving.decrementVelocity();
}
}
@Override
public void update()
{
if (moving != null && moving.isAwake() == true)
{
moving.update();
}
else if (moving != null)
{
tileMatrix.addToColumn(moving.getColumn(), moving.getTiles());
moving = null;
tileMatrix.update();
}
else if (tileMatrix.isUpdateInProgress() == false)
{
if (tileMatrix.isGameover() == true)
{
setGameover();
}
else
{
moving = nextMoving;
moving.setTranslateX(gameInfo.getMovingXCoord());
moving.setTranslateY(0);//- moving.getHeight());
nextMoving = new Figure(gameInfo.getTileDimension(), gameInfo.getMinVelocity(), gameInfo.getMaxVelocity(), gameInfo.getVelocityIncrement());
nextMoving.setTranslateX(gameInfo.getNextXCoord());
nextMoving.setTranslateY(gameInfo.getNextYCoord());
getChildren().addAll(nextMoving.getTiles());
}
}
}
public double getFreeSpaceInColumn(int col)
{
return gameInfo.getBoardHeight() - tileMatrix.getNoTiles(col) * moving.getWidth();
}
public boolean isGameover() {return gameover;}
private void setGameover()
{
gameover = true;
Rectangle gameoverText = new Rectangle(gameInfo.getGameoverXCoord(), gameInfo.getGameoverYCoord(), gameInfo.getGameoverWidth(), gameInfo.getGameoverHeight());
Image image = new Image(getClass().getResource("/coloris/sprites/gameover.png").toString());
gameoverText.setFill(new ImagePattern(image, 0, 0, 1, 1, true));
gameoverText.setOpacity(0.0);
gameoverText.setStroke(gameInfo.getBoardBackgroundColor());
FadeTransition ft = new FadeTransition(Duration.millis(2000), gameoverText);
ft.setFromValue(0.0);
ft.setToValue(1.0);
ft.setOnFinished((e) -> {
//stvori prozor sa buttonom koji omogucava
});
ft.play();
getChildren().add(gameoverText);
}
}