-
Notifications
You must be signed in to change notification settings - Fork 0
/
Shot.java
89 lines (76 loc) · 2.51 KB
/
Shot.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
public class Shot extends Game {
public int HandBomb(int x, int y, int i) {
int type = -1;
if (worldgrid.getPointWorld(y, x + i) >= 2) // -1 free
{
type = worldgrid.getPointWorld(y, x + i); // get type ships
}
if (type == -1) {
worldgrid.setPointWorld(y, x + i, -1); // missed shot
} else {
worldgrid.setPointWorld(y, x + i, 1); // shot
}
return type;
}
public void HeadShot(int weapon, int square, int x, int y) {
/* type 0 = free,1 = shot,2 >= ships active */
int type = -1;
for (int i = 0; i < square; i++) {
type = -1;
if (x + i >= 10 && y + i >= 10) {
continue;
}
if (weapon == 1) { //rocket
if (x == 0 && i - 1 < 0) {
continue;
}
if (type == -1) {
type = HandBomb(x, y, i - 1);
} else {
HandBomb(x, y, i - 1);
}
} else if (weapon == 2) { // gun shot
if (x == 0 && i - 1 < 0) {
continue;
}
if (type == -1) {
type = HandBomb(x, y, i);
} else {
HandBomb(x, y, i);
}
} else if (weapon == 0) // rocket
{
if (type == -1) {
type = HandBomb(x - 1, y, 0);
} else {
HandBomb(x - 1, y, 0);
}
if (type == -1) {
type = HandBomb(x, y, 0);
} else {
HandBomb(x, y, 0);
}
if (type == -1) {
type = HandBomb(x + 1, y, 0);
} else {
HandBomb(x + 1, y, 0);
}
if (type == -1) {
type = HandBomb(x, y + 1, 0);
} else {
HandBomb(x, y + 1, 0);
}
if (type == -1) {
type = HandBomb(x, y - 1, 0);
} else {
HandBomb(x, y - 1, 0);
}
break;
}
}
equipment.setDecrease(weapon);
if (type > -1) {
System.out.println("You just sank a " + ship.getType(type));
}
}
}