summary refs log tree commit diff stats
path: root/src/com/fourisland/fourpuzzle/gamestate/mapview/event/specialmove/MoveEventThread.java
blob: ab160f13d7d662795b4b4ea1684b207f618e952a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

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.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author hatkirby
 */
public class MoveEventThread implements Runnable {
    
    public static volatile CountDownLatch moveEventWait = new CountDownLatch(0);
    public static volatile int countMoveEventThreads = 0;
    public static volatile List<Event> events = new Vector<Event>();
    
    Event ev;
    MoveEvent[] actions;
    
    public MoveEventThread(Event ev, MoveEvent[] actions)
    {
        this.ev = ev;
        this.actions = actions;
    }

    public void run()
    {
        events.add(ev);
        
        MoveEventThread.countMoveEventThreads++;
        moveEventWait = new CountDownLatch(countMoveEventThreads);
        
        for (MoveEvent action : actions)
        {
            action.doAction(ev);
        }
        
        events.remove(ev);
        
        MoveEventThread.countMoveEventThreads--;
        moveEventWait.countDown();
    }
    
    public static boolean isHeroMoving()
    {
        return (events.contains(Game.getHeroEvent()));
    }
    
    public static boolean isOtherMoving(LayerEvent event)
    {
        return (events.contains(event));
    }

}