-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTank.java
104 lines (84 loc) · 1.95 KB
/
Tank.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import java.text.BreakIterator;
public class Tank {
private int x;
private int y;
private int health; // 0 to 10
private int damage; // 5 to 10
private int xSpeed;
private int ySpeed;
private int shells;
public Tank() {
this.x = 0;
this.y = 0;
this.health = 10;
this.damage = 3;
this.xSpeed = 0;
this.ySpeed = 0;
this.shells = 5;
}
public Tank(int x, int y, int health, int damage, int xSpeed, int ySpeed, int shells) {
this.x = x;
this.y = y;
this.health = health;
this.damage = damage;
this.xSpeed = xSpeed;
this.ySpeed = ySpeed;
this.shells = shells;
}
public void setPosition(int newX, int newY) {
this.x = newX;
this.y = newY;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public int getHealth() {
return health;
}
public void setHealth(int health) {
this.health = health;
}
public int getDamage() {
return damage;
}
public void setDamage(int damage) {
this.damage = damage;
}
public int getxSpeed() {
return xSpeed;
}
public void setxSpeed(int xSpeed) {
this.xSpeed = xSpeed;
}
public int getySpeed() {
return ySpeed;
}
public int getShells() {
return shells;
}
public void setySpeed(int ySpeed) {
this.ySpeed = ySpeed;
}
public String toString() {
return "x: " + this.x + " y: " + this.y + " health: " + this.health + " damage: " + this.damage + " xSpeed: "
+ this.xSpeed + " ySpeed: " + this.ySpeed + " shells: " + this.shells;
}
public void shoot(Tank t) {
t.health -= this.damage;
t.shells -= 1;
System.out.println(
"Tank " + this.x + ", " + this.y + " shoots tank " + t.x + ", " + t.y + " for " + this.damage + " damage.");
if (t.health <= 0) {
System.out.println("Tank " + t.x + ", " + t.y + " is destroyed.");
}
}
}