blob: cfadb5c981c2ced39b1dad332fd3ca7aea8dfdc7 (
plain) (
blame)
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
|
package space.m0e.quga.oop.lab56maven.decisions;
import javafx.application.Platform;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import space.m0e.quga.oop.lab56maven.Main;
import space.m0e.quga.oop.lab56maven.entities.common.Coordinates;
import space.m0e.quga.oop.lab56maven.entities.macro.Fortress;
import space.m0e.quga.oop.lab56maven.entities.macro.ThroneRoom;
import space.m0e.quga.oop.lab56maven.entities.micro.Dwarf;
import space.m0e.quga.oop.lab56maven.entities.micro.Nobel;
import java.util.ArrayList;
import java.util.stream.Collectors;
public class GoToThroneRoomDecision extends Decision {
private Dwarf dwarf;
public GoToThroneRoomDecision(int executeWhen, Dwarf dwarf) {
super(executeWhen);
this.dwarf = dwarf;
}
@Override
public void cycle() {
ThroneRoom throneRoom = dwarf.findNearestThroneRoom();
if (throneRoom != null) {
dwarf.getFortress().removeFromContainer(dwarf);
Coordinates nearCoordinates = dwarf.getCoordinatesToThroneRoom(throneRoom);
dwarf.move(nearCoordinates);
if (nearCoordinates.isThere(dwarf)) {
Platform.runLater(() -> {
Fortress fort = Main.fortresses.stream().filter(fortress -> fortress.getThroneRooms().contains(throneRoom)).collect(Collectors.toCollection(ArrayList::new)).get(0);
double lastX = dwarf.getX();
double lastY = dwarf.getY();
dwarf.getFortress().remove(dwarf);
Main.root.getChildren().remove(dwarf.getGroup());
Nobel nobel = new Nobel(dwarf, throneRoom);
Main.immigrants.remove(dwarf);
Main.immigrants.add(nobel);
fort.add(nobel);
fort.removeFromContainer(nobel);
throneRoom.add(nobel);
nobel.setX(lastX);
nobel.setY(lastY);
dwarf.getTimeline().stop();
nobel.getTimeline().play();
});
setComplete(true);
}
}
}
}
|