-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lion.java
74 lines (66 loc) · 1.24 KB
/
Lion.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
import java.util.*;
/**
* @author abhin
* This is a Lion class which is a type of Feline which is a type of Animal
*/
public class Lion extends Feline {
/**
* @param r is the row position of the Lion object
* @param c is the column position of the Lion object
* @param ch is the id of the Lion object
* This is a parameterized constructor
*/
public Lion(int r, int c, char ch) {
super(r, c, ch);
}
/* (non-Javadoc)
* @see Feline#attack(Animal)
*/
protected boolean attack(Animal a) {
char ch = a.getid();
if (ch == 'd' || ch == 'f' || ch == 'w') {
return true;
}
if (ch == this.getid()) {
Random rand = new Random();
int rant = rand.nextInt(2);
switch (rant) {
case 1: {
return true;
}
case 0: {
return false;
}
default:
return false;
}
}
if (ch == 'u') {
Random ra = new Random();
int ran = ra.nextInt(5);
switch (ran) {
case 1: {
return true;
}
case 2: {
return false;
}
case 3: {
return false;
}
case 4: {
return false;
}
case 0: {
return false;
}
default:
return false;
}
}
if (ch == 'h')
return true;
else
return false;
}
}