Achilles Posted September 1, 2007 Posted September 1, 2007 (edited) This is a game that tests your memory! It begins by showing you one color, which will then disappear. You must then match that color in the bottom half of the window and then click check. If you are right it will continue to add another color. Then you must add the two colors there are and check again. This goes on and on and on... can you win? NO!!! Requires: AutoItBugs:You can't delete or change colors you have already added to your listPlans: Add some animation and maybe sound effectsFix bugsLet the user win once the whole window is fullHave the computer tell you your score when you loose -- It doesn't tell you now --Include a small exit and minimize button in the top left of the window***This Gui was based on a 1280x1024 screen resolution, and was planned to work on any screen. As of yet I have not tested this on any computed but this so if the GUI doesn't fit right please let me know what happened and your screen resolution. ***As always please let me know of any bugs and of any suggestions or comments you may have. So far the high score is 21 which was achieved by FireLord. If you have a score higher then that please post it. ---> Important note: Escape exits the program <--- View the screen shot in the next post or go here!Also view all changes since very first edition in the next post!expandcollapse popup#include <GUIConstants.au3> #include <Misc.au3> _SingleTon('Memory Game.au3') Opt('GUICloseOnESC', 1) Opt('GUIOnEventMode', 1) Local Const $MAX_COLUMN = (@DesktopWidth - Mod(@DesktopWidth, 110)) / 110 Local Const $SLEEP_TIME = 1000 Local $COLORS[9] = ['', 0xFF0000, 0x0080FF, 0x00FF00, 0x00008A, 0x000000, 0x800080, 0xFF8000, 0xFFFF00] ;red blue green darkblue black purple orange yellow Local $playing = False Local $snapped = False Local $currentIndex = 1 Local $shadowIndex = 1 Local $currentColor = -1 Local $firstTime = True Local $dragLabel, $hoverLabel Local $dragGUI Local $correct[41] ;An array of the correct colors Local $userColor[41] ;An array of the colors the user choose Local $userLabel[41] ;An array of the labels that the user sets up Local $previewLabel[41] ;An array of the preview labels Local $colorChoices[9] $memoryGUI = GuiCreate('Memory', @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP) GuiSetOnEvent($GUI_EVENT_CLOSE, '_Exit') GuiSetBkColor(0xD5DEFF) WinSetOnTop('Memory', '', 1) $temp = '-' For $index = 1 to @DesktopWidth / 3 $temp &= '-' Next GuiCtrlCreateLabel($temp, 0, @DesktopHeight / 2 - 30, @DesktopWidth, 10) GuiCtrlCreateLabel($temp, 0, @DesktopHeight - 90, @DesktopWidth, 10) $btnNewGame = GuiCtrlCreateButton('New Game', @DesktopWidth / 2 - 100, @DesktopHeight - 60, 200, 40) GuiCtrlSetOnEvent(-1, '_NewGame') $btnCheck = GuiCtrlCreateButton('Check', @DesktopWidth / 2, @DesktopHeight - 60, 150, 40) GuiCtrlSetOnEvent(-1, '_Check') GuiCtrlSetState(-1, $GUI_HIDE) For $index = 4 to 1 Step -1 $colorChoices[5 - $index] = GuiCtrlCreateLabel('', @DesktopWidth / 2 - $index * 100 - 150, @DesktopHeight - 76, 70, 70, '', $WS_EX_STATICEDGE) GuiCtrlSetOnEvent(-1, '_ColorPicked') GuiCtrlSetBkColor(-1, $COLORS[5 - $index]) Next For $index = 5 to 8 $colorChoices[$index] = GuiCtrlCreateLabel('', @DesktopWidth / 2 + ($index - 5) * 100 + 179, @DesktopHeight - 76, 70, 70, '', $WS_EX_STATICEDGE) GuiCtrlSetOnEvent(-1, '_ColorPicked') GuiCtrlSetBkColor(-1, $COLORS[$index]) Next GuiSetState() While 1 Sleep(1000) WEnd Func _NewGame() If $firstTime then GuiCtrlSetPos($btnNewGame, @DesktopWidth / 2 - 150, @DesktopHeight - 60, 150, 40) GuiCtrlSetState($btnCheck, $GUI_SHOW) $playing = True EndIf For $index = 1 to $currentIndex GuiCtrlDelete($previewLabel[$index]) $correct[$index] = '' Next For $index = 1 to $shadowIndex GuiCtrlDelete($userLabel[$index]) $userColor[$index] = '' Next GuiCtrlDelete($hoverLabel) $currentIndex = 1 $shadowIndex = 1 _Preview() EndFunc Func _ColorPicked() If Not $playing then Return Local $grab = -1 Local $mousePos For $index = 0 to 8 If @GUI_CtrlId = $colorChoices[$index] then $grab = $index ExitLoop EndIf Next $mousePos = MouseGetPos() $dragGUI = GuiCreate('Drag', 100, 100, $mousePos[0] - 50, $mousePos[1] - 50, $WS_POPUPWINDOW) $dragLabel = GuiCtrlCreateLabel('', 0, 0, 100, 100) GuiCtrlSetOnEvent(-1, '_DropDrag') GuiCtrlSetBkColor(-1, $COLORS[$grab]) $currentColor = $COLORS[$grab] AdLibEnable('_Drag', 20) GuiSetState() WinSetOnTop('Drag', '', 1) EndFunc Func _Preview($add = True) Local $mousePos Local $newColor = $COLORS[Random(1, 8, 1)] $mousePos = MouseGetPos() _MouseTrap(@DesktopWidth, @DesktopHeight) For $index = 1 to $currentIndex -1 GuiCtrlSetState($previewLabel[$index], $GUI_SHOW) Sleep(220) Next If Not $add then GuiCtrlSetState($previewLabel[$currentIndex], $GUI_SHOW) EndIf If $add then $previewLabel[$currentIndex] = GuiCtrlCreateLabel('', _GetX($currentIndex), _GetY($currentIndex, True), 100, 100, $SS_SUNKEN, $GUI_WS_EX_PARENTDRAG) GuiCtrlSetBkColor(-1, $newColor) $correct[$currentIndex] = $newColor Sleep($SLEEP_TIME) For $index = 1 to $currentIndex GuiCtrlSetState($previewLabel[$index], $GUI_HIDE) Sleep(220) Next EndIf _MouseTrap() MouseMove($mousePos[0], $mousePos[1], 0) _Shadow() EndFunc Func _GetX($type) Local $temp = Mod(($type - 1), $MAX_COLUMN) Return $temp * 110 + 10 EndFunc Func _GetY($type, $high = False) Local $temp = ($type - 1) / $MAX_COLUMN Local $toReturn Select Case $temp < 1 $toReturn = @DesktopHeight / 2 - 12 Case $temp < 2 $toReturn = @DesktopHeight / 2 + 102 Case $temp < 3 $toReturn = @DesktopHeight / 2 + 212 Case $temp < 4 $toReturn = @DesktopHeight / 2 + 322 Case $temp < 5 $toReturn = @DesktopHeight / 2 + 432 EndSelect If $high then $toReturn -= @Desktopheight / 2 - 20 EndIf Return $toReturn EndFunc Func _DropDrag() GuiDelete($dragGUI) If $snapped then $userLabel[$shadowIndex] = GuiCtrlCreateLabel('', _GetX($shadowIndex), _GetY($shadowIndex), 100, 100, $SS_SUNKEN) GuiCtrlSetBkColor(-1, $currentColor) $userColor[$shadowIndex] = $currentColor $shadowIndex += 1 GuiCtrlDelete($hoverLabel) If $shadowIndex = 45 then Msgbox(262144, 'Error', 'There are no more spaces') Return EndIf _Shadow() EndIf EndFunc Func _Shadow() $hoverLabel = GuiCtrlCreateLabel('', _GetX($shadowIndex), _GetY($shadowIndex), 100, 100) GuiCtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) EndFunc Func _Check() Local $pass = True For $index = 1 to $currentIndex If $userColor[$index] <> $correct[$index] then $pass = False ExitLoop EndIf Next If $userColor[$currentIndex + 1] <> '' then $pass = False If $pass then $currentIndex += 1 For $index = 1 to $shadowIndex GuiCtrlDelete($userLabel[$index]) GuiCtrlDelete($hoverLabel) $shadowIndex = 1 Next _Preview() Else GuiCtrlSetState($btnCheck, $GUI_HIDE) GuictrlSetPos($btnNewGame, @DesktopWidth / 2 - 100, @DesktopHeight - 60, 200, 40) Msgbox(262144, 'Loser!', 'HAHA... Your score was ' & $currentIndex - 1) _Preview(False) EndIf EndFunc Func _Drag() Local $mousePos = MouseGetPos() Local $cursorInfo = GuiGetCursorInfo($memoryGUI) If WinExists('Drag') then If IsArray($cursorInfo) then If $cursorInfo[4] = $hoverLabel then WinMove('Drag', '', _GetX($shadowIndex), _GetY($shadowIndex)) $snapped = True Return Else $snapped = False WinMove('Drag', '', $mousePos[0] - 50, $mousePos[1] - 50) EndIf Else $snapped = False WinMove('Drag', '', $mousePos[0] - 50, $mousePos[1] - 50) EndIf EndIf EndFunc Func _Exit() Exit EndFunc Edited November 20, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Achilles Posted September 1, 2007 Author Posted September 1, 2007 (edited) Changes since original versionFixed a bug that would let you continue playing even after you loseOnce you lose it shows what the correct sequence should of beenOnce you lose it shows you your scoreScreen shot of me about to Check what I have... Edited September 1, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
JustinReno Posted November 7, 2007 Posted November 7, 2007 (edited) It looks great on a 1400x900 screen. But it doesn't work for me. Edited November 7, 2007 by JustinReno
Achilles Posted November 7, 2007 Author Posted November 7, 2007 (edited) Dethredic said: looks bad on 1024x768 screen resolution.took me a while to figure out where to drag the blocks, but I am a bit dull sometimes.I accidentally put a block in the wrong spot, and you can't put another colour over it, so I auto lost. <- FIX THATWill do! Probably next weekend though... my week days seem to be rather full. I'll also add some sort of instructions... I guess when I'm the creator I don't really think of things like that.@JustinRenoWhat looks good on a 1400x900 screen if it doesn't work? Does any of it startup at all?EDIT: If I remember right I programmed this to support any monitor type... don't have type to check now Edited November 7, 2007 by Piano_Man My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
BrettF Posted November 7, 2007 Posted November 7, 2007 First Try 9... I had the same problem as Deth... meh. Looks cool! Vist my blog!UDFs: Opens The Default Mail Client | _LoginBox | Convert Reg to AU3 | BASS.au3 (BASS.dll) (Includes various BASS Libraries) | MultiLang.au3 (Multi-Language GUIs!)Example Scripts: Computer Info Telnet Server | "Secure" HTTP Server (Based on Manadar's Server)Software: AAMP- Advanced AutoIt Media Player | WorldCam | AYTU - Youtube Uploader Tutorials: Learning to Script with AutoIt V3Projects (Hardware + AutoIt): ArduinoUseful Links: AutoIt 1-2-3 | The AutoIt Downloads Section: | SciTE4AutoIt3 Full Version!
jvanegmond Posted November 7, 2007 Posted November 7, 2007 I had no clue where to drag the blocks to, but I understood once I saw the screen shot. I like it, but I lost because I had light blue instead of dark blue. github.com/jvanegmond
Dhilip89 Posted November 7, 2007 Posted November 7, 2007 Very nice, my first time was score 13 (memory interrupted by thinking other things). [u]My Projects[/u]:General:WinShell (Version 1.6)YouTube Video Downloader Core (Version 2.0)Periodic Table Of Chemical Elements (Version 1.0)Web-Based:Directory Listing Script Written In AutoIt3 (Version 1.9 RC1)UDFs:UnicodeURL UDFHTML Entity UDF[u]My Website:[/u]http://dhilip89.hopto.org/[u]Closed Sources:[/u]YouTube Video Downloader (Version 1.3)[quote]If 1 + 1 = 10, then 1 + 1 ≠ 2[/quote]
icadea Posted November 19, 2007 Posted November 19, 2007 This is great game. I just realized that It seems the same identification structure could be used as a password replacement method. Instead of typing in the password key, You could choose to identify the colour which was preset in terms of sequence using mouse. Thanks for the idea.
FireLord Posted November 19, 2007 Posted November 19, 2007 I don't get how you play. I click on the right colors and it says that I lost. ? [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center]
FireLord Posted November 19, 2007 Posted November 19, 2007 Figured out how to get it to work. Score:21 [center]See the Helpfile[/center] While Alive() DrinkWine(); }[center][/center]
Achilles Posted November 20, 2007 Author Posted November 20, 2007 icadea said: This is great game. I just realized that It seems the same identification structure could be used as a password replacement method. Instead of typing in the password key, You could choose to identify the colour which was preset in terms of sequence using mouse.Thanks for the idea.Thanks! Glad I could help you with that idea... sounds like a good thing, I've never seen passwords represented by colours...@Firelord: I updated the original post with your high score. Good job! I'll make instructions that show how to play sometime to avoid any problems... My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
ian.b Posted May 27, 2008 Posted May 27, 2008 AutoIt community. This is my first post here, so let me THANK ALL who have made this great script language possible. Achilles, thank you for this script, I use it to verify my progress in concentration and visualization - i am not a kid anymore - i do not treat this as a competition. Quote As always please let me know of any bugs and of any suggestions or comments you may have. When i reached the score 40 yesterday, I received the error : "Array variable has incorrect number of subscripts..." to wiew the screen shot of this error message go here! I checked your code and it was caused by setting the dimensions of some arrays to 41, so it was fixed easily. I would appreciate if you could add an option [i.e.. ini file?] or inside the script to select/increase the max number of created squares. Quote a small exit and minimize button in the top left of the window This would be helpful. TIA, Best Regards ian PS. To run it with the newest version - 3.2.12.0, two new include lines must be added: #include <WindowsConstants.au3> #include <StaticConstants.au3>
ReaImDown Posted May 27, 2008 Posted May 27, 2008 Nice work...I got 12 you should add an undo button, I caught my mistake -.-' [u][font="Century Gothic"]~я α и d γ ĵ . ċ . ѕ қ ϊ и и ε я~- My Programs -auto shutdownSleep funcdisallow programs[/font][/u]
DexterMorgan Posted May 27, 2008 Posted May 27, 2008 Pretty cool... I can only get up to 4.. Lol code
ian.b Posted May 28, 2008 Posted May 28, 2008 Achilles Quote As always please let me know of any bugs and of any suggestions or comments you may have. I was unable to edit my previous post.Just in case you would like to enhance your scrip i would suggest to add:"Double click" possibility - it could speed it up - especially when score is high - my last was 43 - i wanted to "verify" my previous result option for different "direction" of the game - from right to left, top-down, down-top TIAianPS.I hope it does not sound too childish
Achilles Posted May 30, 2008 Author Posted May 30, 2008 Thanks for the comments, I haven't worked on this script for quite a while. @ian.b: Thanks for your suggestions, I'll look into them as soon as I get the time. My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now