-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnit.java
More file actions
184 lines (163 loc) · 4.12 KB
/
Unit.java
File metadata and controls
184 lines (163 loc) · 4.12 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
/*******************************************************************************
* Copyright (C) 2019-2020 ROMAINPC
* Copyright (C) 2019-2020 Picachoc
*
* This file is part of PICROM-Wars
*
* PICROM-Wars is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PICROM-Wars is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package picrom.entity.unit;
import picrom.entity.Entity;
import picrom.entity.castle.Castle;
import picrom.entity.castle.Producible;
import picrom.utils.Drawables.EntityAssets;
/**
* Units are mainly military units. They can be produced in Castles and sended
* on the battleground.
*
* Once launched they have a Castle target.
*
* An Unit is characterized by an amount of health-points, an amount of damage
* it can inflict and a speed of movement.
*
* @see picrom.entity.castle.ProductionUnit
*/
public class Unit extends Entity implements Producible {
private int speed, hp, damage;
private String name;
private int productionCost, productionTime;
private Castle origin;
private Castle objective;
/**
* Create new Unit
*
* @param img Image and mask Image, see
* {@link picrom.utils.Drawables.EntityAssets}
* @param name String, the name of the type of Unit
* @param prodCost Money cost to produce it
* @param prodTime Number of turn needed to produce it
* @param speed Speed of movment per turn
* @param hp Health points
* @param damage Damage potential
* @param origin owner Castle
*/
public Unit(EntityAssets img, String name, int prodCost, int prodTime, int speed, int hp, int damage,
Castle origin) {
super(img, origin);
this.speed = speed;
this.hp = hp;
this.damage = damage;
this.name = name;
this.productionCost = prodCost;
this.productionTime = prodTime;
objective = null;
}
/**
* @return Unit speed
*/
public int getSpeed() {
return speed;
}
/**
* Set unit speed
*
* @param speed new speed
*/
public void setSpeed(int speed) {
this.speed = speed;
}
/**
* @return Unit health points
*/
public int getHp() {
return hp;
}
/**
* Set Unit health points
*
* @param hp new amount of points
*/
public void setHp(int hp) {
this.hp = hp;
}
/**
* @return Unit damage potential
*/
public int getDamage() {
return damage;
}
/**
* Set Unit damage potential
*
* @param damage new amount of damages
*/
public void setDamage(int damage) {
this.damage = damage;
}
/**
* @return Name of the type of the Unit
*/
public String getName() {
return name;
}
/**
* Add the produced Unit to the garrison of the following Castle.
*
* @param c Castle
*/
public void produce(Castle c) {
c.enterUnit(this);
}
@Override
public int getProductionCost() {
return productionCost;
}
@Override
public int getProductionTime() {
return productionTime;
}
/**
* @return Target Castle of the Unit.
*/
public Castle getObjective() {
return objective;
}
/**
* Set target Castle of the Unit.
*
* @param objective new objective
*/
public void setObjective(Castle objective) {
this.objective = objective;
}
/**
* @return Last Castle were was the Unit.
*/
public Castle getOrigin() {
return origin;
}
/**
* Set origin Castle of the Unit (last Castle were was the Unit to be exact)
*
* @param origin new origin
*/
public void setOrigin(Castle origin) {
this.origin = origin;
}
@Override
public String toString() {
return getClass() + " (" + getWorldX() + ", " + getWorldY() + "), Owner: " + getOwner() + ", (" + speed + ", "
+ hp + ", " + damage + ")";
}
}