From 80fd704e66e98d70e98da977b01568b7813d80e9 Mon Sep 17 00:00:00 2001 From: Starla Insigna Date: Mon, 19 Jan 2009 16:22:50 -0500 Subject: Fixed MoveEvent bug --- .../fourpuzzle/gamestate/mapview/Map.java | 13 +++-- .../gamestate/mapview/MapViewGameState.java | 55 ++++++++++------------ .../gamestate/mapview/event/EventCall.java | 5 ++ .../gamestate/mapview/event/EventList.java | 42 +++++++++++++++++ .../gamestate/mapview/event/LayerEvent.java | 7 ++- .../gamestate/mapview/event/SpecialEvent.java | 11 ++--- .../mapview/event/specialmove/MoveEventThread.java | 28 +++++++++-- src/com/fourisland/fourpuzzle/util/Functions.java | 34 +++++++++++++ 8 files changed, 147 insertions(+), 48 deletions(-) create mode 100644 src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java index bcc2ed7..b17d7b3 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/Map.java @@ -6,9 +6,9 @@ package com.fourisland.fourpuzzle.gamestate.mapview; import com.fourisland.fourpuzzle.*; +import com.fourisland.fourpuzzle.gamestate.mapview.event.EventList; import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; import java.awt.Dimension; -import java.util.ArrayList; import java.util.HashMap; import java.util.Vector; @@ -41,19 +41,18 @@ public abstract class Map { } } - private ArrayList events = new ArrayList(); - public ArrayList getEvents() + private EventList events = new EventList(); + public EventList getEvents() { return events; } public LayerEvent getEvent(String event) { - int i=0; - for (i=0;i events = currentMap.getEvents(); - for (i=0;i { + + @Override + public boolean add(LayerEvent o) + { + if (o.getLabel().equals("Unlabelled")) + { + o.setLabel("Event" + (this.size()+1)); + } else { + if ( (o.getLabel().equals("Hero")) || + (o.getLabel().equals("Unlabelled")) || + (o.getLabel().equals(""))) + { + return false; + } + + for (Event ev : this) + { + if (ev.getLabel().equals(o.getLabel())) + { + return false; + } + } + } + + return super.add(o); + } + +} diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java index 92cfd54..b67f2aa 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java @@ -27,6 +27,7 @@ public class LayerEvent implements Event { { location = new Point(x,y); events = new ArrayList(); + label = "Unlabelled"; } /** Create a new Event instance @@ -204,4 +205,8 @@ public class LayerEvent implements Event { return getPossibleEvent().getCallback(); } -} + public void setLabel(String string) { + this.label = string; + } + +} \ No newline at end of file diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java index 26f89c7..121bbe8 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java @@ -6,10 +6,9 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event; import com.fourisland.fourpuzzle.*; +import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState; import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; -import java.util.concurrent.BrokenBarrierException; -import java.util.concurrent.CyclicBarrier; import java.util.logging.Level; import java.util.logging.Logger; @@ -102,18 +101,18 @@ public class SpecialEvent { */ public void MoveEvent(MoveEvent[] actions) { - MoveEvent(actions, Game.getHeroEvent()); + new Thread(new MoveEventThread(Game.getHeroEvent(), actions)).start(); } /** * Performs actions on an event * * @param actions An array of MoveEvents to perform on the event - * @param ev The event to act upon + * @param label The label of the event to act upon */ - public void MoveEvent(MoveEvent[] actions, Event ev) + public void MoveEvent(MoveEvent[] actions, String label) { - new Thread(new MoveEventThread(ev, actions)).start(); + new Thread(new MoveEventThread(((MapViewGameState) Game.getGameState()).getCurrentMap().getEvent(label), actions)).start(); } /** diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java index 4c16197..d6971f3 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java @@ -5,9 +5,12 @@ package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; +import com.fourisland.fourpuzzle.Game; import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; +import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent; +import java.util.List; +import java.util.Vector; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.CyclicBarrier; import java.util.logging.Level; import java.util.logging.Logger; @@ -19,6 +22,7 @@ public class MoveEventThread implements Runnable { public static volatile CountDownLatch moveEventWait = new CountDownLatch(0); public static volatile int countMoveEventThreads = 0; + public static volatile List events = new Vector(); Event ev; MoveEvent[] actions; @@ -29,22 +33,36 @@ public class MoveEventThread implements Runnable { this.actions = actions; } - public void run() { + public void run() + { + events.add(ev); + MoveEventThread.countMoveEventThreads++; moveEventWait = new CountDownLatch(countMoveEventThreads); - int i=0; - for (i=0;i