-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc_infected.java
More file actions
115 lines (95 loc) · 2.62 KB
/
src_infected.java
File metadata and controls
115 lines (95 loc) · 2.62 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import java.io.Serializable;
import java.util.List;
import java.util.Iterator;
import java.util.Random;
public class infected implements Serializable {
private int age;
private int totalHour;
private double movementFreedom = 0.95;
private double moveChance;
private boolean personInfected = false;
private int infectedAge;
private double deathChance,deathRand;
private boolean alive;
private Location location;
public infected(boolean startWithRandomAge) {
totalHour = 0;
alive = true;
}
public void hunt(Field currentField, Field updatedField, List<infected> babyinfectedStorage, List<People> babyPeopleStorage, int hour) {
totalHour ++;
if (totalHour > 336) {
deathRand = (double) (Math.random());
if (deathRand > deathChance) {
People newPeople = new People(false);
babyPeopleStorage.add(newPeople);
Location loc = updatedField.randomAdjacentLocation(location);
newPeople.setLocation(loc);
updatedField.put(newPeople, loc);
alive = false;
} else {
alive = false;
}
}
if (alive) {
if(personInfected) {
infected newinfected = new infected(false);
babyinfectedStorage.add(newinfected);
Location loc = updatedField.randomAdjacentLocation(location);
newinfected.setLocation(loc);
newinfected.setAge(infectedAge);
updatedField.put(newinfected, loc);
personInfected = false;
}
Location newLocation = findFood(currentField, location);
if (hour < 17) {
if (newLocation == null) {
moveChance = (double) (Math.random());
if(moveChance > movementFreedom) {
newLocation = updatedField.freeAdjacentLocation(location);
} else {
newLocation = location;
}
}
} else {
newLocation = location;
}
if (newLocation != null) {
setLocation(newLocation);
updatedField.put(this, newLocation);
} else {
alive = false;
}
}
}
private Location findFood(Field field, Location location) {
List<Location> adjacentLocations = field.adjacentLocations(location);
for (Location where : adjacentLocations) {
Object organism = field.getObjectAt(where);
if (organism instanceof People) {
People People1 = (People) organism;
if (People1.isAlive()) {
personInfected = People1.setInfected();
deathChance = People1.getDeathRate();
infectedAge = People1.getAge();
}
}
}
return null;
}
public void setAge(int A) {
age = A;
}
public int getAge() {
return age;
}
public boolean isAlive() {
return alive;
}
public void setLocation(int row, int col) {
this.location = new Location(row, col);
}
public void setLocation(Location location) {
this.location = location;
}
}