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,27 +47,50 @@ 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 abstract void evEndtape(); | ||||
|  | ||||
|         public abstract void evNotendtape(); | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public class StapeNoTapeIn : StateTape | ||||
|     { | ||||
|  | ||||
|         public StapeNoTapeIn() | ||||
|         { | ||||
|             Debug.Print("NoTapeIn\n"); | ||||
|  | ||||
|             // sub to event | ||||
|             SMtape.evIntape += evIntape; | ||||
|         } | ||||
|         public override void evIntape() | ||||
|         { | ||||
|         Debug.Print("tape is now in\n"); | ||||
|  | ||||
|             //unsub | ||||
|             SMtape.evIntape -= evIntape; | ||||
|  | ||||
| @ -77,46 +101,94 @@ public class StapeNoTapeIn : StateTape | ||||
|         { | ||||
|         } | ||||
|  | ||||
|  | ||||
|     public StapeNoTapeIn() | ||||
|         public override void evEndtape() | ||||
|         { | ||||
|         // sub to event | ||||
|         SMtape.evIntape += evIntape; | ||||
|  | ||||
|         } | ||||
|  | ||||
|         public override void evNotendtape() | ||||
|         { | ||||
|  | ||||
|         } | ||||
|     } | ||||
|  | ||||
|  | ||||
|     public class StapeTapeInNotEnd : StateTape | ||||
|     { | ||||
|  | ||||
|  | ||||
|         public StapeTapeInNotEnd() | ||||
|         { | ||||
|  | ||||
|             Debug.Print("TapeInNotEnd\n"); | ||||
|             //sub | ||||
|             SMtape.evOuttape += evOuttape; | ||||
|             SMtape.evEndtape += evEndtape; | ||||
|         } | ||||
|  | ||||
|         public override void evIntape() | ||||
|         { | ||||
|         } | ||||
|  | ||||
|         public override void evOuttape() | ||||
|         { | ||||
|         Debug.Print("tape is now out\n"); | ||||
|  | ||||
|             //unsub | ||||
|             SMtape.evOuttape -= evOuttape; | ||||
|             SMtape.evEndtape -= evEndtape; | ||||
|             SMtape.setState(new StapeNoTapeIn()); | ||||
|         } | ||||
|  | ||||
|  | ||||
|     public StapeTapeInNotEnd() | ||||
|         public override void evEndtape() | ||||
|         { | ||||
|         //sub | ||||
|         SMtape.evOuttape += evOuttape; | ||||
|             //unsub | ||||
|             SMtape.evOuttape -= evOuttape; | ||||
|             SMtape.evEndtape -= evEndtape; | ||||
|             SMtape.setState(new StapeTapeInEnd()); | ||||
|         } | ||||
|  | ||||
|         public override void evNotendtape() | ||||
|         { | ||||
|              | ||||
|         } | ||||
|  | ||||
|  | ||||
|         | ||||
|     } | ||||
|  | ||||
|  | ||||
| /* | ||||
|     public class StapeTapeInEnd : StateTape | ||||
|     { | ||||
|     public override void setStateText() | ||||
|  | ||||
|         public StapeTapeInEnd() | ||||
|         { | ||||
|         throw new NotImplementedException(); | ||||
|     } | ||||
|             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()); | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -67,12 +67,12 @@ namespace winVCR | ||||
|  | ||||
|         private void BtnNotEndTape_Click(object sender, EventArgs e) | ||||
|         { | ||||
|  | ||||
|             SMtape.notEndTape(); | ||||
|         } | ||||
|  | ||||
|         private void BtnEndTape_Click(object sender, EventArgs e) | ||||
|         { | ||||
|  | ||||
| SMtape.endTape(); | ||||
|         } | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user