-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCharacter.java
More file actions
231 lines (192 loc) · 7.48 KB
/
Character.java
File metadata and controls
231 lines (192 loc) · 7.48 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
import java.io.Serializable;
public class Character implements Serializable {
private String name;
private int price;
protected int pos; // position in army (List)
private double attack, defence, health, speed;
private Equipment armour;
private Equipment artefact;
public Character(String name, int price, double attack, double defence, double health, double speed) {
// a common constructor
this.name = name;
this.price = price;
this.attack = attack;
this.defence = defence;
this.health = health;
this.speed = speed;
}
public void printInfo() {
if (this.equals(null)) {
System.out.println("Character Slot is empty!!!");
return;
}
System.out.printf("Name: %s\nPrice: %d Gold coins\nAttack: %.1f\nDefence: %.1f\nHealth: %.1f\nSpeed: %.1f\n",
name, price, attack, defence, health, speed);
// "Name: " + name + "\nPrice: " + price + " gc\nAttack: " + attack
// + "\nDefence: " + defence + "\nHealth: " + defence + "\nSpeed: " + speed
}
public void attackOpponent(Character op) { // attacking procedure is same for most of the characters
System.out.println(this.name+" attacks "+op.getName());
op.setHealth(op.getHealth() - (0.5 * this.getAttack() - 0.1*op.getDefence()));
if(op.getHealth()<=0){
op.setHealth(0);
}
System.out.println(op.getName()+"'s health: "+op.getHealth());
System.out.println(this.getName()+"'s health: "+this.getHealth());
}
public String getName() {
return this.name;
}
public void setAttack(double attack) {
this.attack = attack;
}
public double getAttack() {
return (double)Math.round(attack*10)/10;
}
public int getPrice() {
return price;
}
public void setPrice(int price) {
this.price = price;
}
public double getDefence() {
return defence;
}
public void setDefence(double defence) {
this.defence = defence;
}
public double getHealth() {
return health;
}
public void setHealth(double health) {
this.health = (double)Math.round(health*10)/10;
}
public double getSpeed() {
return speed;
}
public void setSpeed(double speed) {
this.speed = speed;
}
public Equipment getArmour() {
return armour;
}
public Equipment getArtefact() {
return artefact;
}
public boolean hasArmour() {
if (this.armour != null) {
return true;
}
return false;
}
public boolean hasArtefact() {
if (this.artefact != null) {
return true;
}
return false;
}
public int getPos() {
return this.pos;
}
public void setPos(int pos) {
this.pos = pos;
}
private void wearArmour(Equipment newArmour) {
this.armour = newArmour;
this.setPrice(this.getPrice() + (int) (0.2 * newArmour.getPrice()));
this.setAttack(this.getAttack() + newArmour.getAttack());
this.setDefence(this.getDefence() + newArmour.getDefence());
this.setHealth(this.getHealth() + newArmour.getHealth());
this.setSpeed(this.getSpeed() + newArmour.getSpeed());
}
private void equipArtefact(Equipment newArtefact) {
this.artefact = newArtefact;
this.setPrice(this.getPrice() + (int) (0.2 * newArtefact.getPrice()));
this.setAttack(this.getAttack() + newArtefact.getAttack());
this.setDefence(this.getDefence() + newArtefact.getDefence());
this.setHealth(this.getHealth() + newArtefact.getHealth());
this.setSpeed(this.getSpeed() + newArtefact.getSpeed());
}
private void removeArmour() {
this.setPrice(this.getPrice() - (int) (0.2 * this.armour.getPrice()));
this.setAttack(this.getAttack() - this.armour.getAttack());
this.setDefence(this.getDefence() - this.armour.getDefence());
this.setHealth(this.getHealth() - this.armour.getHealth());
this.setSpeed(this.getSpeed() - this.armour.getSpeed());
this.armour = null;
}
private void unequipArtefact() {
this.setPrice(this.getPrice() - (int) (0.2 * this.artefact.getPrice()));
this.setAttack(this.getAttack() - this.artefact.getAttack());
this.setDefence(this.getDefence() - this.artefact.getDefence());
this.setHealth(this.getHealth() - this.artefact.getHealth());
this.setSpeed(this.getSpeed() - this.artefact.getSpeed());
this.artefact = null;
}
public void changeArmour(Equipment newArmour) {
if (this.hasArmour()) {
this.removeArmour();
this.wearArmour(newArmour);
}
this.wearArmour(newArmour);
return;
}
public void changeEquipment(Equipment newArtefact) {
if (hasArtefact()) {
this.unequipArtefact();
this.equipArtefact(newArtefact);
}
this.equipArtefact(newArtefact);
return;
}
// differentiating characters accordingto the homegrounds
// public static Character[] highLanders = { Character.shooter,
// Character.ranger, Character.cavalier,
// Character.enchanter, Character.zoro, Character.conjurer, Character.medic };
// public static Character[] marshlanders = { Character.squire,
// Character.swiftblade, Character.warlock,
// Character.alchemist, Character.basilisk, Character.hydra };
// public static Character[] sunchildren = { Character.sunfire, Character.zing,
// Character.templar, Character.soother,
// Character.lightbringer, Character.dragon, Character.phoenix };
// public static Character[] mystics = { Character.saggitarius,
// Character.illusionist, Character.eldritch,
// Character.saint, Character.pegasus };
}
class Archer extends Character {
public Archer(String name, int price, double attack, double defence, double health, double speed) {
super(name, price, attack, defence, health, speed);
setPos(0);
}
}
class Knight extends Character {
public Knight(String name, int price, float attack, float defence, float health, float speed) {
super(name, price, attack, defence, health, speed);
setPos(1);
}
}
class Mage extends Character {
public Mage(String name, int price, float attack, float defence, float health, float speed) {
super(name, price, attack, defence, health, speed);
setPos(2);
}
}
class MythicalCreature extends Character {
public MythicalCreature(String name, int price, float attack, float defence, float health, float speed) {
super(name, price, attack, defence, health, speed);
setPos(3);
}
}
class Healer extends Character {
public Healer(String name, int price, float attack, float defence, float health, float speed) {
super(name, price, attack, defence, health, speed);
setPos(4);
}
@Override
public void attackOpponent(Character ally) {
System.out.println(this.getName()+" heals "+ally.getName());
ally.setHealth(ally.getHealth()+0.1 * this.getAttack());
System.out.println(ally.getName()+"'s health: "+ally.getHealth());
System.out.println(this.getName()+"'s health: "+this.getHealth());
}
}