finished tape state machine
This commit is contained in:
		| @ -16,18 +16,19 @@ namespace VCRlogic | |||||||
|  |  | ||||||
|         public static event TapeEventHandler evOuttape; |         public static event TapeEventHandler evOuttape; | ||||||
|  |  | ||||||
|  |         public static event TapeEventHandler evEndtape; | ||||||
|  |  | ||||||
|  |         public static event TapeEventHandler evNoendtape; | ||||||
|  |  | ||||||
|  |  | ||||||
|         public static void initSMtape() |         public static void initSMtape() | ||||||
|         { |         { | ||||||
|             setState(new StapeNoTapeIn()); |             setState(new StapeNoTapeIn()); | ||||||
|  |  | ||||||
|             //evIntape += evIntape; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         public static void setState(StateTape e) |         public static void setState(StateTape e) | ||||||
|         { |         { | ||||||
|             _concreteState = null; |             _concreteState = null; | ||||||
|  |  | ||||||
|             _concreteState = e; |             _concreteState = e; | ||||||
|         } |         } | ||||||
|  |  | ||||||
| @ -46,77 +47,148 @@ namespace VCRlogic | |||||||
|             { |             { | ||||||
|                 evOuttape(); |                 evOuttape(); | ||||||
|             } |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|              |  | ||||||
|  |         public static void endTape() | ||||||
|  |         { | ||||||
|  |             if (evEndtape != null) | ||||||
|  |             { | ||||||
|  |                 evEndtape(); | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         public static void notEndTape() | ||||||
|  |         { | ||||||
|  |             if (evNoendtape != null) | ||||||
|  |             { | ||||||
|  |                 evNoendtape(); | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } |  | ||||||
|  |  | ||||||
|  |     public abstract class StateTape | ||||||
| public abstract class StateTape |  | ||||||
| { |  | ||||||
|     public abstract void evIntape(); |  | ||||||
|  |  | ||||||
|     public abstract void evOuttape(); |  | ||||||
| } |  | ||||||
|  |  | ||||||
|  |  | ||||||
| public class StapeNoTapeIn : StateTape |  | ||||||
| { |  | ||||||
|     public override void evIntape() |  | ||||||
|     { |     { | ||||||
|         Debug.Print("tape is now in\n"); |         public abstract void evIntape(); | ||||||
|  |  | ||||||
|         //unsub |         public abstract void evOuttape(); | ||||||
|         SMtape.evIntape -= evIntape; |  | ||||||
|  |  | ||||||
|         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 |             // sub to event | ||||||
| { |             SMtape.evIntape += evIntape; | ||||||
|     public override void evIntape() |         } | ||||||
|     { |         public override void evIntape() | ||||||
|     } |         { | ||||||
|  |             //unsub | ||||||
|  |             SMtape.evIntape -= evIntape; | ||||||
|  |  | ||||||
|     public override void evOuttape() |             SMtape.setState(new StapeTapeInNotEnd()); | ||||||
|     { |         } | ||||||
|         Debug.Print("tape is now out\n"); |  | ||||||
|  |  | ||||||
|         //unsub |         public override void evOuttape() | ||||||
|         SMtape.evOuttape -= evOuttape; |         { | ||||||
|         SMtape.setState(new StapeNoTapeIn()); |         } | ||||||
|  |  | ||||||
|  |         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 class StapeTapeInEnd : StateTape |  | ||||||
| { |  | ||||||
|     public override void setStateText() |  | ||||||
|     { |     { | ||||||
|         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()); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -67,12 +67,12 @@ namespace winVCR | |||||||
|  |  | ||||||
|         private void BtnNotEndTape_Click(object sender, EventArgs e) |         private void BtnNotEndTape_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|  |             SMtape.notEndTape(); | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         private void BtnEndTape_Click(object sender, EventArgs e) |         private void BtnEndTape_Click(object sender, EventArgs e) | ||||||
|         { |         { | ||||||
|  | SMtape.endTape(); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
		Reference in New Issue
	
	Block a user