summaryrefslogtreecommitdiff
path: root/src/main/java/space/m0e/quga/oop/lab56maven/handlers/NobelHandler.java
blob: abb84a24c11269ce286f6dfd7dab1046b9bffdad (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package space.m0e.quga.oop.lab56maven.handlers;

import javafx.application.Platform;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import space.m0e.quga.oop.lab56maven.Main;
import space.m0e.quga.oop.lab56maven.decisions.Decision;
import space.m0e.quga.oop.lab56maven.decisions.GoToDwarvesContainerDecision;
import space.m0e.quga.oop.lab56maven.decisions.GoToThroneRoomDecision;
import space.m0e.quga.oop.lab56maven.decisions.GoToWorkstationDecision;
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.Objects;
import java.util.Random;

public class NobelHandler implements EventHandler<ActionEvent> {
    public Nobel getNobel() {
        return nobel;
    }

    private int timer = 0;

    public void setNobel(Nobel nobel) {
        this.nobel = nobel;
    }

    private Nobel nobel;

    public NobelHandler(Nobel nobel) {
        super();
        this.nobel = nobel;
    }

    @Override
    public void handle(ActionEvent event) {
        if (nobel != null && !nobel.isActive()) {
            timer++;
            if (nobel.getFortress() == null) {
                Fortress fortress = nobel.findNearestFortress();
                if (fortress != null) {
                    Coordinates moveToFortress = nobel.getCoordinatesToFortress(fortress);
                    nobel.move(moveToFortress);
                    if (moveToFortress.isThere(nobel)) {
                        Platform.runLater(() -> {
                            nobel.setFortress(fortress);
                            fortress.add(nobel);
                            fortress.removeFromContainer(nobel);
                        });
                    }

                }
            } else {
                ThroneRoom throneRoom = nobel.findNearestThroneRoom();
                if (throneRoom != null) {
                    Coordinates moveToThroneRoom = nobel.getCoordinatesToThroneRoom(throneRoom);
                    nobel.move(moveToThroneRoom);
                    if (moveToThroneRoom.isThere(nobel)) {
                        Platform.runLater(() -> {
                            throneRoom.add(nobel);
                        });
                    }
                }
            }
        }
    }


}