From 5b174360f75e9482210692c7277c9c90981bdcde Mon Sep 17 00:00:00 2001 From: Anton Johansson Date: Thu, 8 Jan 2009 21:32:07 +0100 Subject: [PATCH] New Unit. Collision detection fails on moving left to right. --- src/se/umu/cs/dit06ajnajs/ATDController.java | 2 +- src/se/umu/cs/dit06ajnajs/ATDView.java | 12 +++++++++--- .../cs/dit06ajnajs/agent/AgentPrototypeFactory.java | 5 +++++ src/se/umu/cs/dit06ajnajs/agent/SuperFootmanUnit.java | 18 ++++++++++++++++++ src/se/umu/cs/dit06ajnajs/agent/Unit.java | 5 +++++ src/se/umu/cs/dit06ajnajs/util/LevelEditor.java | 2 +- 6 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 src/se/umu/cs/dit06ajnajs/agent/SuperFootmanUnit.java diff --git a/src/se/umu/cs/dit06ajnajs/ATDController.java b/src/se/umu/cs/dit06ajnajs/ATDController.java index 0a29524..bb932e1 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDController.java +++ b/src/se/umu/cs/dit06ajnajs/ATDController.java @@ -288,7 +288,7 @@ public class ATDController { // TODO: implement System.out.println("hej"); AgentPrototypeFactory factory = AgentPrototypeFactory.getInstance(); - model.addUnit(factory.createUnit("FootmanUnit")); + model.addUnit(factory.createUnit(view.getSelectedUnitType())); } } } diff --git a/src/se/umu/cs/dit06ajnajs/ATDView.java b/src/se/umu/cs/dit06ajnajs/ATDView.java index 2422183..93eedb6 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDView.java +++ b/src/se/umu/cs/dit06ajnajs/ATDView.java @@ -25,6 +25,7 @@ import javax.swing.DefaultListModel; import se.umu.cs.dit06ajnajs.agent.AgentPrototypeFactory; import javax.swing.JList; import javax.swing.ListSelectionModel; +import se.umu.cs.dit06ajnajs.agent.Unit; public class ATDView { private static Logger logger = Logger.getLogger("AntiTD"); @@ -83,10 +84,11 @@ public class ATDView { // JList unitTypes DefaultListModel unitTypesListModel = new DefaultListModel(); - for (String type : AgentPrototypeFactory.getInstance().getUnitTypes()) { - unitTypesListModel.addElement(type); + AgentPrototypeFactory factory = AgentPrototypeFactory.getInstance(); + for (String type : factory.getUnitTypes()) { + Unit unit = factory.createUnit(type); + unitTypesListModel.addElement(unit); } - this.unitList= new JList(unitTypesListModel); unitList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); resultPanel.add(unitList, BorderLayout.NORTH); @@ -140,6 +142,10 @@ public class ATDView { return gameGraphics; } + public String getSelectedUnitType() { + return this.unitList.getSelectedValue().toString(); + } + /** * Returns the Graphics used to update visual information about the Background in * the game. diff --git a/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java b/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java index 32b6870..0ef2adc 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java +++ b/src/se/umu/cs/dit06ajnajs/agent/AgentPrototypeFactory.java @@ -54,6 +54,11 @@ public class AgentPrototypeFactory { BufferedImage image = ImageIO.read(new URL(imagesURL, "unit1.gif")); unitMap.put("FootmanUnit", new FootmanUnit(20, 20, 2, 100, 10, image)); + + // Create Standard FootmanUnit + image = ImageIO.read(new URL(imagesURL, "unit1.gif")); + unitMap.put("SuperFootmanUnit", + new SuperFootmanUnit(20, 20, 4, 100, 10, image)); } catch (IOException e) { System.err.println("Couldn't find image. Exception: " + e.getMessage()); diff --git a/src/se/umu/cs/dit06ajnajs/agent/SuperFootmanUnit.java b/src/se/umu/cs/dit06ajnajs/agent/SuperFootmanUnit.java new file mode 100644 index 0000000..1916503 --- /dev/null +++ b/src/se/umu/cs/dit06ajnajs/agent/SuperFootmanUnit.java @@ -0,0 +1,18 @@ +package se.umu.cs.dit06ajnajs.agent; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Image; + +public class SuperFootmanUnit extends Unit { + public SuperFootmanUnit(int width, int height, int speed, int health, + int cost, Image image) { + super(width, height, speed, health, cost, image); + } + + public void paint(Graphics g) { + // TODO Auto-generated method stub + g.setColor(Color.YELLOW); + g.fillRect(this.getX(), this.getY(), this.getWidth(), this.getHeight()); + } +} diff --git a/src/se/umu/cs/dit06ajnajs/agent/Unit.java b/src/se/umu/cs/dit06ajnajs/agent/Unit.java index 41a8d37..1f8588a 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/Unit.java +++ b/src/se/umu/cs/dit06ajnajs/agent/Unit.java @@ -243,4 +243,9 @@ public abstract class Unit implements Agent, Paintable, Cloneable { public void setPause(boolean state) { this.pause = state; } + + @Override + public String toString() { + return this.getClass().getSimpleName(); + } } \ No newline at end of file diff --git a/src/se/umu/cs/dit06ajnajs/util/LevelEditor.java b/src/se/umu/cs/dit06ajnajs/util/LevelEditor.java index d93f21b..2717b64 100644 --- a/src/se/umu/cs/dit06ajnajs/util/LevelEditor.java +++ b/src/se/umu/cs/dit06ajnajs/util/LevelEditor.java @@ -144,7 +144,7 @@ public class LevelEditor extends JFrame { } /** - * An inner class that handles selection changes in jeedViews item list. + * An inner class that handles changes in MapSquare list. */ private class MapSquareListListener implements ListSelectionListener { public void valueChanged(ListSelectionEvent e) { -- 2.11.4.GIT