-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFlecha.java
More file actions
223 lines (134 loc) · 5.95 KB
/
Copy pathFlecha.java
File metadata and controls
223 lines (134 loc) · 5.95 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hilos;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.swing.Icon;
import javax.swing.JPanel;
/**
*
* @author abel
*/
public class Flecha extends Ser{
public Flecha(String especie,String audio,Icon imagenCria,Icon imagenAdulto,boolean hembra,JPanel panel,ArrayList colonia,
int esperanzadevida,int limiteedadreproduccion,int edadadulta,int limitedescendientes,
int traslacion,int hambre
)
{ super( especie,audio,imagenCria,imagenAdulto,hembra,panel,colonia,
esperanzadevida,limiteedadreproduccion,edadadulta,limitedescendientes,traslacion,hambre);
}
public Object clone(){
Flecha hor= new Flecha(especie,audio,imagenCria,imagenAdulto,hembra,panel,colonia,
esperanzadevida,limiteedadreproduccion,edadadulta,limitedescendientes,traslacion,hambre);
hor.x+=10-(int)random.nextFloat()*20;
hor.y+=10-(int)random.nextFloat()*20;
return hor;
}
public void alimentate(Ser otro){
if ((otro instanceof Herbivoro
||
otro instanceof Carnivoro
||
otro instanceof Omnivoro)
)
{ otro.muere(); muere();
panel.validate();
try{
AudioInputStream audio2 = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/audios/flecha.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audio2);
clip.start();
}catch(Exception ex){ex.printStackTrace();}
for(int i=0;i<colonia.size();i++)
{if (colonia.get(i) instanceof Jugador)
{((Jugador)colonia.get(i)).caza=((Jugador)colonia.get(i)).caza+1;
((Jugador)colonia.get(i)).puntos=((Jugador)colonia.get(i)).puntos+20;
}
}
}
}
public void reproducete(Ser otro){;}
public void arrastre(java.awt.event.MouseEvent evt){;}
public void inicializar(){;}
public void camina(){
if (timer!=null) timer.cancel();
timer=new Timer();
if (timer1!=null) timer1.cancel();
timer1=new Timer();
if (direccion!=null) direccion.cancel();
direccion=new Timer();
TimerTask timerTask = new TimerTask() {public void run() {try {
desarrollo();
} catch (InterruptedException ex) {
Logger.getLogger(Ser.class.getName()).log(Level.SEVERE, null, ex);
}
}
// Aquí el código que queremos ejecutar.
};
TimerTask timerTask1 = new TimerTask() {public void run() {HAMBRE=true;}
// Aquí el código que queremos ejecutar.
};
TimerTask timerTask2 = new TimerTask() {public void run() {;}
// Aquí el código que queremos ejecutar.
};
timer.scheduleAtFixedRate(timerTask, 0,10);
timer1.scheduleAtFixedRate(timerTask1, 0,1);
direccion.scheduleAtFixedRate(timerTask2, 0,500+(int)random.nextFloat()*500);
}
public boolean esAdulto(){return(true) ;}
public boolean esHembra(){return(true) ;}
public boolean especie(Ser otro){return false;}
public void muere() {
colonia.remove(this);
panel.remove(label);
label.setVisible(false);
if (timer!=null)timer.cancel();
if (timer1!=null) timer1.cancel();
if(direccion!=null) direccion.cancel();
panel.validate();
try {
finalize();
} catch (Throwable ex) {
Logger.getLogger(Ser.class.getName()).log(Level.SEVERE, null, ex);
}
}
public boolean hacinado(){
if (colonia.size()>0&&panel.getWidth()/colonia.size()<30)
{ return true; }
else return false;
}
public void desarrollo() throws InterruptedException{
int rx=(int)(random.nextFloat()*traslacion);
int ry=(int)(random.nextFloat()*traslacion);
x+=rx*fx;
y+=ry*fy;
for(int i=0;i<colonia.size();i++)
{Ser aux=(Ser)colonia.get(i);
if (Math.abs(x-aux.x)<40&& Math.abs(y-aux.y)<40
){
rx=traslacion;
// ry=traslacion;
fx=(hembra)?1:-1;
x+=rx*fx;
//y+=ry*fy;
alimentate(aux);
}
}
if (x>panel.getWidth()-label.getWidth()) {muere();}
if (x<0 ) {muere();}
if (y>panel.getHeight()-label.getHeight()) {muere(); }
if (y<0) {muere();}
panel.add(label, new org.netbeans.lib.awtextra.AbsoluteConstraints(x,y,-1,-1));
panel.repaint();
panel.validate();
}
}