-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDecomposer.java
176 lines (170 loc) · 3.57 KB
/
Decomposer.java
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package Projects;
public class Decomposer {
public int xAxis;
public int yAxis;
public int xSize;
public int ySize;
public int nuts;
public boolean life;
public Life lifeClass;
CircleComparer c = new CircleComparer();
public boolean eating = false;
public Decomposer(Life lifeClass) {
this.lifeClass = lifeClass;
xAxis = (int)(Math.random() * 485);
yAxis = (int)(Math.random() * 485);
xSize = 2;
ySize = xSize;
nuts = 1;
life = true;
}
public Decomposer(int x, int y, int a, int b, Life life1) {
xAxis = x;
yAxis = y;
xSize = a;
ySize = b;
nuts = 1;
lifeClass = life1;
life = true;
}
public void behavior() {
if(reproduce()) {
}
else{
if(!eating) {
movement();
eatTest();
}
else {
eatTest();
}
}
}
private void movement() {
double xTest = Math.random();
double yTest = Math.random();
if (xAxis <= 0) {
xAxis+=1;
}
else if (xAxis >= 500) {
xAxis-=1;
}
else {
if (xTest > 0.5) {
xAxis +=1;
}
else {
xAxis-=1;
}
}
if (yAxis <= 0) {
yAxis+=1;
}
else if (yAxis >= 500) {
yAxis-=1;
}
else {
if (yTest > 0.5) {
yAxis +=1;
}
else {
yAxis-=1;
}
}
}
private void eatTest() {
for(int j = 0; j < lifeClass.herbStore.size(); j++) {
if(c.compare(xAxis, yAxis, xSize, lifeClass.herbStore.get(j).getxAxis(), lifeClass.herbStore.get(j).getyAxis(), lifeClass.herbStore.get(j).getxSize())) {
if(lifeClass.herbStore.get(j).isLife() == false) {
//eating = true;
eat(lifeClass.herbStore.get(j), j);
}
}
}
for(int j = 0; j < lifeClass.predStore.size(); j++) {
if(c.compare(xAxis, yAxis, xSize, lifeClass.predStore.get(j).getxAxis(), lifeClass.predStore.get(j).getyAxis(), lifeClass.predStore.get(j).getxSize())) {
if(lifeClass.predStore.get(j).isLife() == false) {
//eating = true;
eat(lifeClass.predStore.get(j), j);
}
}
}
}
private void eat(Predator p, int j) {
/* if(lifeClass.predStore.get(j).getNuts() > 0) {
nuts += 5;
lifeClass.predStore.get(j).setNuts((lifeClass.predStore.get(j).getNuts() - 5));
}
else{
lifeClass.predStore.remove(j);
eating = false;
}*/
nuts += lifeClass.predStore.get(j).getNuts();
lifeClass.predStore.remove(j);
}
private void eat(Herbivore p, int j) {
/* if(lifeClass.herbStore.get(j).getNuts() > 0) {
nuts += 5;
lifeClass.herbStore.get(j).setNuts((lifeClass.herbStore.get(j).getNuts() - 5));
System.out.print(lifeClass.herbStore.get(j).getNuts());
}
else{
lifeClass.herbStore.remove(j);
eating = false;
}*/
nuts += lifeClass.herbStore.get(j).getNuts();
lifeClass.herbStore.remove(j);
}
private boolean reproduce() {
if (nuts > 20) {
Decomposer d = new Decomposer(xAxis, yAxis, xSize, ySize, lifeClass);
d.populate(d);
nuts -= 5;
return true;
}
return false;
}
public void populate(Decomposer d) {
lifeClass.decoStore.add(d);
// print();
}
public void print(){
System.out.println("x: " + xAxis + " " + "y: " + yAxis);
}
public int getxAxis() {
return xAxis;
}
public void setxAxis(int xAxis) {
this.xAxis = xAxis;
}
public int getyAxis() {
return yAxis;
}
public void setyAxis(int yAxis) {
this.yAxis = yAxis;
}
public int getxSize() {
return xSize;
}
public void setxSize(int xSize) {
this.xSize = xSize;
}
public int getySize() {
return ySize;
}
public void setySize(int ySize) {
this.ySize = ySize;
}
public int getNuts() {
return nuts;
}
public void setNuts(int nuts) {
this.nuts = nuts;
}
public boolean isLife() {
return life;
}
public void setLife(boolean life) {
this.life = life;
}
}