-
Notifications
You must be signed in to change notification settings - Fork 0
/
Link.java
66 lines (47 loc) · 1.38 KB
/
Link.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
package assignment5;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import assignment5.Critter.CritterShape;
public class Link extends Critter {
private int dir;
private boolean hasMoved;
@Override
public String toString() { return "2"; }
public Link() {
dir = Critter.getRandomInt(2);
}
public boolean fight(String opponent) {
if (!hasMoved) {
if (opponent.equals("project5. Link")) { walk(dir); return false; }
}
return true;
}
@Override
public void doTimeStep() {
walk(dir);
hasMoved = true;
int new_dir = Critter.getRandomInt(2);
switch(new_dir) {
case 0:
dir = 2;
case 1:
dir = 6;
}
try {
AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("src/assignment5/WW_Link_PowerAttack1.wav").getAbsoluteFile());
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
} catch(Exception ex) {
System.out.println("Error with playing sound.");
ex.printStackTrace();
}
}
@Override
public CritterShape viewShape() {
return CritterShape.TRIANGLE;
}
public javafx.scene.paint.Color viewColor() { return javafx.scene.paint.Color.CHARTREUSE; }
}