-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsrc_People.java
More file actions
150 lines (127 loc) · 3.96 KB
/
src_People.java
File metadata and controls
150 lines (127 loc) · 3.96 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import java.io.Serializable;
import java.util.List;
import java.util.Random;
public class People implements Serializable {
private double movementFreedom = 0.8;
private double moveChance;
private static double ageRandPercent;
private Location newLocation;
private double infecRand;
private static int age;
private boolean alive;
private static double infecFactorAge;
private boolean maskOn = true;
private static double deathRate;
private double infecFactorDistance;
private static double infecChance;
private Location location;
private static boolean infecFactorMask;
private double maskEffect = (Math.random() * .26) + .49;
public People(boolean startWithRandomAge)
{
ageGenerator();
alive = true;
}
public static boolean mask(boolean mask) {
if(mask = true) {
infecFactorMask = true;
} else {
infecFactorMask = false;
}
return infecFactorMask;
}
public void run(Field updatedField, List<People> babyPeopleStorage, int hour) {
if(alive) {
if (hour < 17) {
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;
}
}
}
public static void ageGenerator() {
ageRandPercent = (double) (Math.random());
if (ageRandPercent < 0.058) {
age = (int) (1 + Math.random() * 4);
infecFactorAge = 0.022;
deathRate = 0;
} else if (ageRandPercent < 0.225) {
age = (int) (5 + Math.random() * 12);
infecFactorAge = 0.08;
} else if (ageRandPercent < 0.468) {
age = (int) (18 + Math.random() * 16);
infecFactorAge = 0.352;
} else if (ageRandPercent < 0.661) {
age = (int) (35 + Math.random() * 14);
infecFactorAge = 0.249;
deathRate = 0.058;
} else if (ageRandPercent < 0.785) {
age = (int) (50 + Math.random() * 9);
infecFactorAge = 0.139;
deathRate = 0.104;
} else if (ageRandPercent < 0.844) {
age = (int) (60 + Math.random() * 4);
infecFactorAge = 0.05;
deathRate = 0.082;
} else if (ageRandPercent < 0.894) {
age = (int) (65 + Math.random() * 4);
infecFactorAge = 0.035;
deathRate = 0.102;
} else if (ageRandPercent < 0.961) {
age = (int) (70 + Math.random() * 9);
infecFactorAge = 0.041;
deathRate = 0.114;
} else if (ageRandPercent < 1) {
age = (int) (80 + Math.random() * 19);
infecFactorAge = 0.034;
deathRate = 0.413;
}
}
public double getDeathRate() {
return deathRate;
}
public void infectionChance() {
if(infecFactorMask) {
infecChance = infecFactorAge*maskEffect;
} else {
infecChance = infecFactorAge;
}
}
public boolean isAlive()
{
return alive;
}
public int getAge() {
return age;
}
public boolean setInfected() {
infecRand = (double) (Math.random() * 1);
infectionChance();
if (infecChance > infecRand) {
alive = false;
return true;
} else {
return false;
}
}
public void setLocation(int row, int col)
{
this.location = new Location(row, col);
}
public void setLocation(Location location)
{
this.location = location;
}
}