From ff6d3bc16d6291d89e3dd4196e0d5d054eea54be Mon Sep 17 00:00:00 2001 From: Anton Johansson Date: Mon, 5 Jan 2009 20:31:17 +0100 Subject: [PATCH] LevelEditor StartSquare --- src/resources/levels.xml | 2 +- src/se/umu/cs/dit06ajnajs/map/StartSquare.java | 15 +++++++-------- src/se/umu/cs/dit06ajnajs/util/LevelEditor.java | 21 +++++++++++++++++++++ .../umu/cs/dit06ajnajs/util/LevelsXMLOutputter.java | 4 ++-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/resources/levels.xml b/src/resources/levels.xml index 9bb9f08..e93490c 100644 --- a/src/resources/levels.xml +++ b/src/resources/levels.xml @@ -104,7 +104,7 @@ - + diff --git a/src/se/umu/cs/dit06ajnajs/map/StartSquare.java b/src/se/umu/cs/dit06ajnajs/map/StartSquare.java index c28cf21..106ab88 100644 --- a/src/se/umu/cs/dit06ajnajs/map/StartSquare.java +++ b/src/se/umu/cs/dit06ajnajs/map/StartSquare.java @@ -1,24 +1,23 @@ package se.umu.cs.dit06ajnajs.map; -import java.util.List; import java.awt.Image; import se.umu.cs.dit06ajnajs.agent.Unit; import java.util.logging.Logger; -import java.util.ArrayList; +import se.umu.cs.dit06ajnajs.agent.Direction; -public class StartSquare extends MapSquare implements Traversable { +public class StartSquare extends MapSquare implements Traversable { private static Logger logger = Logger.getLogger("AntiTD"); - private List units; + + // TODO, set startDirection dynamicly + private Direction startDirection = Direction.UP; public StartSquare(int x, int y, Image image) { super(x, y, image); - units = new ArrayList(); } public void landOn(Unit unit) { // TODO copied from GoalSquare, how do we implement a starting Unit? // Set direction... - units.add(unit); - unit.setAlive(true); + unit.setDirection(startDirection); } -} +} \ 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 b89dfa9..48835fa 100644 --- a/src/se/umu/cs/dit06ajnajs/util/LevelEditor.java +++ b/src/se/umu/cs/dit06ajnajs/util/LevelEditor.java @@ -14,6 +14,7 @@ import se.umu.cs.dit06ajnajs.AntiTD; import se.umu.cs.dit06ajnajs.map.Map; import se.umu.cs.dit06ajnajs.map.MapSquare; import se.umu.cs.dit06ajnajs.map.MapSquarePrototypeFactory; +import se.umu.cs.dit06ajnajs.util.LevelsXMLOutputter; import javax.swing.JList; import javax.swing.ListSelectionModel; import javax.swing.DefaultListModel; @@ -22,6 +23,13 @@ import javax.swing.event.ListSelectionEvent; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JButton; +import java.io.Writer; +import java.io.FileWriter; +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.io.OutputStreamWriter; +import java.io.FileOutputStream; public class LevelEditor extends JFrame { private static Logger logger = Logger.getLogger("AntiTD.levelEditor"); @@ -77,6 +85,19 @@ public class LevelEditor extends JFrame { saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { System.out.println("Dude"); + try { + URL dirURL = this.getClass().getResource("/resources/"); + File outFile = new File(dirURL.toString(), "anton-test.xml"); + + Writer writer = + new OutputStreamWriter(new FileOutputStream(outFile), "UTF-8"); + + LevelsXMLOutputter.outputMap(map, writer); + System.out.println("Wrote file"); + } catch (IOException e) { + // TODO - fix error message + e.printStackTrace(); + } } }); controlsPanel.add(saveButton, BorderLayout.SOUTH); diff --git a/src/se/umu/cs/dit06ajnajs/util/LevelsXMLOutputter.java b/src/se/umu/cs/dit06ajnajs/util/LevelsXMLOutputter.java index 69a4839..be5165a 100644 --- a/src/se/umu/cs/dit06ajnajs/util/LevelsXMLOutputter.java +++ b/src/se/umu/cs/dit06ajnajs/util/LevelsXMLOutputter.java @@ -1,4 +1,4 @@ -package cs.umu.se.dit06ajnajs.util; +package se.umu.cs.dit06ajnajs.util; import java.io.IOException; import java.io.Writer; @@ -22,7 +22,7 @@ public final class LevelsXMLOutputter { e.printStackTrace(); } } - + // TODO make Document of one ore more Maps private static Document makeDoc(Map map) { MapSquare[][] squareMatrix = map.toArray(); -- 2.11.4.GIT