-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPrey.java
More file actions
175 lines (146 loc) · 4.66 KB
/
Prey.java
File metadata and controls
175 lines (146 loc) · 4.66 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
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
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
public class Prey {
BufferedImage imgPrey;
int x, y;
int en, boy;
boolean oldu = false;
public Prey() {
try {
imgPrey = ImageIO.read(getClass().getResource("img/bird.png"));
x = 0;
y = 0;
} catch (Exception ex) {
}
}
public Prey(BufferedImage imgPrey, int x, int y) {
this.imgPrey = imgPrey;
this.x = x;
this.y = y;
}
public Prey(BufferedImage imgPrey, int x, int y, int en, int boy) {
this.imgPrey = imgPrey;
this.x = x;
this.y = y;
this.en = en;
this.boy = boy;
}
public void escape(Hunter[] hunters, int en, int boy) {
if (!oldu) {
for (Hunter hunter : hunters) {
if (x == hunter.x && y == hunter.y) {
oldu = true;
x = -100;
y = -100;
return;
}
}
int yon = 0;
int max = 0;
int temp = 0;
if (x > 0) {
temp = 0;
for (Hunter hunter : hunters) {
if (Math.abs(x - hunter.x) < 3 && Math.abs(y - hunter.y) < 3) {
temp += (int) Math.abs((x - 1) - hunter.x) + (int) Math.abs(y - hunter.y);
}
}
// System.out.println("Temp : " + temp + " Max : " + max + " Yon : " + yon);
if (temp > max) {
max = temp;
yon = 4;
}
}
if (x < en - 1) {
temp = 0;
for (Hunter hunter : hunters) {
if (Math.abs(x - hunter.x) < 3 && Math.abs(y - hunter.y) < 3) {
temp += (int) Math.abs((x + 1) - hunter.x) + (int) Math.abs(y - hunter.y);
}
}
// System.out.println("Temp : " + temp + " Max : " + max + " Yon : " + yon);
if (temp > max) {
max = temp;
yon = 2;
}
}
if (y > 0) {
temp = 0;
for (Hunter hunter : hunters) {
if (Math.abs(x - hunter.x) < 3 && Math.abs(y - hunter.y) < 3) {
temp += (int) Math.abs(x - hunter.x) + (int) Math.abs((y - 1) - hunter.y);
}
}
// System.out.println("Temp : " + temp + " Max : " + max + " Yon : " + yon);
if (temp > max) {
max = temp;
yon = 1;
}
}
if (y < boy - 1) {
temp = 0;
for (Hunter hunter : hunters) {
if (Math.abs(x - hunter.x) < 3 && Math.abs(y - hunter.y) < 3) {
temp += (int) Math.abs(x - hunter.x) + (int) Math.abs((y + 1) - hunter.y);
}
}
// System.out.println("Temp : " + temp + " Max : " + max + " Yon : " + yon);
if (temp > max) {
max = temp;
yon = 3;
}
}
temp = 0;
for (Hunter hunter : hunters) {
if (Math.abs(x - hunter.x) < 3 && Math.abs(y - hunter.y) < 3) {
temp += (int) Math.abs(x - hunter.x) + (int) Math.abs((y) - hunter.y);
}
}
if (temp > max) {
max = temp;
yon = 0;
}
switch (yon) {
case 1:
y--;
// moveUp();
break;
case 2:
x++;
// moveRight();
break;
case 3:
y++;
// moveDown();
break;
case 4:
x--;
// moveLeft();
break;
default:
break;
}
// System.out.println("Av yön : " + yon);
// System.out.println("sonraki : x:" + x + "y:" + y);
}
}
public void oldur() {
oldu = true;
}
public void moveRight() {
x = (x < en) ? x++ : x;
}
public void moveLeft() {
// System.out.println("Sola git laann!!");
x = (x > 0) ? x-- : x;
System.out.println("x:" + x);
}
public void moveUp() {
y = (y > 0) ? y-- : y;
}
public void moveDown() {
y = (y < boy) ? y++ : y;
}
public void moveNot() {
}
}