1
1
Fork 0
mirror of https://github.com/FellippeHeitor/InForm.git synced 2024-05-12 06:50:12 +00:00
InForm/examples/MasterMindGuessTheSequence/MasterMindGuessTheSequence.bas
2024-01-11 05:36:34 +05:30

437 lines
10 KiB
QBasic
Raw Blame History

': This program was generated by
': InForm - GUI system for QB64 - Beta version 1
': Fellippe Heitor, 2016 - fellippe@qb64.org - @fellippeheitor
'-----------------------------------------------------------
$UNSTABLE:MIDI
$MIDISOUNDFONT:DEFAULT
': Controls' IDs: ------------------------------------------------------------------
DIM SHARED MasterMindGuessTheSequence AS LONG
DIM SHARED SecretSequenceLB AS LONG
DIM SHARED WriteSequenceToTestTB AS LONG
DIM SHARED ListBox1 AS LONG
DIM SHARED TestSequenceBT AS LONG
DIM SHARED HelpBT AS LONG
DIM SHARED StartBT AS LONG
DIM SHARED OptionsBT AS LONG
DIM SHARED QuitBT AS LONG
DIM SHARED HelpLB AS LONG
DIM SHARED TrackBar1 AS LONG
DIM SHARED RadioButton1 AS LONG
DIM SHARED TrackBar1LB AS LONG
DIM SHARED MusicCB AS LONG
DIM SHARED MaxSequence AS INTEGER ' it set how numbers make the sequence
DIM SHARED ResulT AS STRING
DIM SHARED ma&
'$INCLUDE:'../../InForm/InForm.bi'
'$INCLUDE:'MasterMindGuessTheSequence.frm'
'$INCLUDE:'../../InForm/InForm.ui'
': Event procedures: ---------------------------------------------------------------
SUB __UI_BeforeInit
END SUB
SUB __UI_OnLoad
RANDOMIZE TIMER
MaxSequence = 4
Caption(SecretSequenceLB) = STR$(MaxSequence) + " Digits"
Control(SecretSequenceLB).Disabled = TRUE
Control(ListBox1).Disabled = TRUE
Control(WriteSequenceToTestTB).Disabled = TRUE
Control(TestSequenceBT).Disabled = TRUE
Caption(HelpLB) = "Help:" + CHR$(10) + " Options: set difficult of game, Tutor, Music " + CHR$(10) + " Help: this info" + CHR$(10) + " Quit:exit program" + CHR$(10) + " Start: begin the game" + CHR$(10) + " Reset: restart the game" + CHR$(10) + " HOW TO PLAY: click Start, type sequence, press Enter/click Test sequence"
Control(HelpLB).Hidden = TRUE
Control(HelpLB).Disabled = TRUE
Control(HelpLB).WordWrap = TRUE
Control(TrackBar1).Value = 4
Control(TrackBar1).HasBorder = TRUE
Control(TrackBar1).BorderColor = _RGB32(0, 255, 127)
Caption(TrackBar1) = LTRIM$(STR$(MaxSequence))
Control(TrackBar1).ForeColor = _RGB32(0, 0, 255)
Control(TrackBar1).Disabled = TRUE
Caption(RadioButton1) = "Tutor"
Control(RadioButton1).Disabled = TRUE
Caption(TrackBar1LB) = LTRIM$(STR$(MaxSequence))
ma& = _SNDOPEN("mozart_-_Turkish_March_in_Bb.mid")
Control(MusicCB).Disabled = TRUE
END SUB
SUB __UI_BeforeUpdateDisplay
END SUB
SUB __UI_BeforeUnload
END SUB
SUB VictorY
Caption(SecretSequenceLB) = "YOU GOT IT. YOU WIN!!"
BEEP
_DELAY 2
BEEP
Caption(StartBT) = "Start"
ResetList ListBox1
Control(SecretSequenceLB).Disabled = TRUE
Control(ListBox1).Disabled = TRUE
Control(WriteSequenceToTestTB).Disabled = TRUE
Control(TestSequenceBT).Disabled = TRUE
Caption(SecretSequenceLB) = ""
Text(SecretSequenceLB) = ""
Control(RadioButton1).Value = FALSE
END SUB
SUB CheckInput (stringa AS STRING)
DIM Goal AS STRING, z AS STRING, x AS STRING, visto AS STRING
DIM a AS INTEGER, b AS INTEGER
Goal = Text(SecretSequenceLB) 'sequence made at random at each start pushing and put in Text(iD) array
ResulT = " ": a = 0: b = 0: z = "": x = ""
visto = ""
Goal = Text(SecretSequenceLB)
IF stringa = Goal THEN
VictorY
EXIT SUB
END IF
FOR a = 1 TO MaxSequence
z = MID$(stringa, a, 1)
b = INSTR(1, Goal, z) ' z is in SecretSequenceLB
' if it is in the secret sequence then if it is at right place we get a X otherwise we get an O
IF b > 0 THEN
' if position of z in stringa is the same in Text(secretSequenceLB) we get X otherwise we get O z is in Text(secretSequenceLB) but in different position
IF INSTR(1, visto, z) = 0 THEN IF b = a THEN ResulT = ResulT + "X" ELSE ResulT = ResulT + "O"
ELSE
IF Control(RadioButton1).Value = TRUE THEN ResulT = ResulT + "-"
END IF
visto = visto + z
NEXT
IF Control(RadioButton1).Value = FALSE THEN IF LEN(ResulT) < MaxSequence THEN ResulT = ResulT + STRING$(MaxSequence - LEN(ResulT) + 1, "_") ' or ,"?") or ,"<22>")
AddItem ListBox1, stringa + "--> " + ResulT
Text(WriteSequenceToTestTB) = ""
ResulT = " "
END SUB
SUB __UI_Click (id AS LONG)
SELECT CASE id
CASE RadioButton1
CASE TrackBar1LB
CASE MusicCB
CASE MasterMindGuessTheSequence
CASE SecretSequenceLB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
IF LEN(Text(WriteSequenceToTestTB)) >= MaxSequence THEN
Text(WriteSequenceToTestTB) = LEFT$(Text(WriteSequenceToTestTB), MaxSequence)
CheckInput Text(WriteSequenceToTestTB)
ELSE
BEEP
Caption(SecretSequenceLB) = "Add " + STR$(MaxSequence - LEN(Text(WriteSequenceToTestTB))) + " Digits"
_DELAY 3
BEEP
Caption(SecretSequenceLB) = LTRIM$(STR$(MaxSequence)) + " Digits"
END IF
CASE HelpBT
Control(HelpLB).Hidden = FALSE
Control(HelpLB).Disabled = FALSE
CASE StartBT
IF Caption(StartBT) = "Start" THEN
Caption(StartBT) = "Reset"
Control(SecretSequenceLB).Disabled = FALSE
Control(ListBox1).Disabled = FALSE
Text(WriteSequenceToTestTB) = ""
Control(WriteSequenceToTestTB).Disabled = FALSE
Control(TestSequenceBT).Disabled = FALSE
CreateListToCheck
Caption(SecretSequenceLB) = STR$(MaxSequence) + " Digits" 'Text(SecretSequenceLB) ' debug statement
ELSE
Caption(StartBT) = "Start"
ResetList ListBox1
Control(SecretSequenceLB).Disabled = TRUE
Text(WriteSequenceToTestTB) = ""
Control(ListBox1).Disabled = TRUE
Control(WriteSequenceToTestTB).Disabled = TRUE
Control(TestSequenceBT).Disabled = TRUE
Caption(SecretSequenceLB) = STR$(MaxSequence) + " Digits"
Text(SecretSequenceLB) = ""
Control(RadioButton1).Value = FALSE
END IF
CASE OptionsBT
IF Control(TrackBar1).Disabled = TRUE THEN
Control(TrackBar1).Disabled = FALSE
Control(RadioButton1).Disabled = FALSE
IF ma& = 0 THEN Control(MusicCB).Disabled = TRUE ELSE Control(MusicCB).Disabled = FALSE
ELSE
Control(TrackBar1).Disabled = TRUE
Control(RadioButton1).Disabled = TRUE
Control(MusicCB).Disabled = TRUE
END IF
CASE QuitBT
SYSTEM
CASE HelpLB
Control(HelpLB).Hidden = TRUE
Control(HelpLB).Disabled = TRUE
CASE TrackBar1
END SELECT
__UI_Focus = WriteSequenceToTestTB
END SUB
SUB CreateListToCheck
Text(SecretSequenceLB) = ""
a = 0: n = -1
FOR a = 1 TO MaxSequence
DO
n = CINT(RND * 9) ' cint(rnd * (9-0)+ 0
LOOP WHILE (INSTR(Text(SecretSequenceLB), LTRIM$(STR$(n)))) ' while n is in string SecretSequenceLB it creates another sequence item
Text(SecretSequenceLB) = Text(SecretSequenceLB) + LTRIM$(STR$(n))
NEXT
END SUB
SUB __UI_MouseEnter (id AS LONG)
SELECT CASE id
CASE HelpLB
CASE TrackBar1
CASE RadioButton1
CASE TrackBar1LB
CASE MusicCB
CASE MasterMindGuessTheSequence
CASE SecretSequenceLB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_MouseLeave (id AS LONG)
SELECT CASE id
CASE HelpLB
CASE TrackBar1
CASE RadioButton1
CASE TrackBar1LB
CASE MusicCB
CASE MasterMindGuessTheSequence
CASE SecretSequenceLB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_FocusIn (id AS LONG)
SELECT CASE id
CASE TrackBar1
CASE RadioButton1
CASE MusicCB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_FocusOut (id AS LONG)
SELECT CASE id
CASE TrackBar1
CASE RadioButton1
CASE MusicCB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_MouseDown (id AS LONG)
SELECT CASE id
CASE HelpLB
CASE TrackBar1
CASE RadioButton1
CASE TrackBar1LB
CASE MusicCB
CASE MasterMindGuessTheSequence
CASE SecretSequenceLB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_MouseUp (id AS LONG)
SELECT CASE id
CASE HelpLB
CASE TrackBar1
CASE RadioButton1
CASE TrackBar1LB
CASE MusicCB
CASE MasterMindGuessTheSequence
CASE SecretSequenceLB
CASE WriteSequenceToTestTB
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_KeyPress (id AS LONG)
SELECT CASE id
CASE TrackBar1
CASE RadioButton1
CASE MusicCB
CASE WriteSequenceToTestTB
IF __UI_KeyHit = 13 THEN __UI_Click TestSequenceBT
CASE ListBox1
CASE TestSequenceBT
CASE HelpBT
CASE StartBT
CASE OptionsBT
CASE QuitBT
END SELECT
END SUB
SUB __UI_TextChanged (id AS LONG)
SELECT CASE id
CASE WriteSequenceToTestTB
Text(WriteSequenceToTestTB) = LTRIM$(Text(WriteSequenceToTestTB))
END SELECT
END SUB
SUB __UI_ValueChanged (id AS LONG)
SELECT CASE id
CASE RadioButton1
CASE ListBox1
CASE TrackBar1
MaxSequence = Control(TrackBar1).Value
ToolTip(TrackBar1) = LTRIM$(STR$(MaxSequence))
Caption(TrackBar1LB) = LTRIM$(STR$(MaxSequence))
CASE MusicCB
IF Control(MusicCB).Value = TRUE THEN _SNDLOOP ma& ELSE _SNDSTOP ma&
END SELECT
END SUB
SUB __UI_FormResized
END SUB