2018-08-28 06:13:14 +00:00
|
|
|
package com.seodisparate.TurnBasedMinecraft.common;
|
|
|
|
|
2018-09-06 08:08:36 +00:00
|
|
|
import java.util.ArrayDeque;
|
|
|
|
import java.util.Queue;
|
2018-09-20 06:15:34 +00:00
|
|
|
import java.util.concurrent.atomic.AtomicBoolean;
|
2018-09-06 08:08:36 +00:00
|
|
|
|
2018-08-28 06:13:14 +00:00
|
|
|
public class BattleUpdater implements Runnable
|
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
private BattleManager manager;
|
2018-09-20 06:15:34 +00:00
|
|
|
private AtomicBoolean isRunning;
|
2018-08-28 06:13:14 +00:00
|
|
|
|
|
|
|
public BattleUpdater(BattleManager manager)
|
|
|
|
{
|
|
|
|
this.manager = manager;
|
2018-09-20 06:15:34 +00:00
|
|
|
isRunning = new AtomicBoolean(true);
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
2018-09-06 08:08:36 +00:00
|
|
|
Queue<Integer> endedQueue = new ArrayDeque<Integer>();
|
|
|
|
Integer ended;
|
2018-09-20 06:15:34 +00:00
|
|
|
while(isRunning.get())
|
2018-08-28 06:13:14 +00:00
|
|
|
{
|
2018-08-29 06:09:44 +00:00
|
|
|
for(Battle e : manager.battleMap.values())
|
|
|
|
{
|
2018-09-06 08:08:36 +00:00
|
|
|
if(e.update())
|
|
|
|
{
|
|
|
|
endedQueue.add(e.getId());
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 06:15:34 +00:00
|
|
|
for(ended = endedQueue.poll(); ended != null; ended = endedQueue.poll())
|
2018-09-06 08:08:36 +00:00
|
|
|
{
|
|
|
|
manager.battleMap.remove(ended);
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
try { Thread.sleep(250); } catch (Exception e) { /* ignored */ }
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
2018-08-29 06:09:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setIsRunning(boolean isRunning)
|
|
|
|
{
|
2018-09-20 06:15:34 +00:00
|
|
|
this.isRunning.set(isRunning);
|
2018-08-28 06:13:14 +00:00
|
|
|
}
|
|
|
|
}
|