Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Self Assignment input keys Demo
#3
Hi Pete
thank you for your feedback.
I find it very useful and it pulls over the development of this demo.
Here the adding for proof of user Siam Tupid.

Code: (Select All)

Rem selfdefinition of input from keyboard
DefStr S
Dim sKeyUP, sKeyDOWN, sKeyLeft, sKeyRight
_Title "Self Assignment Input Key Demo"
Print "inizialization"
KeyInit sKeyUP, sKeyDOWN, sKeyLeft, sKeyRight
Print "keys' setup done"
_Delay 2
Xc% = 2
Yc% = 1
Cls
Locate 1, 1
sInput = sKeyUP + sKeyDOWN + sKeyLeft + sKeyRight
Print "Move the character using these keys "; sInput
Print "°";
Do
    sInp = InKey$
    If InStr(sInput, sInp) Then
        If sInp = sKeyUP Then
            If Xc% > 1 Then
                Printstring Xc%, Yc%, " "
                Xc% = Xc% - 1
                Printstring Xc%, Yc%, "°"
            End If
        ElseIf sInp = sKeyDOWN Then
            If Xc% < 25 Then
                Printstring Xc%, Yc%, " "
                Xc% = Xc% + 1
                Printstring Xc%, Yc%, "°"
            End If
        ElseIf sInp = sKeyLeft Then
            If Yc% > 1 Then
                Printstring Xc%, Yc%, " "
                Yc% = Yc% - 1
                Printstring Xc%, Yc%, "°"
            End If
        ElseIf sInp = sKeyRight Then
            If Yc% < 80 Then
                Printstring Xc%, Yc%, " "
                Yc% = Yc% + 1
                Printstring Xc%, Yc%, "°"
            End If
        End If
    End If
Loop
End



Sub Printstring (X%, Y%, sS)
    Locate X%, Y%
    Print sS;
End Sub

Sub KeyInit (sUp, sDown, sLeft, sRight)

    Do
        Print "Press the key for going UP"
        sUp = ""
        ' for dummy user or accidental wrong choice
        sUsed = ""
        Do
            sUp = InKey$
            If sUp <> "" And AlreadyUsed(sUsed, sUp) Then sUp = ""
        Loop While sUp = ""
        Print " you have choosen "; sUp
    Loop Until Confirm$ = "y"
    ' for dummy user or accidental wrong choice
    sUsed = sUp


    Do
        Print "Press the key for going DOWN"
        sDown = ""
        Do
            sDown = InKey$
            If sDown <> "" And AlreadyUsed(sUsed, sDown) Then sDown = ""
        Loop While sDown = ""
        Print " you have choosen "; sDown
    Loop Until Confirm$ = "y"
    ' for dummy user or accidental wrong choice
    sUsed = sUp + sDown


    Do
        Print "Press the key for going Left"
        sLeft = ""
        Do
            sLeft = InKey$
            If sLeft <> "" And AlreadyUsed(sUsed, sLeft) Then sLeft = ""
        Loop While sLeft = ""
        Print " you have choosen "; sLeft
    Loop Until Confirm$ = "y"
    ' for dummy user or accidental wrong choice
    sUsed = sUp + sDown + sLeft


    Do
        Print "Press the key for going Right"
        sRight = ""
        Do
            sRight = InKey$
            If sRight <> "" And AlreadyUsed(sUsed, sRight) Then sRight = ""
        Loop While sRight = ""
        Print " you have choosen "; sRight
    Loop Until Confirm$ = "y"
End Sub

Function AlreadyUsed (sUsed, sNew)
    AlreadyUsed = InStr(sUsed, sNew)
End Function

Function Confirm$
    Print "Do you  confirm your choice?  Y/N"
    sInp = ""
    While sInp = ""
        sInp = LCase$(InKey$)
        If sInp <> "" And InStr("yn", sInp) = 0 Then sInp = ""
    Wend
    Confirm$ = sInp
End Function

thanks to let me go on with this demo
Reply


Messages In This Thread
Self Assignment input keys Demo - by TempodiBasic - 10-27-2024, 01:42 AM
RE: Self Assignment input keys Demo - by Pete - 10-27-2024, 02:27 AM
RE: Self Assignment input keys Demo - by TempodiBasic - 10-27-2024, 10:23 PM
RE: Self Assignment input keys Demo - by Pete - 10-28-2024, 08:05 AM



Users browsing this thread: 2 Guest(s)