-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStimer.java
More file actions
58 lines (47 loc) · 1.76 KB
/
Stimer.java
File metadata and controls
58 lines (47 loc) · 1.76 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
package com.company;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.util.Duration;
public class Stimer {
double time;
Controller ctrl;
Timeline timer;
public Stimer(double time, Controller ctrl) {
this.time = time + 0.101;
this.ctrl = ctrl;
}
public double getTime() {
return time;
}
public void start(){
timer = new Timeline();
timer.setCycleCount(Timeline.INDEFINITE);
KeyFrame frame = new KeyFrame(Duration.seconds(0.1), new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
time=time-0.1;
String timeString = String.format("%.2f", time);
ctrl.labelSeconds.setText(timeString.substring(0,timeString.length()-3));
ctrl.labelDseconds.setText(timeString.substring(timeString.length()-2));
if (time<0.1) {
ctrl.labelConsole.setText("Solution: " + ctrl.board.getSolution());
ctrl.labelConsole.setStyle("-fx-background-color:red");
ctrl.labelResult.setText("you are out of time!");
ctrl.gameOver=true;
ctrl.ngames=0;
ctrl.labelThescore.setText((String.valueOf(Integer.parseInt(ctrl.labelThescore.getText())/2)));
ctrl.controlButton.setText("next");
ctrl.controlButton.setStyle("-fx-font-weight:bold");
timer.stop();
}
}
});
timer.getKeyFrames().add(frame);
timer.playFromStart();
}
public void stop(){
timer.stop();
}
}