Sign in to follow this  
Followers 0
james3mg

Exercise your memory

4 posts in this topic

Clicked on a Google ad the other day that took me to www.lumosity.com/MindTeasers . They've got some fun mind exercises, and I felt like making one similar to their Memory Matrix, so I could change some of the configuration options.

It turned out fine (no animations or sounds, but the gameplay is easy enough and works well), so I just thought I'd share! You can see the options you can set in the first few lines- either change the defaults there or set the options in the .ini file (created in @workingdir when you finish your first game).

There's only one thing that doesn't work like I wanted- I really wanted the popup label between levels to have a translucent background, but GDIPlus wasn't doing it for me, and I didn't want to create an actual GUI other than the main one, so I just left it as a white background.

Have fun!

Global $iShapesBegin=IniRead(@WorkingDir&"\MemoryConfig.ini","config","iShapesBegin",3)
Global $iTurnsBegin=IniRead(@WorkingDir&"\MemoryConfig.ini","config","iTurnsBegin",10)
Global $iBoxSize=IniRead(@WorkingDir&"\MemoryConfig.ini","config","iBoxSize",50)
Global $iMemorizeMS=IniRead(@WorkingDir&"\MemoryConfig.ini","config","iMemorizeMS",1500)
Global $iFontSize=IniRead(@WorkingDir&"\MemoryConfig.ini","config","iFontSize",40)

Global $aGUISize[2]=[(Ceiling((($iShapesBegin+$iTurnsBegin)-3)/2)+3)*$iBoxSize,(Floor((($iShapesBegin+$iTurnsBegin)-3)/2)+3)*$iBoxSize]
Global $hGUI=GUICreate("Memory",$aGUISize[0]-2,$aGUISize[1]+18)
GUISetBkColor(0x449944)
Global $hStatusBar=GUICtrlCreateLabel("Score: 0"&@TAB&"Shapes: "&$iShapesBegin&"/"&$iShapesBegin&@TAB&"Rounds left: "&$iTurnsBegin&@TAB&"Personal best: "&IniRead(@WorkingDir&"\MemoryConfig.ini","Scores",$iShapesBegin&"-"&$iTurnsBegin,"0"),0,$aGUISize[1],$aGUISize[0],20)
GUICtrlSetBkColor(-1,0xCCCCCC)
GUISetState(@SW_SHOW,$hGUI)

