package Algorithms.Animated;

import Model.LayeredGraphNode;

public abstract class AnimatedAlgorithm extends Thread implements AlgorithmStage {

	protected AnimationController ac;
	protected LayeredGraphNode graph;
	
	public AnimatedAlgorithm( AnimationController controller, LayeredGraphNode graph )
	{
		this.ac = controller;
		this.graph = graph;
		if( controller != null )
			start();
	}
	
	@Override
	public void run()
	{
		while( true ) // if this loop would end we could not undo steps any more
		{
			try {
				switch( ac.getNextAction() )
				{
				case FORWARD:
					System.out.println( "FORWARD" );
					forwardStep();
					break;
				case BACKWARD:
					System.out.println( "BACKWARD" );
					backwardStep();
					break;
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
				return;
			}
			
		}
	}
}
