-
Notifications
You must be signed in to change notification settings - Fork 3
/
LoadThread.java
94 lines (75 loc) · 2.76 KB
/
LoadThread.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
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
package com.danilchican.pacman;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import Statistics.ScalaSorting;
import Statistics.ScalaStatistic;
import javafx.application.Platform;
import javafx.geometry.Insets;
import javafx.geometry.Rectangle2D;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
public class LoadThread implements Runnable {
private Image blockImg;
private boolean isMainScreen = true;
public void setPosition(int x, int y) {
Constants.loader.setTranslateX(x);
Constants.loader.setTranslateY(y);
}
LoadThread(boolean mainScreen, String name, int width, int height, int fitHeight, int fitWidth,
int posX, int posY) {
blockImg = new Image(getClass().getResourceAsStream(name));
Constants.loader = new ImageView(blockImg);
Constants.loader.setFitHeight(fitHeight);
Constants.loader.setFitWidth(fitWidth);
Constants.loader.setViewport(new Rectangle2D(0, 0, width, height));
setPosition(posX, posY);
}
public void run() {
Platform.runLater(new Runnable() {
@Override
public void run() {
if (isMainScreen) {
Constants.mainRoot.getChildren().add(Constants.loader);
} else {
Constants.loadScreen.getChildren().add(Constants.loader);
}
}
});
Constants.save.convertSavesInToInfo();
JavaSorting javaSort = new JavaSorting();
long time = System.currentTimeMillis();
javaSort.sort(Constants.games, 0, Constants.games.length - 1);
time = System.currentTimeMillis() - time;
System.out.println("Time for java sort: " + time);
ScalaSorting scalaSort = new ScalaSorting();
time = System.currentTimeMillis();
scalaSort.sort(Constants.games);
time = System.currentTimeMillis() - time;
System.out.println("Time for scala sort: " + time);
List<Integer> listStat = new ArrayList<Integer>();
for (GameInfo game : Constants.games) {
listStat.add(game.getRightMoving());
}
int[] statistics = new int[listStat.size()];
for (int i=0; i < statistics.length; i++) {
statistics[i] = listStat.get(i).intValue();
}
ScalaStatistic stat = new ScalaStatistic();
int indexArray[] = stat.getStatistic(statistics);
String statisticText = new String("Òîï-3 èãð, êîòîðûå âûèãðàë èãðîê ñ íàèë. äâèæåíèåì ââåðõ: \n");
System.out.println(statisticText);
for (int i = 0; i < 3; i++) {
System.out.println(indexArray[i]);
}
Platform.runLater(new Runnable() {
@Override
public void run() {
Constants.mainRoot.getChildren().remove(Constants.loader);
Constants.loader = null;
Constants.startSorting = false;
Constants.menu.setPadding(new Insets(1, 0, 0, 0));
}
});
}
}