-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPersonSearching.java
More file actions
71 lines (58 loc) · 2.54 KB
/
PersonSearching.java
File metadata and controls
71 lines (58 loc) · 2.54 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
import processing.core.PImage;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BiPredicate;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
public class PersonSearching extends Person {
private int resourceCount;
public PersonSearching(String id, Point position, double animationPeriod, double actionPeriod, int resourceLimit, List<PImage> images) {
super(id, position, animationPeriod, actionPeriod, resourceLimit, images);
}
@Override
public void executeActivity(WorldModel world, ImageStore imageStore, EventScheduler scheduler) {
Optional<Entity> target = world.findNearest(getPosition(), new ArrayList<>(Arrays.asList(Tree.class, Sapling.class)));
if (target.isEmpty() || !this.moveTo(world, target.get(), scheduler) || !this.transform(world, scheduler, imageStore)) {
scheduler.scheduleEvent(this, Factory.createActivityAction(this, world, imageStore), getActionPeriod());
}
}
@Override
public boolean moveTo(WorldModel world, Entity target, EventScheduler scheduler) {
if (getPosition().adjacent(target.getPosition())) {
this.resourceCount += 1;
if (target instanceof Plant) {
((Plant) target).setHealth(((Plant) target).getHealth() - 1);
}
return true;
} else {
Point nextPos = this.nextPosition(world, target.getPosition());
if (!getPosition().equals(nextPos)) {
world.moveEntity(scheduler, this, nextPos);
}
return false;
}
}
@Override
public boolean transform(WorldModel world, EventScheduler scheduler, ImageStore imageStore) {
if (resourceCount >= getResourceLimit()) {
ActivityEntity dude = Factory.createPersonFull(getId(), getPosition(), getActionPeriod(), getAnimationPeriod(), getResourceLimit(), getImages());
world.removeEntity(scheduler, this);
scheduler.unscheduleAllEvents(this);
world.tryAddEntity(dude);
dude.scheduleActions(scheduler, world, imageStore);
return true;
}
return false;
}
@Override
public int getHealth() {
return 0;
}
@Override
public List<Point> computePath(Point start, Point end, Predicate<Point> canPassThrough, BiPredicate<Point, Point> withinReach, Function<Point, Stream<Point>> potentialNeighbors) {
return null;
}
}