-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCharacter.java
310 lines (265 loc) · 7.67 KB
/
Character.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
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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
/**
* This class stores the details for each character present on the battle field. Also, simultates the
* life span of each individual.
*
* @author Maria Roxana Luca
* @version 1.0
*/
import javax.swing.JProgressBar;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public abstract class Character extends Element implements Runnable
{
private int agility; //attribute that grants Armor and Attack Speed
private double intelligence; //for creating spells
private double strength; //grants heath and heath regeneration
protected static int LEFTMOVE = 20;
protected static int RIGHTMOVE = 20;
protected static int UPMOVE = 20;
protected static int DOWNMOVE = 20;
boolean areFeatures = true;
/*
* Constructor for objects of class Character
*/
public Character(String name)
{
super(name);
setAgility();
setIntelligence();
setStrength();
}
public Character(String name, Boolean ok)
{
super(name,ok);
setAgility();
setIntelligence();
setStrength();
}
/*
* Constructor for objects of class Character with additional information about character
* (agility, intelligence, strength)
*/
public Character(String name,int agility,double intelligence,double strength)
{
super(name);
setAgility(agility);
setIntelligence(intelligence);
setStrength(strength);
}
/*
* Constructor for objects of class Character that copies the information from an object of
* Character-type
*/
public Character(Character c)
{
super(c.getName());
setAgility(c.getAgility());
setIntelligence(c.getIntelligence());
setStrength (c.getStrength());
}
/*
* Constructor for objects of class Character that have a fixed location on the screen
*/
public Character(String name,int x,int y)
{
super(name,x,y);
setAgility();
setIntelligence();
setStrength();
}
/*
* Setter method for agility of the character
*
* @param agility the decimal number that represents the reaction of the character according to
* environment: defence or offence
* @return none
*/
public void setAgility(int agility)
{
this.agility = agility;
}
public void setAgility()
{
this.agility = 500;
}
/*
* Setter method for intelligence of the character
*
* @param intelligence the decimal number that represents how much imagination should have the
* character at some point in game to launch one spell from magic object
* @return none
*/
public void setIntelligence(double intelligence)
{
this.intelligence = intelligence;
}
public void setIntelligence()
{
this.intelligence = 0;
}
/*
* Setter method for the strength of the character
*
* @param strength the decimal number that represents how much the magic objects put up any
* resistent to incoming damage
* @return none
*/
public void setStrength(double strength)
{
this.strength = strength;
}
public void setStrength()
{
this.strength = 100;
}
/*
* Getter method for agility of the character
*
* @param none
* @return the decimal number that represents the reaction of the character according to
* çenvironment: defence or offence
*/
public int getAgility()
{
return this.agility;
}
/*
* Getter method for intelligence of the character
*
* @param none
* @return the decimal number that represents how much imagination should have the character at
* some point in game to launch one spell from magic object
*/
public double getIntelligence()
{
return this.intelligence;
}
/*
* Getter method for strength of the character
*
* @param none
* @return the decimal number that represents how much the magic objects put up any
* resistent to incoming damage
*/
public double getStrength()
{
return this.strength;
}
/*
* This method builds one line of text about one character.
*
* @param none
* @return one string with overall information of the character
*/
public String toString()
{
return this.getName() +": "+ super.toString()+" agility - " + this.getAgility() + " intelligence - "
+ this.getIntelligence() + " strength - " + this.getStrength();
}
/*
* This method performs the movement of the character. All exceptions about the movement of the character
* are mentioned.
*
* @param none
* @return none
*/
public void run()
{
try{
this.movement();
}
catch (ArrayIndexOutOfBoundsException e)
{
e.printStackTrace();
System.out.println(e + " The character is unable to perform movement.");
Element.stopForWhile(200);
}
catch (NullPointerException e)
{
System.out.println(e + " The character is unable to perform movement.");
System.exit(0);
}
}
/*
* This method represents the algorithm that controls the movement of this character
*
* @param none
* @return none
*/
public abstract void movement();
/*
* This method moves the character to the left side.
*
* @param none
* @return none
*/
public void makeStepLeft()
{
if (getStartX() > LEFTMOVE)
moveBy(-LEFTMOVE,0,agility);
}
/*
* This method moves the character to the up side.
*
* @param none
* @return none
*/
public void makeStepUp()
{
if (getStartY() > UPMOVE)
moveBy(0,-UPMOVE,agility);
}
/*
* This method moves the character to the down side.
*
* @param none
* @return none
*/
public void makeStepDown()
{
if (getEndY() + DOWNMOVE < getBoundDown())
moveBy(0,DOWNMOVE,agility);
}
/*
* This method moves the character to the right side.
*
* @param none
* @return none
*/
public void makeStepRight()
{
if (getEndX() + RIGHTMOVE < getBoundRight())
moveBy(RIGHTMOVE,0,agility);
}
/*
* This method shows the entire details of the character on the screen. Notice that the
* position of the features is determinated according to the character appearance shown by the
* first element of the group(type ViewImage).
*
* @param none
* @return none
*/
public void draw(Graphics2D g,JPanel jp)
{
super.draw(g,jp);
if (areFeatures)
{
int width = (int) Math.round(strength*imageWidth/100);
g.drawRect(getStartX(),getEndY()+5,width,5);
}
}
/*
* This method decrese the life span of the character. It can be trigger by magicobject. Also, Adjusts
* the progress bar of the character.
*
* @param double - the intensitive of negative power over the character
* @return none
*/
public void decreaseStrength(double points)
{
if (strength > points)
strength -= points;
else
strength = 0;
}
}