Finite state machine: Difference between revisions
Content added Content deleted
(Finite state machine en FreeBASIC) |
|||
Line 552: | Line 552: | ||
=={{header|FreeBASIC}}== |
=={{header|FreeBASIC}}== |
||
{{trans|Phix}} |
{{trans|Phix}} |
||
<lang freebasic> |
<lang freebasic>Enum states |
||
READY |
|||
WAITING |
|||
DISPENSE |
|||
REFUND |
|||
QUIT |
|||
End Enum '-- (or just use strings if you prefer) |
|||
Dim As states state = READY |
|||
Dim As String KBD = " " |
|||
Do |
Do |
||
Print KBD |
Print KBD |
||
Select Case state |
Select Case state |
||
Case |
Case READY |
||
Print "Machine is READY. (D)eposit or (Q)uit : "; |
Print "Machine is READY. (D)eposit or (Q)uit : "; |
||
Do |
Do |
||
Do: KBD = Ucase(Inkey): Loop While KBD = "" |
Do: KBD = Ucase(Inkey): Loop While KBD = "" |
||
If KBD = "D" Then state = |
If KBD = "D" Then state = WAITING : Exit Do |
||
If KBD = "Q" Then state = |
If KBD = "Q" Then state = QUIT : Exit Do |
||
Loop |
Loop |
||
Case |
Case WAITING |
||
Print "(S)elect product or choose to (R)efund : "; |
Print "(S)elect product or choose to (R)efund : "; |
||
Do |
Do |
||
Do: KBD = Ucase(Inkey): Loop While KBD = "" |
Do: KBD = Ucase(Inkey): Loop While KBD = "" |
||
If KBD = "S" Then state = |
If KBD = "S" Then state = DISPENSE : Exit Do |
||
If KBD = "R" Then state = |
If KBD = "R" Then state = REFUND : Exit Do |
||
Loop |
Loop |
||
Case |
Case DISPENSE |
||
Print "Dispensing product... "; |
Print "Dispensing product... "; |
||
Print "Please (C)ollect product. : "; |
Print "Please (C)ollect product. : "; |
||
Do |
Do |
||
Do: KBD = Ucase(Inkey): Loop While KBD = "" |
Do: KBD = Ucase(Inkey): Loop While KBD = "" |
||
If KBD = "C" Then state = |
If KBD = "C" Then state = READY : Exit Do |
||
Loop |
Loop |
||
Case |
Case REFUND |
||
Print "Please collect refund." |
Print "Please collect refund." |
||
state = |
state = READY |
||
KBD = " " |
KBD = " " |
||
Case |
Case QUIT |
||
Print !"Thank you, shuttingwn now.\n" |
Print !"Thank you, shuttingwn now.\n" |
||
Exit Do |
Exit Do |
||
Line 595: | Line 604: | ||
Igual que la entrada de Phix. |
Igual que la entrada de Phix. |
||
</pre> |
</pre> |
||
=={{header|Go}}== |
=={{header|Go}}== |