From 343e6670113522db5358eff4340ffcb4f7a411de Mon Sep 17 00:00:00 2001 From: Anton Johansson Date: Fri, 2 Jan 2009 23:21:11 +0100 Subject: [PATCH] getTypes from factories --- build.xml | 7 ++++++ src/se/umu/cs/dit06ajnajs/ATDView.java | 2 +- .../dit06ajnajs/agent/AgentPrototypeFactory.java | 25 +++++++++++++++------- .../dit06ajnajs/map/MapSquarePrototypeFactory.java | 25 +++++++++++++++------- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/build.xml b/build.xml index fae7e33..c8cea61 100644 --- a/build.xml +++ b/build.xml @@ -108,6 +108,13 @@ + + + + + + + diff --git a/src/se/umu/cs/dit06ajnajs/ATDView.java b/src/se/umu/cs/dit06ajnajs/ATDView.java index 2b4f5d1..2ad74d2 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDView.java +++ b/src/se/umu/cs/dit06ajnajs/ATDView.java @@ -174,7 +174,7 @@ public class ATDView { */ @Override public void paintComponent(Graphics g) { - logger.fine("paintComponent(...)"); + logger.fine("paintComponent(...)"); g.drawImage(backgroundImage, 0, 0, null); diff --git a/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java b/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java index bdfc410..255ca6d 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java +++ b/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java @@ -6,13 +6,14 @@ import java.net.URL; import javax.imageio.ImageIO; import se.umu.cs.dit06ajnajs.agent.Direction; import se.umu.cs.dit06ajnajs.map.Map; +import java.util.Set; import java.util.HashMap; /** * MapSquarePrototypeFactory is used to create new instances of different * implementations of MapSquare from a String. Implemented as a Singleton. */ -public class AgentPrototypeFactory { +public class AgentPrototypeFactory { private static final AgentPrototypeFactory INSTANCE = new AgentPrototypeFactory(); // private static Logger logger = Logger.getLogger("AntiTD"); @@ -20,7 +21,7 @@ public class AgentPrototypeFactory { private java.util.Map unitMap; private java.util.Map towerMap; private static final int UNSET = -3333; - + /** * Gets the only instance of this class, if none exists one is created. * @@ -42,14 +43,13 @@ public class AgentPrototypeFactory { private AgentPrototypeFactory() { unitMap = new HashMap(); towerMap = new HashMap(); - + // Instantiate Units try { - // Get directory containing images // TODO: move to config class of file URL imagesURL = this.getClass().getResource("/resources/"); - + // Create Standard FootmanUnit BufferedImage image = ImageIO.read(new URL(imagesURL, "unit1.gif")); unitMap.put("FootmanUnit", @@ -60,7 +60,7 @@ public class AgentPrototypeFactory { + e.getMessage()); } } - + // TODO: Implement and think, is this crazy? Lot's of stuff shouldn't have // to be in the parameterlist, needed info is x, y, Direction and map, the // rest is information about the unit-type. Create a Unit with only a @@ -84,14 +84,23 @@ public class AgentPrototypeFactory { resultUnit.setMap(map); return resultUnit; } - + // TODO: How to get all keys? Hashtable can return Enumeration // public List getUnitTypes() {} - + @Override public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException("AgentPrototypeFactory is a " + "Singleton no clones are" + " supported."); } + + /** + * Returns a Set containing all unitTypes this Class can produce. + * + * @return A Set containing all unitTypes this Class can produce. + */ + public Set getUnitTypes() { + return unitMap.keySet(); + } } \ No newline at end of file diff --git a/src/se/umu/cs/dit06ajnajs/map/MapSquarePrototypeFactory.java b/src/se/umu/cs/dit06ajnajs/map/MapSquarePrototypeFactory.java index b5b7999..3593f89 100644 --- a/src/se/umu/cs/dit06ajnajs/map/MapSquarePrototypeFactory.java +++ b/src/se/umu/cs/dit06ajnajs/map/MapSquarePrototypeFactory.java @@ -6,7 +6,7 @@ import java.net.URL; import java.util.HashMap; import javax.imageio.ImageIO; -import java.io.File; +import java.util.Set; /** * MapSquarePrototypeFactory is used to create new instances of different @@ -45,12 +45,12 @@ public class MapSquarePrototypeFactory { squareMap = new HashMap(); //TODO read squaresettings from file - + try { // Get directory containing images // TODO: move to config class of file URL imagesURL = this.getClass().getResource("/resources/"); - + // Create TowerSquare Prototype // URL url = this.getClass().getResource("/resources/grass.jpg"); URL url = new URL(imagesURL, "grass.jpg"); @@ -61,17 +61,17 @@ public class MapSquarePrototypeFactory { url = new URL(imagesURL, "path.jpg"); image = ImageIO.read(url); squareMap.put("PathSquare", new PathSquare(-1, -1, image)); - + // Create GoalSquare Prototype url = new URL(imagesURL, "goal.gif"); image = ImageIO.read(url); squareMap.put("GoalSquare", new GoalSquare(-1, -1, image)); - + // Create BlockedSquare Prototype url = new URL(imagesURL, "stone.gif"); image = ImageIO.read(url); squareMap.put("BlockedSquare", new BlockedSquare(-1, -1, image)); - + // Create TurSquare Prototype url = new URL(imagesURL, "path.jpg"); image = ImageIO.read(url); @@ -99,16 +99,25 @@ public class MapSquarePrototypeFactory { + "' doesn't exist"); } MapSquare resultSquare = (MapSquare) squarePrototype.clone(); - + resultSquare.setX(x); resultSquare.setY(y); return resultSquare; } - + @Override public Object clone() throws CloneNotSupportedException { throw new CloneNotSupportedException("AgentPrototypeFactory is a " + "Singleton no clones are" + " supported."); } + + /** + * Returns a Set containing all unitTypes this Class can produce. + * + * @return A Set containing all unitTypes this Class can produce. + */ + public Set getMapSquareTypes() { + return squareMap.keySet(); + } } \ No newline at end of file -- 2.11.4.GIT