diff options
Diffstat (limited to 'src/com/fourisland/fourpuzzle/database/GameCharacters.java')
-rwxr-xr-x | src/com/fourisland/fourpuzzle/database/GameCharacters.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/com/fourisland/fourpuzzle/database/GameCharacters.java b/src/com/fourisland/fourpuzzle/database/GameCharacters.java new file mode 100755 index 0000000..bcd533a --- /dev/null +++ b/src/com/fourisland/fourpuzzle/database/GameCharacters.java | |||
@@ -0,0 +1,72 @@ | |||
1 | /* | ||
2 | * To change this template, choose Tools | Templates | ||
3 | * and open the template in the editor. | ||
4 | */ | ||
5 | |||
6 | package com.fourisland.fourpuzzle.database; | ||
7 | |||
8 | import com.fourisland.fourpuzzle.*; | ||
9 | import com.fourisland.fourpuzzle.gamestate.GameOverGameState; | ||
10 | import java.util.ArrayList; | ||
11 | |||
12 | /** | ||
13 | * | ||
14 | * @author hatkirby | ||
15 | */ | ||
16 | public class GameCharacters extends ArrayList<GameCharacter> | ||
17 | { | ||
18 | private GameCharacters() {} | ||
19 | |||
20 | private static GameCharacters INSTANCE = new GameCharacters(); | ||
21 | static GameCharacters getDefaultParty() | ||
22 | { | ||
23 | return INSTANCE; | ||
24 | } | ||
25 | |||
26 | static GameCharacters createParty() | ||
27 | { | ||
28 | GameCharacters temp = new GameCharacters(); | ||
29 | temp.addAll(INSTANCE); | ||
30 | |||
31 | return temp; | ||
32 | } | ||
33 | |||
34 | public GameCharacter getLeader() | ||
35 | { | ||
36 | for (GameCharacter chara : this) | ||
37 | { | ||
38 | if (chara.isInParty()) | ||
39 | { | ||
40 | return chara; | ||
41 | } | ||
42 | } | ||
43 | |||
44 | Game.setGameState(new GameOverGameState()); | ||
45 | return null; | ||
46 | } | ||
47 | |||
48 | public boolean exists(String heroName) { | ||
49 | for (GameCharacter chara : this) | ||
50 | { | ||
51 | if (chara.getName().equals(heroName)) | ||
52 | { | ||
53 | return true; | ||
54 | } | ||
55 | } | ||
56 | |||
57 | return false; | ||
58 | } | ||
59 | |||
60 | public GameCharacter get(String heroName) throws NullPointerException { | ||
61 | for (GameCharacter chara : this) | ||
62 | { | ||
63 | if (chara.getName().equals(heroName)) | ||
64 | { | ||
65 | return chara; | ||
66 | } | ||
67 | } | ||
68 | |||
69 | throw new NullPointerException("Could not find character \"" + heroName + "\""); | ||
70 | } | ||
71 | |||
72 | } | ||