From c861cdfb060566b9c4452c2002b6214e0a9359a6 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Sat, 7 Feb 2009 11:20:45 -0500 Subject: Started Database --- src/com/fourisland/fourpuzzle/Database.java | 95 ++++++++++++++++++++++ src/com/fourisland/fourpuzzle/GameCharacters.java | 6 +- .../fourisland/fourpuzzle/PuzzleApplication.java | 4 +- src/com/fourisland/fourpuzzle/SaveFile.java | 2 +- .../fourpuzzle/gamestate/GameOverGameState.java | 3 +- .../fourpuzzle/gamestate/TitleScreenGameState.java | 2 +- .../gamestate/mapview/event/SpecialEvent.java | 26 ++++-- .../transition/DoNotEraseTransition.java | 5 ++ .../fourpuzzle/transition/SlideTransition.java | 5 ++ .../fourpuzzle/transition/SquareTransition.java | 5 ++ .../fourpuzzle/transition/Transition.java | 2 + 11 files changed, 142 insertions(+), 13 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/Database.java (limited to 'src/com') diff --git a/src/com/fourisland/fourpuzzle/Database.java b/src/com/fourisland/fourpuzzle/Database.java new file mode 100644 index 0000000..8d51f9a --- /dev/null +++ b/src/com/fourisland/fourpuzzle/Database.java @@ -0,0 +1,95 @@ +/* + * To change this template, choose Tools | Templates + * and open the template in the editor. + */ + +package com.fourisland.fourpuzzle; + +import com.fourisland.fourpuzzle.transition.SquareTransition; +import com.fourisland.fourpuzzle.transition.Transition; +import com.fourisland.fourpuzzle.transition.TransitionDirection; +import java.util.HashMap; + +/** + * + * @author hatkirby + */ +public class Database { + + private static HashMap vocabulary = new HashMap(); + private static GameCharacters heros = GameCharacters.getDefaultParty(); + private static HashMap music = new HashMap(); + private static HashMap transitions = new HashMap(); + + static { + loadDefaultVocabulary(); + loadDefaultMusic(); + loadDefaultTransitions(); + } + + /* Vocabulary */ + + private static void loadDefaultVocabulary() + { + vocabulary.put("Title", "Untitled Game"); + } + + public static String getVocab(String key) + { + return vocabulary.get(key); + } + + public static void setVocab(String key, String value) + { + vocabulary.put(key, value); + } + + /* Heros */ + + public static void addHero(GameCharacter hero) + { + heros.add(hero); + } + + public static GameCharacters createParty() + { + return GameCharacters.createParty(); + } + + /* Music */ + + public static void loadDefaultMusic() + { + music.put("Title", "Opening"); + music.put("GameOver", "GameOver"); + } + + public static String getMusic(String key) + { + return music.get(key); + } + + public static void setMusic(String key, String value) + { + music.put(key, value); + } + + /* Transitions */ + + public static void loadDefaultTransitions() + { + transitions.put("MapExit", new SquareTransition(TransitionDirection.Out)); + transitions.put("MapEnter", new SquareTransition(TransitionDirection.In)); + } + + public static Transition getTransition(String key) + { + return transitions.get(key).copy(); + } + + public static void setTransition(String key, Transition value) + { + transitions.put(key, value); + } + +} diff --git a/src/com/fourisland/fourpuzzle/GameCharacters.java b/src/com/fourisland/fourpuzzle/GameCharacters.java index 933b333..211b66d 100644 --- a/src/com/fourisland/fourpuzzle/GameCharacters.java +++ b/src/com/fourisland/fourpuzzle/GameCharacters.java @@ -17,12 +17,12 @@ public class GameCharacters extends ArrayList private GameCharacters() {} private static GameCharacters INSTANCE = new GameCharacters(); - public static GameCharacters getDefaultParty() + static GameCharacters getDefaultParty() { return INSTANCE; } - public static GameCharacters createParty() + static GameCharacters createParty() { GameCharacters temp = new GameCharacters(); temp.addAll(INSTANCE); @@ -42,7 +42,7 @@ public class GameCharacters extends ArrayList Game.setGameState(new GameOverGameState()); return null; - } + } public boolean exists(String heroName) { for (GameCharacter chara : this) diff --git a/src/com/fourisland/fourpuzzle/PuzzleApplication.java b/src/com/fourisland/fourpuzzle/PuzzleApplication.java index 9225c90..80b6cd3 100644 --- a/src/com/fourisland/fourpuzzle/PuzzleApplication.java +++ b/src/com/fourisland/fourpuzzle/PuzzleApplication.java @@ -40,7 +40,7 @@ public class PuzzleApplication extends Application { INSTANCE = this; gameFrame = new JDialog(new JFrame(), false); - gameFrame.setTitle("The Hat"); + gameFrame.setTitle(Database.getVocab("title")); gameFrame.setSize(Game.WIDTH * 2, Game.HEIGHT * 2); gameFrame.setResizable(false); gameFrame.addWindowListener(new WindowAdapter() { @@ -158,7 +158,7 @@ public class PuzzleApplication extends Application { JFrame errorBox = new JFrame(ex.getClass().getSimpleName()); JLabel text = new JLabel(); - text.setText("
I'm sorry, but " + INSTANCE.getContext().getResourceMap().getString("Application.title") + + text.setText("
I'm sorry, but " + Database.getVocab("Title") + " has run into an error and been forced to quit.
Your save file has not been kept. The error was:

" + ex.getMessage() + "
"); if (ex instanceof Error) diff --git a/src/com/fourisland/fourpuzzle/SaveFile.java b/src/com/fourisland/fourpuzzle/SaveFile.java index 2b99bc5..d079f0f 100644 --- a/src/com/fourisland/fourpuzzle/SaveFile.java +++ b/src/com/fourisland/fourpuzzle/SaveFile.java @@ -27,7 +27,7 @@ public class SaveFile implements Serializable { public SaveFile() { switches = new HashMap(); - party = GameCharacters.createParty(); + party = Database.createParty(); variables = new HashMap(); currentMap = new String(); hero = new HeroEvent(); diff --git a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java index d20691f..53cae37 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/GameOverGameState.java @@ -6,6 +6,7 @@ package com.fourisland.fourpuzzle.gamestate; import com.fourisland.fourpuzzle.Audio; +import com.fourisland.fourpuzzle.Database; import com.fourisland.fourpuzzle.Display; import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.SaveFile; @@ -23,7 +24,7 @@ public class GameOverGameState implements GameState { public void initalize() { - Audio.playMusic("GameOver"); + Audio.playMusic(Database.getMusic("GameOver")); } public void deinitalize() diff --git a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java index 0b032eb..9247282 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java +++ b/src/com/fourisland/fourpuzzle/gamestate/TitleScreenGameState.java @@ -21,7 +21,7 @@ public class TitleScreenGameState implements GameState { public void initalize() { - Audio.playMusic("Opening"); + Audio.playMusic(Database.getMusic("Title")); } public void deinitalize() diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index c39082d..c48b312 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -166,9 +166,12 @@ public class SpecialEvent { */ public void StartTransition(OutTransition trans) throws InterruptedException { - startedTransition = true; - - Display.transition(trans); + if (!startedTransition) + { + startedTransition = true; + + Display.transition(trans); + } } /** @@ -181,10 +184,21 @@ public class SpecialEvent { * @param map The name of the map to move to * @param x The X position on the map to move to * @param y The Y position on the map to move to + * @throws InterruptedException */ - public void Teleport(String map, int x, int y) + public void Teleport(String map, int x, int y) throws InterruptedException { - throw new UnsupportedOperationException("Not yet implemented"); + if (!startedTransition) + { + Display.transition(Database.getTransition("MapExit")); + } + + Game.setGameState(new MapViewGameState(map, x, y)); + + if (!startedTransition) + { + Display.transition(Database.getTransition("MapEnter")); + } } /** @@ -202,6 +216,8 @@ public class SpecialEvent { if (startedTransition) { Display.transition(trans); + + startedTransition = false; } } diff --git a/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java b/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java index ccdf3f2..027077c 100644 --- a/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/DoNotEraseTransition.java @@ -23,5 +23,10 @@ public class DoNotEraseTransition implements OutTransition { { // Do nothing } + + public Transition copy() + { + return new DoNotEraseTransition(); + } } diff --git a/src/com/fourisland/fourpuzzle/transition/SlideTransition.java b/src/com/fourisland/fourpuzzle/transition/SlideTransition.java index e40ad99..81031fe 100644 --- a/src/com/fourisland/fourpuzzle/transition/SlideTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SlideTransition.java @@ -137,4 +137,9 @@ public class SlideTransition implements MultidirectionalTransition { UpOrDown } + public Transition copy() + { + return new SlideTransition(direction, d); + } + } diff --git a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java index 8a74176..6167fc3 100644 --- a/src/com/fourisland/fourpuzzle/transition/SquareTransition.java +++ b/src/com/fourisland/fourpuzzle/transition/SquareTransition.java @@ -74,4 +74,9 @@ public class SquareTransition implements MultidirectionalTransition { this.postTransition = postTransition; } + public Transition copy() + { + return new SquareTransition(direction); + } + } diff --git a/src/com/fourisland/fourpuzzle/transition/Transition.java b/src/com/fourisland/fourpuzzle/transition/Transition.java index 445d75d..8362d1a 100644 --- a/src/com/fourisland/fourpuzzle/transition/Transition.java +++ b/src/com/fourisland/fourpuzzle/transition/Transition.java @@ -23,4 +23,6 @@ public interface Transition { public boolean render(Graphics2D g); public void setPreTransition(BufferedImage preTransition); + + public Transition copy(); } \ No newline at end of file -- cgit 1.4.1