summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-01-19 16:22:50 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-01-19 16:22:50 -0500
commit80fd704e66e98d70e98da977b01568b7813d80e9 (patch)
tree8ea16d1f3d37a212c42025e3fbc86d1f4c15545f /src/com/fourisland/fourpuzzle/gamestate/mapview/event
parent69b495c392bffe96dab97306a42466edd4b2474e (diff)
downloadfourpuzzle-80fd704e66e98d70e98da977b01568b7813d80e9.tar.gz
fourpuzzle-80fd704e66e98d70e98da977b01568b7813d80e9.tar.bz2
fourpuzzle-80fd704e66e98d70e98da977b01568b7813d80e9.zip
Fixed MoveEvent bug
Diffstat (limited to 'src/com/fourisland/fourpuzzle/gamestate/mapview/event')
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java5
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java42
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/LayerEvent.java7
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/SpecialEvent.java11
-rw-r--r--src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java28
5 files changed, 81 insertions, 12 deletions
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java index daca678..3bbde17 100644 --- a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventCall.java
@@ -22,4 +22,9 @@ public abstract class EventCall extends SpecialEvent implements Runnable {
22 22
23 public abstract void run(); 23 public abstract void run();
24 24
25 public void activate()
26 {
27 new Thread(this, "Special Event").start();
28 }
29
25} 30}
diff --git a/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java new file mode 100644 index 0000000..a10aadc --- /dev/null +++ b/src/com/fourisland/fourpuzzle/gamestate/mapview/event/EventList.java
@@ -0,0 +1,42 @@
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7
8import java.util.Vector;
9
10/**
11 *
12 * @author hatkirby
13 */
14public class EventList extends Vector<LayerEvent> {
15
16 @Override
17 public boolean add(LayerEvent o)
18 {
19 if (o.getLabel().equals("Unlabelled"))
20 {
21 o.setLabel("Event" + (this.size()+1));
22 } else {
23 if ( (o.getLabel().equals("Hero")) ||
24 (o.getLabel().equals("Unlabelled")) ||
25 (o.getLabel().equals("")))
26 {
27 return false;
28 }
29
30 for (Event ev : this)
31 {
32 if (ev.getLabel().equals(o.getLabel()))
33 {
34 return false;
35 }
36 }
37 }
38
39 return super.add(o);
40 }
41
42}
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 {
27 { 27 {
28 location = new Point(x,y); 28 location = new Point(x,y);
29 events = new ArrayList<PossibleEvent>(); 29 events = new ArrayList<PossibleEvent>();
30 label = "Unlabelled";
30 } 31 }
31 32
32 /** Create a new Event instance 33 /** Create a new Event instance
@@ -204,4 +205,8 @@ public class LayerEvent implements Event {
204 return getPossibleEvent().getCallback(); 205 return getPossibleEvent().getCallback();
205 } 206 }
206 207
207} 208 public void setLabel(String string) {
209 this.label = string;
210 }
211
212} \ 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 @@
6package com.fourisland.fourpuzzle.gamestate.mapview.event; 6package com.fourisland.fourpuzzle.gamestate.mapview.event;
7 7
8import com.fourisland.fourpuzzle.*; 8import com.fourisland.fourpuzzle.*;
9import com.fourisland.fourpuzzle.gamestate.mapview.MapViewGameState;
9import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent; 10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEvent;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread; 11import com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove.MoveEventThread;
11import java.util.concurrent.BrokenBarrierException;
12import java.util.concurrent.CyclicBarrier;
13import java.util.logging.Level; 12import java.util.logging.Level;
14import java.util.logging.Logger; 13import java.util.logging.Logger;
15 14
@@ -102,18 +101,18 @@ public class SpecialEvent {
102 */ 101 */
103 public void MoveEvent(MoveEvent[] actions) 102 public void MoveEvent(MoveEvent[] actions)
104 { 103 {
105 MoveEvent(actions, Game.getHeroEvent()); 104 new Thread(new MoveEventThread(Game.getHeroEvent(), actions)).start();
106 } 105 }
107 106
108 /** 107 /**
109 * Performs actions on an event 108 * Performs actions on an event
110 * 109 *
111 * @param actions An array of MoveEvents to perform on the event 110 * @param actions An array of MoveEvents to perform on the event
112 * @param ev The event to act upon 111 * @param label The label of the event to act upon
113 */ 112 */
114 public void MoveEvent(MoveEvent[] actions, Event ev) 113 public void MoveEvent(MoveEvent[] actions, String label)
115 { 114 {
116 new Thread(new MoveEventThread(ev, actions)).start(); 115 new Thread(new MoveEventThread(((MapViewGameState) Game.getGameState()).getCurrentMap().getEvent(label), actions)).start();
117 } 116 }
118 117
119 /** 118 /**
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 @@
5 5
6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove; 6package com.fourisland.fourpuzzle.gamestate.mapview.event.specialmove;
7 7
8import com.fourisland.fourpuzzle.Game;
8import com.fourisland.fourpuzzle.gamestate.mapview.event.Event; 9import com.fourisland.fourpuzzle.gamestate.mapview.event.Event;
10import com.fourisland.fourpuzzle.gamestate.mapview.event.LayerEvent;
11import java.util.List;
12import java.util.Vector;
9import java.util.concurrent.CountDownLatch; 13import java.util.concurrent.CountDownLatch;
10import java.util.concurrent.CyclicBarrier;
11import java.util.logging.Level; 14import java.util.logging.Level;
12import java.util.logging.Logger; 15import java.util.logging.Logger;
13 16
@@ -19,6 +22,7 @@ public class MoveEventThread implements Runnable {
19 22
20 public static volatile CountDownLatch moveEventWait = new CountDownLatch(0); 23 public static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
21 public static volatile int countMoveEventThreads = 0; 24 public static volatile int countMoveEventThreads = 0;
25 public static volatile List<Event> events = new Vector<Event>();
22 26
23 Event ev; 27 Event ev;
24 MoveEvent[] actions; 28 MoveEvent[] actions;
@@ -29,22 +33,36 @@ public class MoveEventThread implements Runnable {
29 this.actions = actions; 33 this.actions = actions;
30 } 34 }
31 35
32 public void run() { 36 public void run()
37 {
38 events.add(ev);
39
33 MoveEventThread.countMoveEventThreads++; 40 MoveEventThread.countMoveEventThreads++;
34 moveEventWait = new CountDownLatch(countMoveEventThreads); 41 moveEventWait = new CountDownLatch(countMoveEventThreads);
35 42
36 int i=0; 43 for (MoveEvent action : actions)
37 for (i=0;i<actions.length;i++)
38 { 44 {
39 try { 45 try {
40 actions[i].doAction(ev); 46 action.doAction(ev);
41 } catch (Exception ex) { 47 } catch (Exception ex) {
42 Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex); 48 Logger.getLogger(MoveEventThread.class.getName()).log(Level.SEVERE, null, ex);
43 } 49 }
44 } 50 }
45 51
52 events.remove(ev);
53
46 MoveEventThread.countMoveEventThreads--; 54 MoveEventThread.countMoveEventThreads--;
47 moveEventWait.countDown(); 55 moveEventWait.countDown();
48 } 56 }
57
58 public static boolean isHeroMoving()
59 {
60 return (events.contains(Game.getHeroEvent()));
61 }
62
63 public static boolean isOtherMoving(LayerEvent event)
64 {
65 return (events.contains(event));
66 }
49 67
50} 68}