diff options
| author | Starla Insigna <hatkirby@fourisland.com> | 2009-01-24 14:37:02 -0500 |
|---|---|---|
| committer | Starla Insigna <hatkirby@fourisland.com> | 2009-01-24 14:37:02 -0500 |
| commit | a581d9b4136bb633771e5e881bbee5a36247b0e0 (patch) | |
| tree | 54578b8b841fb7d15678c9f4062418f10d4d3ffe /src/com | |
| parent | 80fd704e66e98d70e98da977b01568b7813d80e9 (diff) | |
| download | fourpuzzle-a581d9b4136bb633771e5e881bbee5a36247b0e0.tar.gz fourpuzzle-a581d9b4136bb633771e5e881bbee5a36247b0e0.tar.bz2 fourpuzzle-a581d9b4136bb633771e5e881bbee5a36247b0e0.zip | |
Extended GameCharacters from ArrayList
Diffstat (limited to 'src/com')
| -rw-r--r-- | src/com/fourisland/fourpuzzle/Audio.java | 3 | ||||
| -rw-r--r-- | src/com/fourisland/fourpuzzle/GameCharacters.java | 48 | ||||
| -rw-r--r-- | src/com/fourisland/fourpuzzle/SaveFile.java | 2 | ||||
| -rw-r--r-- | src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | 31 |
4 files changed, 37 insertions, 47 deletions
| diff --git a/src/com/fourisland/fourpuzzle/Audio.java b/src/com/fourisland/fourpuzzle/Audio.java index 99d4207..39ce3d8 100644 --- a/src/com/fourisland/fourpuzzle/Audio.java +++ b/src/com/fourisland/fourpuzzle/Audio.java | |||
| @@ -8,7 +8,6 @@ package com.fourisland.fourpuzzle; | |||
| 8 | import com.fourisland.fourpuzzle.util.ObjectLoader; | 8 | import com.fourisland.fourpuzzle.util.ObjectLoader; |
| 9 | import javax.sound.midi.MidiSystem; | 9 | import javax.sound.midi.MidiSystem; |
| 10 | import javax.sound.midi.Sequencer; | 10 | import javax.sound.midi.Sequencer; |
| 11 | import javax.sound.midi.Track; | ||
| 12 | 11 | ||
| 13 | /** | 12 | /** |
| 14 | * | 13 | * |
| @@ -46,7 +45,7 @@ public class Audio { | |||
| 46 | } | 45 | } |
| 47 | 46 | ||
| 48 | public static void playMusic(String file, boolean loop, float speed) throws Exception | 47 | public static void playMusic(String file, boolean loop, float speed) throws Exception |
| 49 | { | 48 | { |
| 50 | seq.setSequence(ObjectLoader.getMusic(file)); | 49 | seq.setSequence(ObjectLoader.getMusic(file)); |
| 51 | 50 | ||
| 52 | if (loop) | 51 | if (loop) |
| diff --git a/src/com/fourisland/fourpuzzle/GameCharacters.java b/src/com/fourisland/fourpuzzle/GameCharacters.java index ef945c5..2a3b050 100644 --- a/src/com/fourisland/fourpuzzle/GameCharacters.java +++ b/src/com/fourisland/fourpuzzle/GameCharacters.java | |||
| @@ -12,45 +12,42 @@ import java.util.ArrayList; | |||
| 12 | * | 12 | * |
| 13 | * @author hatkirby | 13 | * @author hatkirby |
| 14 | */ | 14 | */ |
| 15 | public class GameCharacters implements Cloneable { | 15 | public class GameCharacters extends ArrayList<GameCharacter> |
| 16 | { | ||
| 17 | private GameCharacters() {} | ||
| 16 | 18 | ||
| 17 | private GameCharacters() | 19 | private static GameCharacters INSTANCE = new GameCharacters(); |
| 20 | public static GameCharacters getDefaultParty() | ||
| 18 | { | 21 | { |
| 22 | return INSTANCE; | ||
| 19 | } | 23 | } |
| 20 | |||
| 21 | public static GameCharacters INSTANCE = new GameCharacters(); | ||
| 22 | 24 | ||
| 23 | public void add(GameCharacter e) | 25 | public static GameCharacters createParty() |
| 24 | { | 26 | { |
| 25 | characters.add(e); | 27 | GameCharacters temp = new GameCharacters(); |
| 28 | temp.addAll(INSTANCE); | ||
| 29 | |||
| 30 | return temp; | ||
| 26 | } | 31 | } |
| 27 | 32 | ||
| 28 | public GameCharacter getLeader() throws Exception | 33 | public GameCharacter getLeader() throws Exception |
| 29 | { | 34 | { |
| 30 | int i = 0; | 35 | for (GameCharacter chara : this) |
| 31 | for (i=0;i<characters.size();i++) | ||
| 32 | { | 36 | { |
| 33 | if (characters.get(i).isInParty()) | 37 | if (chara.isInParty()) |
| 34 | { | 38 | { |
| 35 | return characters.get(i); | 39 | return chara; |
| 36 | } | 40 | } |
| 37 | } | 41 | } |
| 38 | 42 | ||
| 39 | Game.setGameState(new GameOverGameState()); | 43 | Game.setGameState(new GameOverGameState()); |
| 40 | throw new NoCharactersInPartyException(); | 44 | return null; |
| 41 | } | ||
| 42 | public GameCharacters newInstance() throws CloneNotSupportedException | ||
| 43 | { | ||
| 44 | return (GameCharacters) clone(); | ||
| 45 | } | 45 | } |
| 46 | |||
| 47 | private ArrayList<GameCharacter> characters = new ArrayList<GameCharacter>(); | ||
| 48 | 46 | ||
| 49 | public boolean exists(String heroName) { | 47 | public boolean exists(String heroName) { |
| 50 | int i=0; | 48 | for (GameCharacter chara : this) |
| 51 | for (i=0;i<characters.size();i++) | ||
| 52 | { | 49 | { |
| 53 | if (characters.get(i).getName().equals(heroName)) | 50 | if (chara.getName().equals(heroName)) |
| 54 | { | 51 | { |
| 55 | return true; | 52 | return true; |
| 56 | } | 53 | } |
| @@ -59,17 +56,12 @@ public class GameCharacters implements Cloneable { | |||
| 59 | return false; | 56 | return false; |
| 60 | } | 57 | } |
| 61 | 58 | ||
| 62 | public GameCharacter get(Integer get) { | ||
| 63 | return characters.get(get); | ||
| 64 | } | ||
| 65 | |||
| 66 | public GameCharacter get(String heroName) throws NullPointerException { | 59 | public GameCharacter get(String heroName) throws NullPointerException { |
| 67 | int i=0; | 60 | for (GameCharacter chara : this) |
| 68 | for (i=0;i<characters.size();i++) | ||
| 69 | { | 61 | { |
| 70 | if (characters.get(i).getName().equals(heroName)) | 62 | if (chara.getName().equals(heroName)) |
| 71 | { | 63 | { |
| 72 | return characters.get(i); | 64 | return chara; |
| 73 | } | 65 | } |
| 74 | } | 66 | } |
| 75 | 67 | ||
| diff --git a/src/com/fourisland/fourpuzzle/SaveFile.java b/src/com/fourisland/fourpuzzle/SaveFile.java index b4f2d68..27a5662 100644 --- a/src/com/fourisland/fourpuzzle/SaveFile.java +++ b/src/com/fourisland/fourpuzzle/SaveFile.java | |||
| @@ -26,7 +26,7 @@ public class SaveFile implements Serializable { | |||
| 26 | public SaveFile() throws CloneNotSupportedException | 26 | public SaveFile() throws CloneNotSupportedException |
| 27 | { | 27 | { |
| 28 | switches = new HashMap<String, Boolean>(); | 28 | switches = new HashMap<String, Boolean>(); |
| 29 | party = GameCharacters.INSTANCE.newInstance(); | 29 | party = GameCharacters.createParty(); |
| 30 | variables = new HashMap<String, Integer>(); | 30 | variables = new HashMap<String, Integer>(); |
| 31 | currentMap = new String(); | 31 | currentMap = new String(); |
| 32 | hero = new HeroEvent(); | 32 | hero = new HeroEvent(); |
| diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index b17d7b3..3df55dd 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java | |||
| @@ -75,27 +75,26 @@ public abstract class Map { | |||
| 75 | return true; | 75 | return true; |
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | int i=0; | 78 | for (LayerEvent ev : events) |
| 79 | for (i=0;i<events.size();i++) | ||
| 80 | { | 79 | { |
| 81 | if (events.get(i).getLayer() == Layer.Middle) | 80 | if (ev.getLayer() == Layer.Middle) |
| 82 | { | 81 | { |
| 83 | if ((events.get(i).getLocation().y == (y - 1)) && (events.get(i).getLocation().x == x) && (toMove == Direction.North)) | 82 | if ((ev.getLocation().y == (y - 1)) && (ev.getLocation().x == x) && (toMove == Direction.North)) |
| 84 | { | 83 | { |
| 85 | return true; | 84 | return true; |
| 86 | } | 85 | } |
| 87 | 86 | ||
| 88 | if ((events.get(i).getLocation().x == (x - 1)) && (events.get(i).getLocation().y == y) && (toMove == Direction.West)) | 87 | if ((ev.getLocation().x == (x - 1)) && (ev.getLocation().y == y) && (toMove == Direction.West)) |
| 89 | { | 88 | { |
| 90 | return true; | 89 | return true; |
| 91 | } | 90 | } |
| 92 | 91 | ||
| 93 | if ((events.get(i).getLocation().y == (y + 1)) && (events.get(i).getLocation().x == x) && (toMove == Direction.South)) | 92 | if ((ev.getLocation().y == (y + 1)) && (ev.getLocation().x == x) && (toMove == Direction.South)) |
| 94 | { | 93 | { |
| 95 | return true; | 94 | return true; |
| 96 | } | 95 | } |
| 97 | 96 | ||
| 98 | if ((events.get(i).getLocation().x == (x + 1)) && (events.get(i).getLocation().y == y) && (toMove == Direction.East)) | 97 | if ((ev.getLocation().x == (x + 1)) && (ev.getLocation().y == y) && (toMove == Direction.East)) |
| 99 | { | 98 | { |
| 100 | return true; | 99 | return true; |
| 101 | } | 100 | } |
| @@ -124,32 +123,32 @@ public abstract class Map { | |||
| 124 | 123 | ||
| 125 | ChipSet cSI = ChipSet.getChipSet(chipSet); | 124 | ChipSet cSI = ChipSet.getChipSet(chipSet); |
| 126 | HashMap<Integer,ChipSetData> cSID = cSI.getChipSetData(); | 125 | HashMap<Integer,ChipSetData> cSID = cSI.getChipSetData(); |
| 127 | for (i=0;i<getMapData().size();i++) | 126 | for (HashMap<Integer,Integer> mapArea : getMapData()) |
| 128 | { | 127 | { |
| 129 | if ((toMove == Direction.North) && (!cSID.get(mapData.get(i).get(x+((y-1)*getSize().width))).isEnableSouth())) | 128 | if ((toMove == Direction.North) && (!cSID.get(mapArea.get(x+((y-1)*getSize().width))).isEnableSouth())) |
| 130 | { | 129 | { |
| 131 | return true; | 130 | return true; |
| 132 | } else if ((toMove == Direction.West) && (!cSID.get(mapData.get(i).get(x-1+(y*getSize().width))).isEnableEast())) | 131 | } else if ((toMove == Direction.West) && (!cSID.get(mapArea.get(x-1+(y*getSize().width))).isEnableEast())) |
| 133 | { | 132 | { |
| 134 | return true; | 133 | return true; |
| 135 | } else if ((toMove == Direction.South) && (!cSID.get(mapData.get(i).get(x+((y+1)*getSize().width))).isEnableNorth())) | 134 | } else if ((toMove == Direction.South) && (!cSID.get(mapArea.get(x+((y+1)*getSize().width))).isEnableNorth())) |
| 136 | { | 135 | { |
| 137 | return true; | 136 | return true; |
| 138 | } else if ((toMove == Direction.East) && (!cSID.get(mapData.get(i).get(x+1+(y*getSize().width))).isEnableWest())) | 137 | } else if ((toMove == Direction.East) && (!cSID.get(mapArea.get(x+1+(y*getSize().width))).isEnableWest())) |
| 139 | { | 138 | { |
| 140 | return true; | 139 | return true; |
| 141 | } | 140 | } |
| 142 | 141 | ||
| 143 | if ((toMove == Direction.North) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableNorth())) | 142 | if ((toMove == Direction.North) && (!cSID.get(mapArea.get(x+(y*getSize().width))).isEnableNorth())) |
| 144 | { | 143 | { |
| 145 | return true; | 144 | return true; |
| 146 | } else if ((toMove == Direction.West) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableWest())) | 145 | } else if ((toMove == Direction.West) && (!cSID.get(mapArea.get(x+(y*getSize().width))).isEnableWest())) |
| 147 | { | 146 | { |
| 148 | return true; | 147 | return true; |
| 149 | } else if ((toMove == Direction.South) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableSouth())) | 148 | } else if ((toMove == Direction.South) && (!cSID.get(mapArea.get(x+(y*getSize().width))).isEnableSouth())) |
| 150 | { | 149 | { |
| 151 | return true; | 150 | return true; |
| 152 | } else if ((toMove == Direction.East) && (!cSID.get(mapData.get(i).get(x+(y*getSize().width))).isEnableEast())) | 151 | } else if ((toMove == Direction.East) && (!cSID.get(mapArea.get(x+(y*getSize().width))).isEnableEast())) |
| 153 | { | 152 | { |
| 154 | return true; | 153 | return true; |
| 155 | } | 154 | } |