While 1
    Global $iShapes=$iShapesBegin, $iScore=0
    For $iTurns=$iTurnsBegin To 0 Step -1
        GUICtrlSetData($hStatusBar,"Score: "&$iScore&@TAB&"Shapes: "&$iShapes&"/"&$iShapes&@TAB&"Rounds left: "&$iTurns&@TAB&"Personal best: "&IniRead(@WorkingDir&"\MemoryConfig.ini","Scores",$iShapesBegin&"-"&$iTurnsBegin,"0"))
        Message($iShapes&" boxes")
        Local $iCols=Ceiling(($iShapes-3)/2)+3
        Local $iRows=Floor(($iShapes-3)/2)+3
        Local $aBoxes[$iCols][$iRows][2]
        Local $aBaseCoord[2]=[$aGUISize[0]/2-.5*$iBoxSize*$iCols,$aGUISize[1]/2-.5*$iBoxSize*$iRows]
        Local $iNumPicked=0
        Do
            $iX=Random(0,$iCols-1,1)
            $iY=Random(0,$iRows-1,1)
            If $aBoxes[$iX][$iY][1]<>"y" Then
                $iNumPicked+=1
                $aBoxes[$iX][$iY][1]="y"
                $aBoxes[$iX][$iY][0]=GUICtrlCreateLabel("",$aBaseCoord[0]+($iX*$iBoxSize),$aBaseCoord[1]+($iY*$iBoxSize),$iBoxSize-2,$iBoxSize-2)
                GUICtrlSetBkColor(-1,0x000000)
                GUICtrlSetFont(-1,$iFontSize,Default,Default,"Wingdings")
                GUICtrlSetColor(-1,0xFF0000)
            EndIf
        Until $iNumPicked=$iShapes
        For $iX=0 To $iCols-1
            For $iY=0 To $iRows-1
                If $aBoxes[$iX][$iY][1]<>"y" Then
                    $aBoxes[$iX][$iY][1]="n"
                    $aBoxes[$iX][$iY][0]=GUICtrlCreateLabel("",$aBaseCoord[0]+$iX*$iBoxSize,$aBaseCoord[1]+$iY*$iBoxSize,$iBoxSize-2,$iBoxSize-2)
                    GUICtrlSetBkColor(-1,0xFFFFFF)
                    GUICtrlSetFont(-1,$iFontSize,Default,Default,"Wingdings")
                    GUICtrlSetColor(-1,0xFF0000)
                EndIf
            Next
        Next
        $hTimer=TimerInit()
        While 1
            Sleep(15)
            If GUIGetMsg()=-3 Then Exit
            If TimerDiff($hTimer)>$iMemorizeMS Then ExitLoop
        WEnd
        For $iX=0 To $iCols-1
            For $iY=0 To $iRows-1
                If $aBoxes[$iX][$iY][1]="y" Then GUICtrlSetBkColor($aBoxes[$iX][$iY][0],0xFFFFFF)
            Next
        Next
        Local $iNumCorrect=0
        While 1
            Sleep(15)
            Local $msg=GUIGetMsg()
            If $msg=-3 Then Exit
            If $msg<0 Then ContinueLoop
            For $iX=0 To $iCols-1
                For $iY=0 To $iRows-1
                    If $aBoxes[$iX][$iY][0]=$msg Then
                        If $aBoxes[$iX][$iY][1]="y" Then
                            GUICtrlSetBkColor($aBoxes[$iX][$iY][0],0x000000)
                            $aBoxes[$iX][$iY][1]=""
                            $iNumCorrect+=1
                            $iScore+=100
                            GUICtrlSetData($hStatusBar,"Score: "&$iScore&@TAB&"Shapes: "&$iShapes-$iNumCorrect&"/"&$iShapes&@TAB&"Rounds left: "&$iTurns&@TAB&"Personal best: "&IniRead(@WorkingDir&"\MemoryConfig.ini","Scores",$iShapesBegin&"-"&$iTurnsBegin,"0"))
                        ElseIf $aBoxes[$iX][$iY][1]="n" Then;wrong box clicked: start over on this level
                            GUICtrlSetData($aBoxes[$iX][$iY][0],"N");crossbones
                            If $iShapes > $iShapesBegin Then $iShapes-=1
                            For $_iX=0 To $iCols-1
                                For $_iY=0 To $iRows-1
                                    If $aBoxes[$_iX][$_iY][1]="y" Then GUICtrlSetBkColor($aBoxes[$_iX][$_iY][0],0xFF0000)
                                Next
                            Next
                            Sleep($iMemorizeMS)
                            For $_iX=0 To $iCols-1
                                For $_iY=0 To $iRows-1
                                    GUICtrlDelete($aBoxes[$_iX][$_iY][0])
                                Next
                            Next
                            ExitLoop 3
                        EndIf
                    EndIf
                Next
            Next
            If $iNumCorrect=$iShapes Then;all shapes clicked for this level
                For $_iX=0 To $iCols-1
                    For $_iY=0 To $iRows-1
                        If $aBoxes[$_iX][$_iY][1]="" Then GUICtrlSetData($aBoxes[$_iX][$_iY][0],"C");thumbs-up
                    Next
                Next
                $iScore+=$iShapes*100
                GUICtrlSetData($hStatusBar,"Score: "&$iScore&@TAB&"Shapes: "&$iShapes-$iNumCorrect&"/"&$iShapes&@TAB&"Rounds left: "&$iTurns&@TAB&"Personal best: "&IniRead(@WorkingDir&"\MemoryConfig.ini","Scores",$iShapesBegin&"-"&$iTurnsBegin,"0"))
                Message("Perfect! +"&$iShapes*100&" points")
                $iShapes+=1
                For $_iX=0 To $iCols-1
                    For $_iY=0 To $iRows-1
                        GUICtrlDelete($aBoxes[$_iX][$_iY][0])
                    Next
                Next
                ExitLoop
            EndIf
        WEnd
    Next

    If IniRead(@WorkingDir&"\MemoryConfig.ini","Scores",$iShapesBegin&"-"&$iTurnsBegin,0)<$iScore Then
        IniWrite(@WorkingDir&"\MemoryConfig.ini","Scores",$iShapesBegin&"-"&$iTurnsBegin,$iScore)
        Message("Game over"&@CRLF&@CRLF&"New HIGH SCORE: "&$iScore,0)
    Else
        Message("Game over"&@CRLF&@CRLF&"Score: "&$iScore,0)
    EndIf
    If MsgBox(4+32,"Play again?","Would you like to play again?")=7 Then Exit
    For $_iX=0 To $iCols-1
        For $_iY=0 To $iRows-1
            GUICtrlDelete($aBoxes[$_iX][$_iY][0])
        Next
    Next
WEnd

Func Message($_sMsg,$_bTimeout=1)
    Local $_tmp=GUICtrlCreateLabel(@CRLF&$_sMsg,$aGUISize[0]/2-100,$aGUISize[1]/2-70,200,140,0x1)
    GUICtrlSetBkColor(-1,0xFFFFFF)
    GUICtrlSetFont(-1,16,600,2,"Swis721 BlkCn BT",5)
    If $_bTimeout=1 Then
        Sleep($iMemorizeMS)
        GUICtrlDelete($_tmp)
    EndIf
EndFunc

"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites



Works good! I got 12500 the first time, then 12800.. each time I messed up one or twice.. You could add a bunch of stuff to this (sounds, better graphics, some options, zombies) but that's up to you..


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites

Glad you both like it :mellow: (though I'm not sure how logmein manages to "lose" the game :()

I thought about adding more features, but I probably won't go beyond a menu bar from which you can launch a new game or configure options- I like that it's a nice 'n small script with nary a single include file and no fileinstalls (I even figured out how to do "graphics" with only pre-installed fonts), and I'm not anxious to change from that setup for such a dinky game. Anyone else would be welcome to run with it though...

Anyway, I thought it was fun and just wanted to share. Glad you tried it out and liked it. Have a nice weekend!


"There are 10 types of people in this world - those who can read binary, and those who can't.""We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true." ~Robert Wilensky0101101 1001010 1100001 1101101 1100101 1110011 0110011 1001101 10001110000101 0000111 0001000 0001110 0001101 0010010 1010110 0100001 1101110

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0