summary refs log tree commit diff stats
path: root/src/com/fourisland
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/fourisland')
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/Game.java2
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/database/Database.java13
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/Map.java64
-rwxr-xr-xsrc/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java22
4 files changed, 60 insertions, 41 deletions
diff --git a/src/com/fourisland/fourpuzzle/Game.java b/src/com/fourisland/fourpuzzle/Game.java index d2e8943..432d8ff 100755 --- a/src/com/fourisland/fourpuzzle/Game.java +++ b/src/com/fourisland/fourpuzzle/Game.java
@@ -17,7 +17,7 @@ public class Game {
17 17
18 public static final int WIDTH = 320; 18 public static final int WIDTH = 320;
19 public static final int HEIGHT = 240; 19 public static final int HEIGHT = 240;
20 public static final int FPS = (1000 / 30); // 30 fps 20 public static final int FPS = (1000 / 20); // 20 fps
21 21
22 private static SaveFile saveFile; 22 private static SaveFile saveFile;
23 public static SaveFile getSaveFile() 23 public static SaveFile getSaveFile()
diff --git a/src/com/fourisland/fourpuzzle/database/Database.java b/src/com/fourisland/fourpuzzle/database/Database.java index 6d61f37..1493a3f 100755 --- a/src/com/fourisland/fourpuzzle/database/Database.java +++ b/src/com/fourisland/fourpuzzle/database/Database.java
@@ -5,7 +5,9 @@
5 5
6package com.fourisland.fourpuzzle.database; 6package com.fourisland.fourpuzzle.database;
7 7
8import com.fourisland.fourpuzzle.gamestate.mapview.Map;
8import com.fourisland.fourpuzzle.transition.Transition; 9import com.fourisland.fourpuzzle.transition.Transition;
10import java.util.HashMap;
9 11
10/** 12/**
11 * 13 *
@@ -117,5 +119,16 @@ public class Database {
117 { 119 {
118 key.setValue(value); 120 key.setValue(value);
119 } 121 }
122
123 private static java.util.Map<String, Map> maps = new HashMap<String, Map>();
124 public static void addMap(String key, Map value)
125 {
126 maps.put(key, value);
127 }
128
129 public static Map getMap(String key)
130 {
131 return maps.get(key);
132 }
120 133
121} 134}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index 124ea95..1511fea 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java
@@ -14,20 +14,53 @@ import java.awt.Dimension;
14import java.awt.Graphics2D; 14import java.awt.Graphics2D;
15import java.awt.image.BufferedImage; 15import java.awt.image.BufferedImage;
16import java.util.HashMap; 16import java.util.HashMap;
17import java.util.List;
17import java.util.Vector; 18import java.util.Vector;
18 19
19/** 20/**
20 * 21 *
21 * @author hatkirby 22 * @author hatkirby
22 */ 23 */
23public abstract class Map { 24public class Map {
24 25
25 public abstract void initalize(); 26 /**
27 * Creates a new Map
28 *
29 * @param width The width of the Map in tiles
30 * @param height The height of the Map in tiles
31 * @param chipSet The name of the ChipSet to use
32 * @param music The name of the Music file to play in the background
33 */
34 public Map(int width, int height, String chipSet, String music)
35 {
36 setSize(new Dimension(width, height));
37 setChipSet(chipSet);
38 setMusic(music);
39 }
26 40
27 protected void initalize(Dimension size) 41 /**
42 * Creates a new Map
43 *
44 * @param width The width of the Map in tiles
45 * @param height The height of the Map in tiles
46 * @param chipSet The name of the ChipSet to use
47 * @param musicType The non-Specified Music mode to use
48 *
49 * @throws IllegalArgumentException if MapMusicType.Specified is passed in
50 * musicType. This constructor is for MapMusicType.NoMusic or
51 * MapMusicType.NoChange. If you wish to specify a Music file, use the other
52 * constructor (int, int, String, String)
53 */
54 public Map(int width, int height, String chipSet, MapMusicType musicType)
28 { 55 {
29 setSize(size); 56 if (musicType == MapMusicType.Specified)
30 mapData = new Vector<HashMap<Integer,Integer>>(); 57 {
58 throw new IllegalArgumentException("MapMusicType.Specified is not a valid value for musicType. If you wish to specify a music type, use the other constructor (int, int, String, String)");
59 }
60
61 setSize(new Dimension(width, height));
62 setChipSet(chipSet);
63 setMusicType(musicType);
31 } 64 }
32 65
33 private Dimension size; 66 private Dimension size;
@@ -172,8 +205,8 @@ public abstract class Map {
172 this.chipSet = chipSet; 205 this.chipSet = chipSet;
173 } 206 }
174 207
175 private Vector<HashMap<Integer,Integer>> mapData; 208 private List<HashMap<Integer,Integer>> mapData = new Vector<HashMap<Integer,Integer>>();
176 public Vector<HashMap<Integer, Integer>> getMapData() { 209 public List<HashMap<Integer, Integer>> getMapData() {
177 return mapData; 210 return mapData;
178 } 211 }
179 212
@@ -182,17 +215,8 @@ public abstract class Map {
182 { 215 {
183 return music; 216 return music;
184 } 217 }
185 218
186 /** 219 private void setMusic(String music)
187 * Sets the name of the Music file to play when this Map loads
188 *
189 * When this function is run, it also sets the MusicType to Specified
190 * automatically as the only time this function would be used would be when
191 * the MusicType was Specified.
192 *
193 * @param music
194 */
195 protected void setMusic(String music)
196 { 220 {
197 this.music = music; 221 this.music = music;
198 this.musicType = MapMusicType.Specified; 222 this.musicType = MapMusicType.Specified;
@@ -204,7 +228,7 @@ public abstract class Map {
204 return musicType; 228 return musicType;
205 } 229 }
206 230
207 protected void setMusicType(MapMusicType musicType) 231 private void setMusicType(MapMusicType musicType)
208 { 232 {
209 this.musicType = musicType; 233 this.musicType = musicType;
210 } 234 }
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java index 8f411af..3ed23c3 100755 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/MapViewGameState.java
@@ -13,6 +13,7 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.HeroEvent;
13import com.fourisland.fourpuzzle.Game; 13import com.fourisland.fourpuzzle.Game;
14import com.fourisland.fourpuzzle.Layer; 14import com.fourisland.fourpuzzle.Layer;
15import com.fourisland.fourpuzzle.PuzzleApplication; 15import com.fourisland.fourpuzzle.PuzzleApplication;
16import com.fourisland.fourpuzzle.database.Database;
16import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime; 17import com.fourisland.fourpuzzle.gamestate.mapview.event.EventCallTime;
17import com.fourisland.fourpuzzle.gamestate.mapview.event.EventHandler; 18import com.fourisland.fourpuzzle.gamestate.mapview.event.EventHandler;
18import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; 19import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList;
@@ -22,13 +23,10 @@ import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventTh
22import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint; 23import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.AutomaticViewpoint;
23import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint; 24import com.fourisland.fourpuzzle.gamestate.mapview.viewpoint.Viewpoint;
24import com.fourisland.fourpuzzle.util.Functions; 25import com.fourisland.fourpuzzle.util.Functions;
25import com.fourisland.fourpuzzle.util.ResourceNotFoundException;
26import com.fourisland.fourpuzzle.window.MessageWindow; 26import com.fourisland.fourpuzzle.window.MessageWindow;
27import java.awt.Graphics2D; 27import java.awt.Graphics2D;
28import java.awt.event.KeyEvent; 28import java.awt.event.KeyEvent;
29import java.awt.image.BufferedImage; 29import java.awt.image.BufferedImage;
30import java.util.logging.Level;
31import java.util.logging.Logger;
32 30
33/** 31/**
34 * 32 *
@@ -238,26 +236,10 @@ public class MapViewGameState implements GameState {
238 } 236 }
239 } 237 }
240 238
241 public void initCurrentMap(String mapName)
242 {
243 try {
244 Class mapClass = Class.forName(PuzzleApplication.INSTANCE.getGamePackage() + ".gamedata.map." + mapName);
245 Object mapObject = mapClass.newInstance();
246 Map map = (Map) mapObject;
247 map.initalize();
248 currentMap = map;
249 } catch (InstantiationException ex) {
250 Logger.getLogger(MapViewGameState.class.getName()).log(Level.SEVERE, null, ex);
251 } catch (IllegalAccessException ex) {
252 Logger.getLogger(MapViewGameState.class.getName()).log(Level.SEVERE, null, ex);
253 } catch (ClassNotFoundException ex) {
254 throw new ResourceNotFoundException("Map", mapName);
255 }
256 }
257 public void setCurrentMap(String mapName) 239 public void setCurrentMap(String mapName)
258 { 240 {
259 Game.getSaveFile().setCurrentMap(mapName); 241 Game.getSaveFile().setCurrentMap(mapName);
260 initCurrentMap(mapName); 242 currentMap = Database.getMap(mapName);
261 } 243 }
262 244
263 public Map getCurrentMap() 245 public Map getCurrentMap()