_TITLE "Word Memory Game" ' by bplus started 2019-07-24 'This is to extend Memory Series to words and test further Button tools.
'Along with testing button tools there is an experiment here to see if 2 word pairs that make sense
'are easier to remember than match A with N and Z with M..., rather arbitrary pairings we did in last game.
REM +inder: Button Memory Game
' The goal here is 2 Fold:
' Broaden the Memory Game series to more than letters,
' And develop some potential button library procedures.
' 1. Button Type
' 2. Button Draw
' 3. Buttons Layout 'setup a whole keypad of buttons, assuming base 1 for first index
' 4. ButtonIndexClicked 'get the button index clicked, assuming base 1 for first index
' ============== Instructions: ========================================================
'This game uses QB64 keywords or symbols that have complementary word or symbol.
'Some are obvious no brainers like WHILE is paired with WEND, ( with ) and IF with THEN.
'Some might might not occur to you, eg I have DIM and AS matched up, see data statements below.
'1. Button Type common to all buttons
O
AS INTEGER 'O stands for On or Off reveal string/img of button function or keep hidden
CONST xmax
= 800, ymax
= 500, sbc
= &HFF005500, sfc
= &HFFAAAADD 'screen stuff REDIM SHARED Btn
(1 TO 1) AS ButtonType
, nBtns
'so setup can set values to these globals DIM i
, s$
, b1Index
, b2Index
, tStart!
, clickCnt
setUpGame
initRound
updateScreen
i = ButtonIndexClicked
IF i
THEN 'reveals, click counts only count if they are revealing IF b1Index
= 0 THEN 'first reveal box IF Btn
(i
).O
<> -1 THEN b1Index
= i: Btn
(i
).O
= -1: clickCnt
= clickCnt
+ 1 IF Btn
(i
).O
<> -1 THEN b2Index
= i: Btn
(i
).O
= -1: clickCnt
= clickCnt
+ 1 updateScreen
IF b2Index
<> 0 THEN 'check pair, if they are a matched pair leave them revealed IF Match
(Btn
(b1Index
).L
, Btn
(b2Index
).L
) = 0 THEN 'no match Btn(b1Index).O = 0: Btn(b2Index).O = 0
nRevealed = nRevealed - 2 'when complete = number of squares then done
updateScreen
b1Index = 0: b2Index = 0 'clear box clicks
s$
= "Completed in" + STR$(INT(TIMER(.001) - tStart!
)) + " secs and" + STR$(clickCnt
) + " clicks."
matchData:
DATA "IF THEN","DO LOOP","WHILE WEND","( )","SUB FUNCTION","SELECT CASE","OPTION _EXPLICIT","FOR NEXT" DATA "INPUT OUTPUT","X Y","LEFT$ RIGHT$","DIM AS","HELLO WORLD","CSRLIN POS","SIN COS"
IF leftOf$
(pair$
, " ") = s1$
THEN IF leftOf$
(pair$
, " ") = s2$
THEN
CLS: nRevealed
= 0 ' (shared) detect how many boxes are revealed DrawButton (i)
IF Btn
(i
).O
THEN nRevealed
= nRevealed
+ 1
SUB initRound
'reassign letters and hide them all FOR i
= nBtns
TO 2 STEP -1 ' shuffle stuff in array SWAP shuffle
(i
), shuffle
(r
) FOR i
= 1 TO nBtns
' reset or reassign values Btn(i).L = shuffle(i): Btn(i).O = 0
DIM i
, pair$
'(main) CONST xmax = 800, ymax = 300, boxSize = 50 CONST xBtns
= 5, yBtns
= 6 ' Board N x M across, down CONST spacer
= 10 ' space between buttons VVVV sets SHARED nBtns needed in lines after call LayoutButtons 0, 0, xmax, ymax, 100, 50, xBtns, yBtns, spacer, &HFFAAAAFF, &HFF000088
REDIM shuffle
(1 TO nBtns
) AS STRING ' load shuffle array for shuffling later (SHARED) FOR i
= 1 TO nBtns
STEP 2 'load shuffle with words/symbol pairs shuffle(i) = leftOf$(pair$, " "): shuffle(i + 1) = rightOf$(pair$, " ")
'2. Button draw for the index of an array Btn() of ButtonType's, assuming standard default font
LINE (Btn
(index
).X
, Btn
(index
).Y
)-STEP(Btn
(index
).W
, Btn
(index
).H
), &HFF000000, BF
LINE (Btn
(index
).X
, Btn
(index
).Y
)-STEP(Btn
(index
).W
- 3, Btn
(index
).H
- 3), &HFFFFFFFF, BF
LINE (Btn
(index
).X
+ 1, Btn
(index
).Y
+ 1)-STEP(Btn
(index
).W
- 3, Btn
(index
).H
- 3), Btn
(index
).BC
, BF
IF 8 * LEN(Btn
(index
).L
) > Btn
(index
).W
- 4 THEN 'string is too long for button s$
= MID$(Btn
(index
).L
, 1, INT((Btn
(index
).W
- 4) / 8)) 'fit part of string into button ox = 2
s$
= Btn
(index
).L: ox
= (Btn
(index
).W
- 8 * LEN(Btn
(index
).L
)) \
2 oy = (Btn(index).H - 16) \ 2
_PRINTSTRING (Btn
(index
).X
+ ox
- 1, Btn
(index
).Y
+ oy
- 1), s$
' 3. Layout buttons
' this sub will setup button locations for shared Btn() as ButtonType with first button index = 1
' also shared is nBtns whic will set/reset here
DIM xoffset
, yoffset
, xx
, yy
, xSide
, ySide
, i
nBtns = BtnsAcross * BtnsDown ' Total btns (shared) in main declares section
REDIM Btn
(1 TO nBtns
) AS ButtonType
' ready to rec data (shared) in main declares section xoffset
= INT((areaW
- btnW
* BtnsAcross
- spacer
* (BtnsAcross
- 1)) / 2) + areaX
yoffset
= INT((areaH
- btnH
* BtnsDown
- spacer
* (BtnsDown
- 1)) / 2) + areaY
xSide = btnW + spacer: ySide = btnH + spacer
FOR yy
= 1 TO BtnsDown
' set screen XY locations for all boxes i = i + 1
Btn(i).X = xoffset + (xx - 1) * xSide
Btn(i).Y = yoffset + (yy - 1) * ySide
Btn(i).W = btnW
Btn(i).H = btnH
Btn(i).FC = Fore
Btn(i).BC = Back
'4. Button Index Clicked
IF mb
THEN ' get last place mouse button was down WHILE mb
' wait for mouse button release as a "click" FOR i
= 1 TO nBtns
' now find which box was clicked IF mx
> Btn
(i
).X
AND mx
< Btn
(i
).X
+ Btn
(i
).W
THEN IF my
> Btn
(i
).Y
AND my
< Btn
(i
).Y
+ Btn
(i
).H
THEN
'old tools from toolbox