finished tape state machine
This commit is contained in:
		@ -16,18 +16,19 @@ namespace VCRlogic
 | 
			
		||||
 | 
			
		||||
        public static event TapeEventHandler evOuttape;
 | 
			
		||||
 | 
			
		||||
        public static event TapeEventHandler evEndtape;
 | 
			
		||||
 | 
			
		||||
        public static event TapeEventHandler evNoendtape;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public static void initSMtape()
 | 
			
		||||
        {
 | 
			
		||||
            setState(new StapeNoTapeIn());
 | 
			
		||||
 | 
			
		||||
            //evIntape += evIntape;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void setState(StateTape e)
 | 
			
		||||
        {
 | 
			
		||||
            _concreteState = null;
 | 
			
		||||
 | 
			
		||||
            _concreteState = e;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
@ -46,77 +47,148 @@ namespace VCRlogic
 | 
			
		||||
            {
 | 
			
		||||
                evOuttape();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        public static void endTape()
 | 
			
		||||
        {
 | 
			
		||||
            if (evEndtape != null)
 | 
			
		||||
            {
 | 
			
		||||
                evEndtape();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void notEndTape()
 | 
			
		||||
        {
 | 
			
		||||
            if (evNoendtape != null)
 | 
			
		||||
            {
 | 
			
		||||
                evNoendtape();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public abstract class StateTape
 | 
			
		||||
{
 | 
			
		||||
    public abstract void evIntape();
 | 
			
		||||
 | 
			
		||||
    public abstract void evOuttape();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class StapeNoTapeIn : StateTape
 | 
			
		||||
{
 | 
			
		||||
    public override void evIntape()
 | 
			
		||||
    public abstract class StateTape
 | 
			
		||||
    {
 | 
			
		||||
        Debug.Print("tape is now in\n");
 | 
			
		||||
        public abstract void evIntape();
 | 
			
		||||
 | 
			
		||||
        //unsub
 | 
			
		||||
        SMtape.evIntape -= evIntape;
 | 
			
		||||
        public abstract void evOuttape();
 | 
			
		||||
 | 
			
		||||
        SMtape.setState(new StapeTapeInNotEnd());
 | 
			
		||||
    }
 | 
			
		||||
        public abstract void evEndtape();
 | 
			
		||||
 | 
			
		||||
    public override void evOuttape()
 | 
			
		||||
    {
 | 
			
		||||
        public abstract void evNotendtape();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public StapeNoTapeIn()
 | 
			
		||||
    public class StapeNoTapeIn : StateTape
 | 
			
		||||
    {
 | 
			
		||||
        // sub to event
 | 
			
		||||
        SMtape.evIntape += evIntape;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
        public StapeNoTapeIn()
 | 
			
		||||
        {
 | 
			
		||||
            Debug.Print("NoTapeIn\n");
 | 
			
		||||
 | 
			
		||||
public class StapeTapeInNotEnd : StateTape
 | 
			
		||||
{
 | 
			
		||||
    public override void evIntape()
 | 
			
		||||
    {
 | 
			
		||||
    }
 | 
			
		||||
            // sub to event
 | 
			
		||||
            SMtape.evIntape += evIntape;
 | 
			
		||||
        }
 | 
			
		||||
        public override void evIntape()
 | 
			
		||||
        {
 | 
			
		||||
            //unsub
 | 
			
		||||
            SMtape.evIntape -= evIntape;
 | 
			
		||||
 | 
			
		||||
    public override void evOuttape()
 | 
			
		||||
    {
 | 
			
		||||
        Debug.Print("tape is now out\n");
 | 
			
		||||
            SMtape.setState(new StapeTapeInNotEnd());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //unsub
 | 
			
		||||
        SMtape.evOuttape -= evOuttape;
 | 
			
		||||
        SMtape.setState(new StapeNoTapeIn());
 | 
			
		||||
        public override void evOuttape()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evEndtape()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evNotendtape()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    public StapeTapeInNotEnd()
 | 
			
		||||
    public class StapeTapeInNotEnd : StateTape
 | 
			
		||||
    {
 | 
			
		||||
        //sub
 | 
			
		||||
        SMtape.evOuttape += evOuttape;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        public StapeTapeInNotEnd()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            Debug.Print("TapeInNotEnd\n");
 | 
			
		||||
            //sub
 | 
			
		||||
            SMtape.evOuttape += evOuttape;
 | 
			
		||||
            SMtape.evEndtape += evEndtape;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evIntape()
 | 
			
		||||
        {
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evOuttape()
 | 
			
		||||
        {
 | 
			
		||||
            //unsub
 | 
			
		||||
            SMtape.evOuttape -= evOuttape;
 | 
			
		||||
            SMtape.evEndtape -= evEndtape;
 | 
			
		||||
            SMtape.setState(new StapeNoTapeIn());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evEndtape()
 | 
			
		||||
        {
 | 
			
		||||
            //unsub
 | 
			
		||||
            SMtape.evOuttape -= evOuttape;
 | 
			
		||||
            SMtape.evEndtape -= evEndtape;
 | 
			
		||||
            SMtape.setState(new StapeTapeInEnd());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evNotendtape()
 | 
			
		||||
        {
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
       
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
public class StapeTapeInEnd : StateTape
 | 
			
		||||
{
 | 
			
		||||
    public override void setStateText()
 | 
			
		||||
    public class StapeTapeInEnd : StateTape
 | 
			
		||||
    {
 | 
			
		||||
        throw new NotImplementedException();
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
    */
 | 
			
		||||
        public StapeTapeInEnd()
 | 
			
		||||
        {
 | 
			
		||||
            Debug.Print("TapeInEnd\n");
 | 
			
		||||
            SMtape.evOuttape += evOuttape;
 | 
			
		||||
            SMtape.evNoendtape += evNotendtape;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evIntape()
 | 
			
		||||
        {
 | 
			
		||||
     
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evOuttape()
 | 
			
		||||
        {
 | 
			
		||||
            SMtape.evOuttape -= evOuttape;
 | 
			
		||||
            SMtape.evNoendtape -= evNotendtape;
 | 
			
		||||
            SMtape.setState(new StapeNoTapeIn());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evEndtape()
 | 
			
		||||
        {
 | 
			
		||||
         
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override void evNotendtape()
 | 
			
		||||
        {
 | 
			
		||||
            SMtape.evOuttape -= evOuttape;
 | 
			
		||||
            SMtape.evNoendtape -= evNotendtape;
 | 
			
		||||
            SMtape.setState(new StapeTapeInNotEnd());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user