1 import java.awt.*;
2 import java.applet.*;
3 import javax.swing.*;
4 import java.awt.image.*;
5 import java.awt.geom.*;
6 import java.net.*;
7 import java.util.*;
8
14 public class Player extends People
15 {
16
19 protected static Image img, bimg, limg, rimg;
23 Vector badges;
24
25
38 public Player()
39 {
40 enterable = false;
41 type = MapObject.PLAYER;
42 activeMon = 0;
43 money = 0;
44 behind = new Grass();
45 name = "Player1";
46 mon = new Vector();
47 hmon = new Vector();
48 items = new Vector();
49 badges = new Vector();
50 }
51
66 public Player(int dir)
67 {
68 if(!setDirection(dir))
69 this.dir = Grid.DOWN;
70 enterable = false;
71 type = MapObject.PLAYER;
72 activeMon = 0;
73 money = 0;
74 behind = new Grass();
75 name = "Player1";
76 mon = new Vector();
77 hmon = new Vector();
78 items = new Vector();
79 badges = new Vector();
80 }
81
95 public Player(MapObject behind)
96 {
97 if(behind.canBeEntered())
98 this.behind = behind;
99 else
100 this.behind = new Grass();
101 enterable = false;
102 type = MapObject.PLAYER;
103 activeMon = 0;
104 money = 0;
105 name = "Player1";
106 mon = new Vector();
107 hmon = new Vector();
108 items = new Vector();
109 badges = new Vector();
110 }
111
127 public Player(MapObject behind, int dir)
128 {
129 if(!setDirection(dir))
130 this.dir = Grid.DOWN;
131 if(behind.canBeEntered())
132 this.behind = behind;
133 else
134 this.behind = new Grass();
135 enterable = false;
136 type = MapObject.PLAYER;
137 activeMon = 0;
138 money = 0;
139 name = "Player1";
140 mon = new Vector();
141 hmon = new Vector();
142 items = new Vector();
143 badges = new Vector();
144 }
145
159 public Player(String name)
160 {
161 this.dir = Grid.DOWN;
162 this.behind = new Grass();
163 enterable = false;
164 type = MapObject.PLAYER;
165 activeMon = 0;
166 money = 0;
167 this.name = name;
168 mon = new Vector();
169 hmon = new Vector();
170 items = new Vector();
171 badges = new Vector();
172 }
173
190 public Player(String name, MapObject behind, int dir)
191 {
192 if(!setDirection(dir))
193 this.dir = Grid.DOWN;
194 if(behind.canBeEntered())
195 this.behind = behind;
196 else
197 this.behind = new Grass();
198 enterable = false;
199 type = MapObject.PLAYER;
200 activeMon = 0;
201 money = 0;
202 this.name = name;
203 mon = new Vector();
204 hmon = new Vector();
205 items = new Vector();
206 badges = new Vector();
207 }
208
214 public void setImage(Image[] img)
215 {
216 if(img.length == 4)
217 {
218 this.img = img[0];
219 this.bimg = img[1];
220 this.limg = img[2];
221 this.rimg = img[3];
222 }
223 }
224
230 public boolean hasBadge(String badge)
231 {
232 if(badge == null)
233 return false;
234 for(int i = 0; i < badges.size(); i++)
235 {
236 if(((String)badges.get(i)).equalsIgnoreCase(badge))
237 {
238 System.out.println((String)badges.get(i) + " || " + badge);
239 return true;
240 }
241 }
242 return false;
243 }
244
250 public void addBadge(String badge)
251 {
252 if(badge == null)
253 return;
254 if(!hasBadge(badge))
255 badges.add(badge);
256 }
257
262 public int getBadgeCount() { return badges.size(); }
263
268 public MapObject getClone() { return new Player(); }
269
274 public void paint(Graphics g)
275 {
276 behind.paint(g);
277
278 int wi, he;
279 switch(dir)
280 {
281 case Grid.LEFT:
282 {
283 g.drawImage(limg, 0, 0, this);
284 break;
285 }
286 case Grid.RIGHT:
287 {
288 g.drawImage(rimg, 0, 0, this);
289 break;
290 }
291 case Grid.UP:
292 {
293 g.drawImage(bimg, 0, 0, this);
294 break;
295 }
296 default:
297 {
298 g.drawImage(img, 0, 0, this);
299 break;
300 }
301 }
302 }
303 }