package cicaprojekt;

import java.util.Timer;
import java.util.TimerTask;

public class FlowOfTime extends Timer {

    private class GameOver extends TimerTask {
        @Override
        public void run() {
            Game.instance.stopGame(GameoverCause.TIMEOUT);
        }
    }

    private class ReplicatorAI extends TimerTask {
        @Override
        public void run()
        {
            Game.instance.moveReplicator(Direction.getRandom());
            Game.instance.updateDisplay();
        }
    }

    public void start(long delay) {
        schedule(new GameOver(), delay);
        scheduleAtFixedRate(new ReplicatorAI(), 2000, 2000);
    }

    public void stopTime() {
        cancel();
        purge();
    }
}
