smstroble Posted November 21, 2006 Share Posted November 21, 2006 (edited) Working on a Diamond Mine like project, so far this is what i have.expandcollapse popup#include <GuiConstants.au3> #include <Array.au3> HotKeySet("{F6}", "newgame") HotKeySet("{ESC}", "quit") #region User controlled variables, change these at will to make changes w/o changing lots of code ;$Defaultgemtype = "New" $Defaultgemtype = IniRead("Settings.ini", "Default", "GemType", "Default") ;Default gem Type $BoardSizeX = IniRead("Settings.ini", "Default", "SizeX", 8) ;how many gems wide? $BoardSizeY = IniRead("Settings.ini", "Default", "SizeY", 8) ;how many gems tall? $GemSize = 29 ;Size in pixles of the gems $BoardOffsetTop = -5 ;Offsets may need to be changed to compensate for cganhes in gem size/window size $BoardOffsetLeft = 150 ;Note: changes in boardsize & gem size auto rezise window #endregion #region Internal Variables leave these alone DIM $gemtypes[100][2] DIM $box[40][40] Dim $gem[40][40] Dim $undogem[40][40] DIM $gonegems[100][2][2] $gonegems[0][0][0] = 0 DIM $temp[4][2][2] Dim $sel1[3] DIM $gem1[40][40] $sel1[0] = "" Dim $sel2[3] $sel2[0] = "" $gemtype = $Defaultgemtype $highscore = 0 $totalscore = 0 $collapsescore = 0 $fileexit = 0 $filenewgame = 0 $score = 0 $fileexit = 0 $gemsreal = 0 $gemsnew = 0 $gemsold = 0 $filesave = 0 $fileload = 0 $undototalscore = 0 $chk = 0 $UNDO = 0 #endregion GUI() Func GUI() ;Create GUI $main = GUICreate("Gems For AU3", (190+($BoardSizeX* ($GemSize+1))), ($BoardSizeY* ($GemSize+1))+60, 200, 200) #region Game Board If FileExists("lastgame.sgm") Then ;If lastgame was saved call loadgame Loadgame() Else ;If not randomly generate gems, 10X20, into $gems array For $i = 1 To $BoardSizeY For $u = 1 To $BoardSizeX $gem[$i][$u] = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" Next Next EndIf For $i = 1 To $BoardSizeY ;Create Gem picture grid from generated/loaded $gems array For $u = 1 To $BoardSizeX $box[$i][$u]= GUICtrlCreatePic($gem[$i][$u], (($u * ($GemSize+1)) +$BoardOffsetLeft), ($i * ($GemSize+1)) + $BoardOffsetTop , $GemSize, $GemSize) Next Next #endregion Game Board #region Menu $file = GUICtrlCreateMenu("File") $filenewgame = GUICtrlCreateMenuitem("New Game", $file) $filesave = GUICtrlCreateMenuitem("Save Game", $file) $fileload = GUICtrlCreateMenuitem("Load Game", $file) $highscore = GUICtrlCreateMenuitem("High Score", $file) $fileexit = GUICtrlCreateMenuitem("Exit", $file) $opt = GUICtrlCreateMenu("Options") $gemsmenu = GUICtrlCreateMenu("Gem Type", $opt) $gemsearch = FileFindFirstFile(@ScriptDir & "\gems\*") While 1 $gemtypes[$gemtypes[0][0]+1][0] = FileFindNextFile($gemsearch) If @error Then ExitLoop EndIf $gemtypes[$gemtypes[0][0]+1][1] = GUICtrlCreateMenuitem($gemtypes[$gemtypes[0][0]+1][0], $gemsmenu) $gemtypes[0][0] += 1 WEnd ;$gemsreal = GUICtrlCreateMenuitem("Real Gems", $gemsmenu) ;$gemsnew = GUICtrlCreateMenuitem("New Gems", $gemsmenu) ;$gemsold = GUICtrlCreateMenuitem("Old Gems", $gemsmenu) $Help = GUICtrlCreateMenu("Help") $helphelp = GUICtrlCreateMenuitem("Help", $help) GUICtrlSetState(-1, @SW_DISABLE) #endregion Menu ;Line around playing area GUICtrlCreateGroup("", 169, 10, ($BoardSizeX*($GemSize+1))+17, ($BoardSizeY*($GemSize+1)+25)) ;Line around score area GUICtrlCreateGroup("", 7, 90, 150, 35) ;Score GUICtrlCreateLabel("Score:", 10, 100) $score = GUICtrlCreateLabel($totalscore, 55, 100, 100) ;Undo Button $UNDO = GUICtrlCreateButton("UNDO!!", 55, 200, 60, 30) GUISetState() chkallformatchs() ;Make shure there are no pre-existing matchs main() ;call GUI $msg loop EndFunc Func HighScoreBox() $HSGUI = GUICreate("HighScores", 130, 160) For $i = 1 to 10 $Name = IniRead("HighScore.ini", "HighScore", "Name" & $i, "") $Score = IniRead("HighScore.ini", "HighScore", "Score" & $i, "") GUICtrlCreateLabel($Name & ": " & $Score, 2, 2+(($i-1)*15), 146) Next GUISetState() While 1 $HSmsg = GUIGetMsg() If $HSmsg = $GUI_EVENT_CLOSE Then GUIDelete($HSGUI) Return(0) EndIf WEnd EndFunc Func main() ;GUI msg loop nomovechker() ;check to see if there are no moves While 1 ;$msg loop $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE OR $msg = $fileexit Then Savegame() Exit ElseIf $msg = $highscore Then ;Open High Score box HighScoreBox() ElseIf $msg = $UNDO Then ;Undo undo() ElseIf $msg = $filenewgame Then ;New game newgame() $totalscore = 0 GUICtrlSetData($score, "0") ElseIf $msg = $filesave Then ;Save current game $filename = FileSaveDialog("Create Saved Game File", @ScriptDir, "SGM File (*.sgm)", 18, "save.sgm") ;choose file savegame($filename);save ElseIf $msg = $fileload Then ;load game $filename = FileOpenDialog("Select Saved Game File", @ScriptDir, "SGM File (*.sgm)", 3, "save.sgm") ;choose file Loadgame($filename);load EndIf If $msg > 0 Then ;saves LOTS OF CPU For $i = 1 to $gemtypes[0][0] If $msg = $gemtypes[$i][1] Then changegems($gemtypes[$i][0]) EndIf Next For $x = 1 to $BoardSizeY ;20 rows For $y = 1 To $BoardSizeX ;10 colums If $msg = $box[$x][$y] Then ;if gem was clicked If $sel1[0] = "" Then ;if no gem has been selected, clicked gem is now selected $sel1[0] = $gem[$x][$y] $sel1[1] = $x $sel1[2] = $y $gemnum = StringMid($gem[$x][$y], StringLen($gem[$x][$y]) - 4, 1) GUICtrlSetImage($box[$x][$y], "Gems\" & $gemtype & "\Image1" & $gemnum & ".jpg") Else ;if a gem has been selected, swap selected and clicked gems, perform logic $sel2[0] = $gem[$x][$y] $sel2[1] = $x $sel2[2] = $y If (($sel2[1] = $sel1[1]+1) AND ($sel2[2] = $sel1[2])) OR (($sel2[1] = $sel1[1]-1) AND ($sel2[2] = $sel1[2])) _ OR (($sel2[2] = $sel1[2]+1) AND ($sel2[1] = $sel1[1])) OR (($sel2[2] = $sel1[2]-1) AND ($sel2[1] = $sel1[1])) Then ;make shure you clicked a gem bordering the first clicked gem $undogem = $gem ;backup gem positions for undo button $undototalscore = $totalscore ;backup score for undo button $gem[$sel1[1]][$sel1[2]] = $sel2[0] ;swap 1st gem in beckend array GUICtrlSetImage($box[$sel1[1]][$sel1[2]], $sel2[0]);makes 1st sel gem 2nd sel gem $gem[$sel2[1]][$sel2[2]] = $sel1[0] ;swap 2nd gem in backend array GUICtrlSetImage($box[$sel2[1]][$sel2[2]], $sel1[0]);makes 2nd sel gem 1st sel gem Global $oops = 1 chkformatch($sel1[1], $sel1[2], $sel2[1] , $sel2[2]) ;check if anymatches created If $oops Then ;if no matches created reverse gem swap Sleep(200) ;gives em time to realize their error $gem[$sel1[1]][$sel1[2]] = $sel1[0];reverse 1st gem in array GUICtrlSetImage($box[$sel1[1]][$sel1[2]], $sel1[0]);reverse 1st gem $gem[$sel2[1]][$sel2[2]] = $sel2[0];reverse 2nd gem in array GUICtrlSetImage($box[$sel2[1]][$sel2[2]], $sel2[0]);reverse 2nd gem Else ;If a match was found and proccessed, check for no moves nomovechker() EndIf Else ;if selected and clicked gems are not adjacent deselect selected gem $gemnum = StringMid($gem[$sel1[1]][$sel1[2]], StringLen($gem[$sel1[1]][$sel1[2]]) - 4, 1) GUICtrlSetImage($box[$sel1[1]][$sel1[2]], "Gems\" & $gemtype & "\Image" & $gemnum & ".jpg") EndIf $sel1[0] = "" ;resets selected and clicked gems $sel2[0] = "" EndIf EndIf Next Next EndIf WEnd EndFunc Func Savegame($filename = "lastgame.sgm") For $i = 1 To $BoardSizeY For $u = 1 To $BoardSizeX IniWrite($filename, "GemPos", $i & "," & $u, $gem[$i][$u]);Write each gem filename to save file by position Next Next IniWrite($filename, "Score", "Current", $totalscore) ;write score to save file IniWrite($filename, "GemType", "Current", $gemtype) ;write gemtype to save file Return(0) EndFunc Func Loadgame($filename = "lastgame.sgm") For $i = 1 To $BoardSizeY For $u = 1 To $BoardSizeX $gem[$i][$u] = IniRead($filename, "GemPos", $i & "," & $u, 0) ;load gems from save into $gems array Next Next $totalscore = IniRead($filename, "Score", "Current", 0) ;load score into variable $gemtype = IniRead($filename, "GemType", "Current", $gemtype) ;load gemtype into variable If $filename <> "lastgame.sgm" Then For $i = 1 To 20 For $u = 1 To 10 GUICtrlSetImage($box[$i][$u], $gem[$i][$u]) ;set images with loaded $gem array Next Next EndIf Return(0) EndFunc Func newgame() For $i = 1 To $BoardSizeY For $u = 1 To $BoardSizeX $gem[$i][$u] = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" GUICtrlSetImage($box[$i][$u], $gem[$i][$u]) ;Sel the image of the generated gem Next Next $totalscore = 0 ;reset score GUICtrlSetData($score, $totalscore) ;reset GUI score chkallformatchs() ;make shure no matches were randomly created EndFunc Func Undo() $totalscore = $undototalscore ;load backup score into variable GUICtrlSetData($score, $totalscore) ;display new score For $i = 1 To $BoardSizeY For $u = 1 To $BoardSizeX If $gem[$i][$u] <> $undogem[$i][$u] Then ;if a gem in the backup array is diffrent then a gem in the current array $gem[$i][$u] = $undogem[$i][$u] ;replace it GUICtrlSetImage($box[$i][$u], $gem[$i][$u]); display the changed gem EndIf Next Next EndFunc Func changegems($newgemtype); change from Real to New to Old etc. For $i = 1 To $BoardSizeY For $u = 1 To $BoardSizeX $gem[$i][$u] = StringReplace($gem[$i][$u], $gemtype, $newgemtype) ;replace real with new in pic file names GUICtrlSetImage($box[$i][$u], $gem[$i][$u]) ;reload new image Next Next $gemtype = $newgemtype ;update gemtype variable EndFunc Func chkallformatchs() ;checks entire board for pre existing matches and breaks them ;----------- ;Incase you were wondering, yes this method could work for chkformatch and vise vera ;BUT i couldent get scoring to work this way ;and this way is faster making it better for backend stuff (same thing for nomovechker) ;---------- $chk = 0 For $y1 = 1 to $BoardSizeY For $x1 = 1 To $BoardSizeY If $gem[$y1][$x1] = $gem[$y1][($x1+1)] AND $gem[$y1][$x1] = $gem[$y1][($x1-1)] Then;gem matchs gems on each side $newgem = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem ;replace gem in array w/ new gem GUICtrlSetImage($box[$y1][$x1], $newgem) ;display new gem $chk = 1 EndIf If $gem[$y1][$x1] = $gem[$y1][($x1+1)] AND $gem[$y1][$x1] = $gem[$y1][($x1+2)] Then;gem matchs 2 gems on right $newgem = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[$y1][$x1] = $gem[$y1][($x1-1)] AND $gem[$y1][$x1] = $gem[$y1][($x1-2)] Then;gem matchs 2 gems on left $newgem = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[($y1+1)][$x1] = $gem[$y1][$x1] AND $gem[($y1-1)][$x1] = $gem[$y1][$x1] Then;gem matchs above and below gems $newgem = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[($y1+1)][$x1] = $gem[$y1][$x1] AND $gem[($y1+2)][$x1] = $gem[$y1][$x1] Then;gem matchs 2 gems below $newgem = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[$y1-1][$x1] = $gem[$y1][$x1] AND $gem[($y1-2)][$x1] = $gem[$y1][$x1] Then;gem matchs 2 gems above $newgem = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $chk Then ;I think this sets the check back a spot to verify that the change broke the match If $y1 > 1 Then $y1 = $y1 - 1 $chk = 0 ElseIf $x1 > 2 Then $x1 = $x1 - 1 $chk = 0 Else $chk = 0 EndIf EndIf Next Next nomovechker() EndFunc Func chkformatch($y1, $x1, $y2, $x2) ;check for created match after gems are moved by user $chk = 0 $matchlen = 0 Global $gem1 = $gem ;load gem array into gem1 array for processing #region Virticle Primary If $gem1[$y2][$x2] = $gem[$y2+1][$x2] Then ;if gem matched gem below it $matchlen += 2 ;match length for scoring purposes If $gem1[$y2][$x2] = $gem[$y2+2][$x2] Then ;if gem matched gem below that $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2+3][$x2] Then ;if gem matched gem below that $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2+4][$x2] Then ;if gem matched gem below that $matchlen += 1 Gemmatch($y2, $x2, $y2 + 1, $x2, $y2 +2, $x2, $y2 +3, $x2, $y2 +4, $x2) ;clear 5 matching gems Else Gemmatch($y2, $x2, $y2 + 1, $x2, $y2 +2, $x2, $y2 +3, $x2) ;clear 4 matching gems EndIf ElseIf $gem1[$y2][$x2] = $gem[$y2-1][$x2] AND $y2-1 > 0 Then ;if 3rd gem down failed but gem above is a match $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2-2][$x2] AND $y2-2 > 0 Then ;and the gem above that a match Gemmatch($y2, $x2, $y2 +1, $x2, $y2 +2, $x2, $y2 -1, $x2, $y2 -2, $x2) ;clear 5 gems Else Gemmatch($y2, $x2, $y2 +1, $x2, $y2 +2, $x2, $y2 -1, $x2) ;clear 4 gems EndIf Else Gemmatch($y2, $x2, $y2 + 1, $x2, $y2 +2, $x2) ; clear 3 gems EndIf ElseIf $gem1[$y2][$x2] = $gem[$y2-1][$x2] AND $y2-1 > 0 Then ;if 2nd gem down failed but gem above is a match $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2-2][$x2] AND $y2-2 > 0 Then ;and the one above that $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2-3][$x2] AND $y2-3 > 0 Then ;and above that $matchlen += 1 Gemmatch($y2, $x2, $y2 +1, $x2, $y2 -1, $x2, $y2 -2, $x2, $y2 -3, $x2) ;clear 5 matching gems Else Gemmatch($y2, $x2, $y2 +1, $x2, $y2 -1, $x2, $y2 -2, $x2) ;clear 4 matching gems EndIf Else Gemmatch($y2, $x2, $y2 +1, $x2, $y2 -1, $x2); clear three matching gems EndIf EndIf ElseIf $gem1[$y2][$x2] = $gem[$y2-1][$x2] AND $y2-1 > 0 Then ;if no matches below but a match above and is is a gem in the playing area $matchlen += 2 If $gem1[$y2][$x2] = $gem[$y2-2][$x2] AND $y2-2 > 0 Then ;if a match above that and is is a gem in the playing area $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2-3][$x2] AND $y2-3 > 0 Then ;if a match above that and is is a gem in the playing area $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2-4][$x2] AND $y2-4 > 0 Then ;if a match above that and is is a gem in the playing area $matchlen += 1 Gemmatch($y2, $x2, $y2 -1, $x2, $y2 -2, $x2, $y2 -3, $x2, $y2 -4, $x2) ;clear 5 matching gems Else Gemmatch($y2, $x2, $y2 -1, $x2, $y2 -2, $x2, $y2 -3, $x2) ;clear 4 matching gems EndIf Else Gemmatch($y2, $x2, $y2 -1, $x2, $y2 -2, $x2) ;clear three mathcing gems EndIf EndIf EndIf #endregion #region Vertical Secondary ;SEE ABOVE, im not doing all the commenting again lol If $gem1[$y1][$x1] = $gem[$y1+1][$x1] Then $matchlen += 2 If $gem1[$y1][$x1] = $gem[$y1+2][$x1] Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1+3][$x1] Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1+4][$x1] Then $matchlen += 1 Gemmatch($y1, $x1, $y1 + 1, $x1, $y1 +2, $x1, $y1 +3, $x1, $y1 +4, $x1) Else Gemmatch($y1, $x1, $y1 + 1, $x1, $y1 +2, $x1, $y1 +3, $x1) EndIf ElseIf $gem1[$y1][$x1] = $gem[$y1-1][$x1] AND $y2-1 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1-2][$x1] AND $y2-2 > 0 Then Gemmatch($y1, $x1, $y1 +1, $x1, $y1 +2, $x1, $y1 -1, $x1, $y1 -2, $x1) Else Gemmatch($y1, $x1, $y1 +1, $x1, $y1 +2, $x1, $y1 -1, $x1) EndIf Else Gemmatch($y1, $x1, $y1 + 1, $x1, $y1 +2, $x1) EndIf ElseIf $gem1[$y1][$x1] = $gem[$y1-1][$x1] AND $y2-1 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1-2][$x1] AND $y2-2 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1-3][$x1] AND $y2-3 > 0 Then $matchlen += 1 Gemmatch($y1, $x1, $y1 +1, $x1, $y1 -1, $x1, $y1 -2, $x1, $y1 -3, $x1) Else Gemmatch($y1, $x1, $y1 +1, $x1, $y1 -1, $x1, $y1 -2, $x1) EndIf Else Gemmatch($y1, $x1, $y1 +1, $x1, $y1 -1, $x1) EndIf Else $matchlen -= 2 EndIf ElseIf $gem1[$y1][$x1] = $gem[$y1-1][$x1] AND $y2-1 > 0 Then $matchlen += 2 If $gem1[$y1][$x1] = $gem[$y1-2][$x1] AND $y2-2 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1-3][$x1] AND $y2-3 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1-4][$x1] AND $y2-4 > 0 Then $matchlen += 1 Gemmatch($y1, $x1, $y1 -1, $x1, $y1 -2, $x1, $y1 -3, $x1, $y1 -4, $x1) Else Gemmatch($y1, $x1, $y1 -1, $x1, $y1 -2, $x1, $y1 -3, $x1) EndIf Else Gemmatch($y1, $x1, $y1 -1, $x1, $y1 -2, $x1) EndIf Else $matchlen -= 2 EndIf EndIf #endregion #region Hoizontal Primary If $gem1[$y2][$x2] = $gem[$y2][$x2+1] Then $matchlen += 2 If $gem1[$y2][$x2] = $gem[$y2][$x2+2] Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2+3] Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2+4] Then $matchlen += 1 Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 +2, $y2, $x2 +3, $y2, $x2 +4) Else Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 +2, $y2, $x2 +3) EndIf ElseIf $gem1[$y2][$x2] = $gem[$y2][$x2-1] AND $x2-1 > 0 Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2-2] AND $x2-2 > 0 Then Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 +2, $y2, $x2 -1, $y2, $x2 -2) Else Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 +2, $y2, $x2 -1) EndIf Else Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 +2) EndIf ElseIf $gem1[$y2][$x2] = $gem[$y2][$x2-1] AND $x2-1 > 0 Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2-2] AND $x2-2 > 0 Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2-3] AND $x2-3 > 0 Then $matchlen += 1 Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 -1, $y2, $x2 -2, $y2, $x2 -3) Else Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 -1, $y2, $x2 -2) EndIf Else Gemmatch($y2, $x2, $y2, $x2 +1, $y2, $x2 -1) EndIf Else $matchlen -= 2 EndIf ElseIf $gem1[$y2][$x2] = $gem[$y2][$x2-1] AND $x2-1 > 0 Then $matchlen += 2 If $gem1[$y2][$x2] = $gem[$y2][$x2-2] AND $x2-2 > 0 Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2-3] AND $x2-3 > 0 Then $matchlen += 1 If $gem1[$y2][$x2] = $gem[$y2][$x2-4] AND $x2-4 > 0 Then $matchlen += 1 Gemmatch($y2, $x2, $y2, $x2 -1, $y2, $x2 -2, $y2, $x2 -3, $y2, $x2 -4) Else Gemmatch($y2, $x2, $y2, $x2 -1, $y2, $x2 -2, $y2, $x2 -3) EndIf Else Gemmatch($y2, $x2, $y2, $x2 -1, $y2, $x2 -2) EndIf Else $matchlen -= 2 EndIf EndIf #endregion #region Horizontal Secondary If $gem1[$y1][$x1] = $gem[$y1][$x1+1] Then $matchlen += 2 If $gem1[$y1][$x1] = $gem[$y1][$x1+2] Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1+3] Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1+4] Then $matchlen += 1 Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 +2, $y1, $x1 +3, $y1, $x1 +4) Else Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 +2, $y1, $x1 +3) EndIf ElseIf $gem1[$y1][$x1] = $gem[$y1][$x1-1] AND $x1-1 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1-2] AND $x1-2 > 0 Then Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 +2, $y1, $x1 -1, $y1, $x1 -2) Else Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 +2, $y1, $x1 -1) EndIf Else Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 +2) EndIf ElseIf $gem1[$y1][$x1] = $gem[$y1][$x1-1] AND $x1-1 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1-2] AND $x1-2 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1-3] AND $x1-3 > 0 Then $matchlen += 1 Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 -1, $y1, $x1 -2, $y1, $x1 -3) Else Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 -1, $y1, $x1 -2) EndIf Else Gemmatch($y1, $x1, $y1, $x1 +1, $y1, $x1 -1) EndIf Else $matchlen -= 2 EndIf ElseIf $gem1[$y1][$x1] = $gem[$y1][$x1-1] AND $x1-1 > 0 Then $matchlen += 2 If $gem1[$y1][$x1] = $gem[$y1][$x1-2] AND $x1-2 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1-3] AND $x1-3 > 0 Then $matchlen += 1 If $gem1[$y1][$x1] = $gem[$y1][$x1-4] AND $x1-4 > 0 Then $matchlen += 1 Gemmatch($y1, $x1, $y1, $x1 -1, $y1, $x1 -2, $y1, $x1 -3, $y1, $x1 -4) Else Gemmatch($y1, $x1, $y1, $x1 -1, $y1, $x1 -2, $y1, $x1 -3) EndIf Else Gemmatch($y1, $x1, $y1, $x1 -1, $y1, $x1 -2) EndIf Else $matchlen -= 2 EndIf EndIf #endregion If $matchlen = 3 AND $chk Then $totalscore += 30 GUICtrlSetData($score, $totalscore) ElseIf $matchlen > 3 AND $chk Then $totalscore += 30 * ($matchlen - 2) GUICtrlSetData($score, $totalscore) EndIf Dropgems() chaincollapse() EndFunc Func Gemmatch($gem1x, $gem1y, $gem2x, $gem2y, $gem3x, $gem3y, $gem4x = 0, $gem4y = 0, $gem5x = 0, $gem5y = 0, $chain = 0) sleep(50) GUICtrlSetImage($box[$gem1x][$gem1y], "") ;clear 1st submitted gem from GUI GUICtrlSetImage($box[$gem2x][$gem2y], "") GUICtrlSetImage($box[$gem3x][$gem3y], "") GUICtrlSetImage($box[$gem4x][$gem4y], "") GUICtrlSetImage($box[$gem5x][$gem5y], "") If $chain = 1 Then ;if this is a chain collapse Sleep(50) GUICtrlSetImage($box[$gem1x][$gem1y], $gem[$gem1x][$gem1y]) ;flash gems back on GUICtrlSetImage($box[$gem2x][$gem2y], $gem[$gem2x][$gem2y]) GUICtrlSetImage($box[$gem3x][$gem3y], $gem[$gem3x][$gem3y]) GUICtrlSetImage($box[$gem4x][$gem4y], $gem[$gem4x][$gem4y]) GUICtrlSetImage($box[$gem5x][$gem5y], $gem[$gem5x][$gem5y]) sleep(50) GUICtrlSetImage($box[$gem1x][$gem1y], "") ;clear 1st submitted gem from GUI (again) GUICtrlSetImage($box[$gem2x][$gem2y], "") GUICtrlSetImage($box[$gem3x][$gem3y], "") GUICtrlSetImage($box[$gem4x][$gem4y], "") GUICtrlSetImage($box[$gem5x][$gem5y], "") EndIf $gem[$gem1x][$gem1y] = "" ;Clear gems from array $gem[$gem2x][$gem2y] = "" $gem[$gem3x][$gem3y] = "" $gem[$gem4x][$gem4y] = "" $gem[$gem5x][$gem5y] = "" $chk = 1 $oops = 0 Return(0) EndFunc Func Dropgems() If $chk Then For $y = 1 To $BoardSizeY For $x = 1 To $BoardSizeX If $gem[$y][$x] = "" Then ;if gem at ($y, $x) yes i know thats backwards, is blank For $count1 = $y-1 To 1 Step -1 ;drop each gem above blank gem $gem[($count1+1)][$x] = $gem[$count1][$x] ;gem is the gem above it GUICtrlSetImage($Box[$count1+1][$x], $gem[$count1+1][$x]) ;apply to GUI Next $gem[1][$x] = "Gems\" & $gemtype & "\Image" & Random(1, 7, 1) & ".jpg" GUICtrlSetImage($box[1][$x], $gem[1][$x]) ;Sel the image of the generated gem EndIf Next Next EndIf EndFunc Func chaincollapse($noscore = 0) ;check for matched created by collapsing proccess $chk = 1 While $chk $chk = 0 For $y = 1 to $BoardSizeY For $x = 1 to $BoardSizeX $matchlen = 0 #region Virticle ;Very simplified version of chkformatch If $gem[$y][$x] = $gem[$y+1][$x] Then $matchlen += 2 If $gem[$y][$x] = $gem[$y+2][$x] Then $matchlen += 1 If $gem[$y][$x] = $gem[$y+3][$x] Then $matchlen += 1 If $gem[$y][$x] = $gem[$y+4][$x] Then $matchlen += 1 Gemmatch($y, $x, $y +1, $x, $y +2, $x, $y +3, $x, $y +4, $x, 1) $y += 4 Else Gemmatch($y, $x, $y +1, $x, $y +2, $x, $y +3, $x, 0, 0, 1) $y += 3 EndIf Else Gemmatch($y, $x, $y +1, $x, $y +2, $x, 0, 0, 0, 0, 1) $y += 2 EndIf Else $matchlen -= 2 EndIf EndIf #endregion #region Hoizontal If $gem[$y][$x] = $gem[$y][$x+1] Then $matchlen += 2 If $gem[$y][$x] = $gem[$y][$x+2] Then $matchlen += 1 If $gem[$y][$x] = $gem[$y][$x+3] Then $matchlen += 1 If $gem[$y][$x] = $gem[$y][$x+4] Then $matchlen += 1 Gemmatch($y, $x, $y, $x+1, $y, $x+2, $y, $x+3, $y, $x+4, 1) $x += 4 Else Gemmatch($y, $x, $y, $x+1, $y, $x+2, $y, $x+3, 0, 0, 1) $x += 3 EndIf Else Gemmatch($y, $x, $y, $x+1, $y, $x+2, 0, 0, 0, 0, 1) $x += 2 EndIf Else $matchlen -= 2 EndIf EndIf #endregion If $noscore <> 1 Then If $matchlen = 3 AND $chk Then $totalscore += 60 GUICtrlSetData($score, $totalscore) ElseIf $matchlen > 3 AND $chk Then $totalscore += (60 * ($matchlen - 2)) GUICtrlSetData($score, $totalscore) EndIf EndIf Next Next Dropgems() WEnd Return(0) EndFunc Func nomovechker() ;checks to see if any moves are possible $move = 0 $gem1 = $gem For $y1 = 1 to $BoardSizeY For $x1 = 1 To $BoardSizeX If $gem1[$y1][$x1] = $gem1[$y1+1][($x1+1)] AND $gem1[$y1][$x1] = $gem1[$y1-1][($x1)] Then;upside down L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][($x1-1)] AND $gem1[$y1][$x1] = $gem1[$y1-1][($x1)] Then;upside down backwards L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][($x1)] AND $gem1[$y1][$x1] = $gem1[$y1-1][($x1+1)] Then;L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1-1] Then;backwards L $move = 1 ExitLoop EndIf If $gem1[($y1)][$x1] = $gem1[$y1+1][$x1-1] AND $gem1[($y1)][$x1] = $gem1[$y1-1][$x1-1] Then;middle one sticking out to right $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1+1] Then;middle one sticking out to left $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] Then;upside down L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1+1] Then;sideways upside down L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1-1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+1] Then;Backwards sideways upsidedown L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+1] Then;backwards sideways L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] Then;middle one sticking down $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1-1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1+1] Then;middle one sticking up (This one was broken fixed it) $move = 1 ExitLoop EndIf If $x1 > 2 Then If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+2] Then;XX0X $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1-2] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+1] Then;X0XX $move = 1 ExitLoop EndIf EndIf If $y1 > 2 Then If $gem1[$y1][$x1] = $gem1[$y1+1][$x1] AND $gem1[$y1][$x1] = $gem1[$y1-2][$x1] Then;XX0X 45deg clockwise $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+2][$x1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1] Then;X0XX 45deg clockwise $move = 1 ExitLoop EndIf EndIf Next If $move Then ; if a move was found no need to continue looking ExitLoop EndIf Next If Not $move Then ; if no move was found For $i = 10 to 1 step -1 $lowesHS = IniRead("HighScore.ini", "HighScore", "Score" & $i, 0) $lowesHS += 0 ;MsgBox(0, $lowesHS, $totalscore & @CRLF & $i) If $totalscore >= $lowesHS Then If $i = 10 Then IniWrite("HighScore.ini", "HighScore", "Score" & $i, $totalscore) IniWrite("HighScore.ini", "HighScore", "Name" & $i, "") Else IniWrite("HighScore.ini", "HighScore", "Score" & ($i+1), IniRead("HighScore.ini", "HighScore", "Score" & $i, 0)) IniWrite("HighScore.ini", "HighScore", "Score" & $i, $totalscore) IniWrite("HighScore.ini", "HighScore", "Name" & ($i+1), IniRead("HighScore.ini", "HighScore", "Name" & $i, 0)) IniWrite("HighScore.ini", "HighScore", "Name" & $i, "") If $i = 1 Then $name = InputBox("New High Score!", "Congratulations you made first place!" & @CRLF & "What is your name?") IniWrite("HighScore.ini", "HighScore", "Name" & $i, $name) HighScoreBox() MsgBox(0, "No Moves!!", "Game over you have no remaing moves." & @CRLF & "Click OK to start a new game.") EndIf EndIf Else ;MsgBox(0, "", $i) If $i = 10 Then MsgBox(0, "No Moves!!", "Game over you have no remaing moves." & @CRLF & "Click OK to start a new game.") Else $name = InputBox("New High Score!", "What is your name?") IniWrite("HighScore.ini", "HighScore", "Name" & $i+1, $name) HighScoreBox() MsgBox(0, "No Moves!!", "Game over you have no remaing moves." & @CRLF & "Click OK to start a new game.") EndIf ExitLoop EndIf Next newgame() EndIf EndFunc Func quit() Exit EndFuncif someone could let me know how to make the code scroll that would be nice Thanks RazerMToDo:1. Chain gem collapse support DONE!!2. Fix vertical columns DONE!!3. Fix 4 and 5 gems in a row DONE!!4. Prevent randomly created rows of 3 of the same gem DONE!!5. Point system DONE!!6. Point system based on a timer7. Highscore system8. Save game function9. Rehaul GUI10. Undo button11. Check for no possible moves DONE!!12. Cleanup and re-note source 13. get my x's and y's straight lol13. Fix chain collapse scoring system14. Put last gem type in an INIV.1 Notesi know i need to document it better, that all part of the plan for this thanksgiving week. As for now it will generate random gems 10 columns 20 rows, check for 3 of the same gem in a row at start and fix it, usually... You can move and cancel out gems, even 4 gem rows, dont ask me how i dont know but it does, 5gem rows are untested and new gems dont drop in yet. press ESC to exit, and F6 to load new gems however for some reason the gems wont work after a refresh, thats also on my ToDo list to work on.V.2 NotesWoot source is cleaned up, optimized a bit, and better documented.GEMS NOW DROP!!some issues still exist with vertical columnsgame still sometimes starts with 3 gems in a rowif you get the opprtunity to take out six gems in a row, dont it will likely crash the game5 gems in a row tested and works! umm.. not so much. 4 and 5 in a row are broken.V.3 Notes2 versions, New Icons and Old IconsFixed game starting with random complete gem setsRefresh now worksV.3.5 NotesFixed several issues with <every known curse word here> "Array variable subscript badly formatted." <- were not making me happychain collapses now work! yay!Note: old icon version is still .3V.7 NotesFixed some more "Array variable subscript badly formatted." plz let me know if you hit a new one!Vertical, 4 gem, 5 gem row's/Column's, and 2 gem row's/column's at same time FIXED!!!! YAY!!both new and old icon sets are updatedV1.0 NotesScoring system in placeNo moves check in placeGUI eyecandy and functionality improvedV1.1 NotesNew gem set, Real GemsChange between gem sets now in file menuseparate versions for each gems set have been combinedAll au3 check warnings fixedNote: changing between Real or New gems to Old gems will reset the game, From New to Old and vise versa will be the same game, score, and gem positions.V1.1.1Minor change in main func to unhighlight a gem that you clicked twice (note if you click to fast it takes 3 clicks, the GUI fails to register the 2nd click, not shure why)V1.1.2Highlighted gems now have a thin black border around themChain Collapse speed has been reduced, chain gems also flash once before dissapearingEDIT:minor tweak increased chain speed very slightly to reduce wait after the gems have dissapeared for the gems on top to fall.V1.1.3Fixed broken scoreproblem with collapse score confirmed, working on a solutionV1.2Fixed a logic error in the no moves checkCreated a save and load game systemAutomatically saves your game as lastgame.sgm upon exit.Automatically loads lastgame.sgmManual save and load menu items are avalible and work!Note: To change the default gem style change the 1 in$gemtype = 1its near the top of the file (line 15) to 0 for Real gems1 for New gems2 for Old gemsV2Woot finnaly an update and a major one too!So, here is what i can remember that i changed-Re Noted source-Changed default board size to 8x8 for more difficulty-Created an one move undo button-Re hauled move checking system to fix chain collapse point system-High scores are now recorded-New menu stuff-Easily add new gem types by making a new folder in \gems with the new images, must be seven named Image#.jpg and Image1#.jpg for highlighted images-No longer comes with "New" or "Old" gems because they are not my gems and im paranoid, comes with heavily modified "Real" gems-Variables at top of file to change, board size (gems wide, tall), gem size, and offsets that need to be changed with a large change in gem size. -Some thing i forgot here lolEDIT: changed board size to 8x8, it was 10x10 by accident, 10x10 is too easyAny comments and or suggestions are welcome!Source and pictures needed to run game: Edited April 1, 2007 by smstroble MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
dandymcgee Posted November 21, 2006 Share Posted November 21, 2006 I'll check it out. - Dan [Website] Link to comment Share on other sites More sharing options...
malu05 Posted November 21, 2006 Share Posted November 21, 2006 I'll check it out.Hehe, great work.. Reminds me of that Popcap game.Tho i couldnt complete it as the space between the dots was too far. [center][u]WoW Machinima Tool[/u] (Tool for Machinima Artists) [/center] Link to comment Share on other sites More sharing options...
RazerM Posted November 21, 2006 Share Posted November 21, 2006 Great game. If you made it refill that would be awesome. Good work My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Valuater Posted November 21, 2006 Share Posted November 21, 2006 Very impressive array work!!! Nice game, hope to see it get finished 8) Link to comment Share on other sites More sharing options...
smstroble Posted November 21, 2006 Author Share Posted November 21, 2006 Woot, i put some more work into this project, the gems will now drop! YAY!! there are some bugs with the game starting with 3 gems in a row, and with dropping gems in vertical columns. MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
RazerM Posted November 21, 2006 Share Posted November 21, 2006 I really like the changes. Well done My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
Skrip Posted November 21, 2006 Share Posted November 21, 2006 (edited) Nice job! Now just add scoring. Oh and controls do not work after pressing F6 heh Edited November 21, 2006 by Firestorm [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] Link to comment Share on other sites More sharing options...
smstroble Posted November 21, 2006 Author Share Posted November 21, 2006 V.3 RELEASED!!! See V.3 Notes for more info. @Firestorm fixed now MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
McGod Posted November 22, 2006 Share Posted November 22, 2006 Looking nice! You should add a scoring idea to it with a timer. Like how fast can you do it. When you get two pairs, one doesnt go away. [indent][center][u]Formerly Chip[/u][/center]~UDFs~[/indent][u]IRC.au3 - Allows you to connect to IRC ServersINetCon.au3 - Connects/Disconnects/Check Status of InternetHardware Key - Creates a unique hardware hashScriptComm - Allows you to communicate between scripts using WM_COPYDATA[/u][indent]~Programs~[/indent][indent]SimonAu3ForumsIRC Bot~Web Site~Web Autoit Example[/indent][indent][b][/b][/indent][u][/u] Link to comment Share on other sites More sharing options...
smstroble Posted November 22, 2006 Author Share Posted November 22, 2006 V.3.5 Done! MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
smstroble Posted November 22, 2006 Author Share Posted November 22, 2006 Looking nice! You should add a scoring idea to it with a timer. Like how fast can you do it.When you get two pairs, one doesnt go away.i know, its the same reason the 4 and 5 gem long rows dont work. something is amiss in the logic of either the chkformatch or gemmatch functions, it worked in version .1 im going to look at that now and see what the problem is. MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
smstroble Posted November 22, 2006 Author Share Posted November 22, 2006 V.7 DONE!! see notes for more info game is now fully functional except scoring and no moves check! MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
ConsultingJoe Posted November 22, 2006 Share Posted November 22, 2006 You did a great job, i think the autoit gaming is going to get bigger. Again, well done! [center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center] Link to comment Share on other sites More sharing options...
RazerM Posted November 22, 2006 Share Posted November 22, 2006 The new gems are really good. This game is getting better and better. It will be great when finished! My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
smstroble Posted November 22, 2006 Author Share Posted November 22, 2006 (edited) V1.0 is done! yay! game is fully functional, now its time to make it look better and include fancy features If anyone hits the No more moves message let me know if it was right, or if you run out of moves and never got the message. Also post your highschores, the top 10 i will include in the highscore feature when i make it. Edited November 22, 2006 by smstroble MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
RazerM Posted November 22, 2006 Share Posted November 22, 2006 Well done smstroble Use this for a codebox [ autoit ] tags inside [ codebox ] tags Also, I have fixed the four warnings in your script from AU3Check expandcollapse popup#include <GuiConstants.au3> HotKeySet("{F6}", "repopgems") HotKeySet("{ESC}", "quit") DIM $box[40][20] Dim $gem[40][20] DIM $gonegems[100][2][2] $gonegems[0][0][0] = 0 DIM $temp[4][2][2] Dim $sel1[3] DIM $gem1[40][20] $sel1[0] = "" Dim $sel2[3] $sel2[0] = "" $main = GUICreate("Gems For AU3", 500, 650, 200, 200) $totalscore = 0 $collapsescore = 0 GUI() Func repopgems() For $i = 1 To 20 For $u = 1 To 10 $gem[$i][$u] = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" GUICtrlSetImage($box[$i][$u], $gem[$i][$u]) Next Next chkallformatchs() EndFunc Func chkallformatchs() $chk = 0 For $y1 = 1 to 20 For $x1 = 1 To 10 If $gem[$y1][$x1] = $gem[$y1][($x1+1)] AND $gem[$y1][$x1] = $gem[$y1][($x1-1)] Then;new gem in 1st sel spot match gem on each side $newgem = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[$y1][$x1] = $gem[$y1][($x1+1)] AND $gem[$y1][$x1] = $gem[$y1][($x1+2)] Then;new gem in 1st sel spot match 2 on right $newgem = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[$y1][$x1] = $gem[$y1][($x1-1)] AND $gem[$y1][$x1] = $gem[$y1][($x1-2)] Then;new gem in 1st sel spot match 2 on left $newgem = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[($y1+1)][$x1] = $gem[$y1][$x1] AND $gem[($y1-1)][$x1] = $gem[$y1][$x1] Then;new gem in 1st sel spot match above and below $newgem = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[($y1+1)][$x1] = $gem[$y1][$x1] AND $gem[($y1+2)][$x1] = $gem[$y1][$x1] Then;new gem in 1st sel spot match 2 below $newgem = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $gem[$y1-1][$x1] = $gem[$y1][$x1] AND $gem[($y1-2)][$x1] = $gem[$y1][$x1] Then;new gem in 1st sel spot match 2 above $newgem = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $gem[$y1][$x1] = $newgem GUICtrlSetImage($box[$y1][$x1], $newgem) $chk = 1 EndIf If $chk Then If $y1 > 1 Then $y1 = $y1 - 1 $chk = 0 ElseIf $x1 > 2 Then $x1 = $x1 - 1 $chk = 0 Else $chk = 0 EndIf EndIf Next Next EndFunc Func chaincollapse() $chk = 0 $gem1 = $gem For $y1 = 1 to 20 For $x1 = 1 To 10 If $gem1[$y1][$x1] = $gem1[$y1][($x1+1)] AND $gem1[$y1][$x1] = $gem1[$y1][($x1-1)] Then;new gem in 1st sel spot match gem on each side Gemmatch($y1, $x1, $y1, $x1+1, $y1, $x1-1) $chk = 1 EndIf If $gem1[$y1][$x1] = $gem1[$y1][($x1+1)] AND $gem1[$y1][$x1] = $gem1[$y1][($x1+2)] Then;new gem in 1st sel spot match 2 on right Gemmatch($y1, $x1, $y1, $x1+1, $y1, $x1+2) $collapsescore = Int($collapsescore = $collapsescore /2) $chk = 1 EndIf If $x1 > 2 Then If $gem1[$y1][$x1] = $gem1[$y1][($x1-1)] AND $gem1[$y1][$x1] = $gem1[$y1][($x1-2)] Then;new gem in 1st sel spot match 2 on left Gemmatch($y1, $x1, $y1, $x1-1, $y1, $x1-2) $chk = 1 EndIf EndIf If $gem1[($y1+1)][$x1] = $gem1[$y1][$x1] AND $gem1[($y1-1)][$x1] = $gem1[$y1][$x1] Then;new gem in 1st sel spot match above and below Gemmatch($y1+1, $x1, $y1-1, $x1, $y1, $x1) $chk = 1 EndIf If $gem1[($y1+1)][$x1] = $gem1[$y1][$x1] AND $gem1[($y1+2)][$x1] = $gem1[$y1][$x1] Then;new gem in 1st sel spot match 2 below Gemmatch($y1+1, $x1, $y1+2, $x1, $y1, $x1) $collapsescore = Int($collapsescore = $collapsescore /2) $chk = 1 EndIf If $y1 > 2 Then If $gem1[($y1 - 1)][$x1] = $gem1[$y1][$x1] AND $gem1[($y1-2)][$x1] = $gem1[$y1][$x1] Then;new gem in 1st sel spot match 2 above Gemmatch($y1-1, $x1, $y1-2, $x1, $y1, $x1) $chk = 1 EndIf EndIf Next Next If $chk Then For $y = 1 To 20 For $x = 1 To 10 ;MsgBox(0, "", "point 2") If $gem[$y][$x] = "" Then For $count1 = $y-1 To 1 Step -1 ;MsgBox(0, "", $gonegems[$count][0][1]) $gem[($count1+1)][$x] = $gem[$count1][$x] GUICtrlSetImage($Box[$count1+1][$x], $gem[$count1+1][$x]) Next ;MsgBox(0, "", $gonegems[$count][0][1]) $gem[1][$x] = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" GUICtrlSetImage($Box[1][$x], $gem[1][$x]) Sleep(20) EndIf Next Next ;MsgBox(0, "", "point 3") chaincollapse() EndIf EndFunc Func GUI() For $i = 1 To 20 For $u = 1 To 10 $gem[$i][$u]= "Gems\New\Image" & Random(1, 7, 1) & ".jpg" $box[$i][$u]= GUICtrlCreatePic($gem[$i][$u], (($u *29 )+150), ($i*29 ), 28, 28) Next Next $file = GUICtrlCreateMenu("File") Global $filenewgame = GUICtrlCreateMenuitem("New Game", $file) Global $fileexit = GUICtrlCreateMenuitem("Exit", $file) $Help = GUICtrlCreateMenu("Help") Global $helphelp = GUICtrlCreateMenuitem("Help", $help) GUICtrlSetState(-1, @SW_DISABLE) GUICtrlCreateGroup("", 169, 10, 309, 605) GUICtrlCreateGroup("", 7, 90, 150, 35) GUICtrlCreateLabel("Score:", 10, 100) Global $score = GUICtrlCreateLabel("0", 55, 100, 100) chkallformatchs() main() EndFunc Func main() GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE OR $msg = $fileexit Then Exit ElseIf $msg = $filenewgame Then repopgems() $totalscore = 0 GUICtrlSetData($score, "0") EndIf If $msg > 0 Then ;saves LOTS OF CPU For $x = 1 to 20 ;20 rows can never remember if x is rows or colums, of well For $y = 1 To 10 ;10 colums If $msg = $box[$x][$y] Then ;if gem was clicked If $sel1[0] = "" Then ;if no gem has been selected, select one $sel1[0] = $gem[$x][$y] $sel1[1] = $x $sel1[2] = $y $gemnum = StringMid($gem[$x][$y], StringLen($gem[$x][$y]) - 4, 1) GUICtrlSetImage($box[$x][$y], "Gems\New\Image1" & $gemnum & ".jpg") Else ;if a gem has been selected, move gem and perform logic $sel2[0] = $gem[$x][$y] $sel2[1] = $x $sel2[2] = $y If (($sel2[1] = $sel1[1]+1) AND ($sel2[2] = $sel1[2])) OR (($sel2[1] = $sel1[1]-1) AND ($sel2[2] = $sel1[2])) OR (($sel2[2] = $sel1[2]+1) AND ($sel2[1] = $sel1[1])) OR (($sel2[2] = $sel1[2]-1) AND ($sel2[1] = $sel1[1])) Then ;this makes shure you clicked a gem bordering the first clicked gem $gem[$sel1[1]][$sel1[2]] = $sel2[0] GUICtrlSetImage($box[$sel1[1]][$sel1[2]], $sel2[0]);makes 1st sel gem 2nd sel gem $gem[$sel2[1]][$sel2[2]] = $sel1[0] GUICtrlSetImage($box[$sel2[1]][$sel2[2]], $sel1[0]);makes 2nd sel gem 1st sel gem Global $oops = 1 chkformatch($sel1[1], $sel1[2], $sel2[1] , $sel2[2]) $totalscore = $totalscore + $collapsescore $collapsescore = 0 GUICtrlSetData($score, $totalscore) If $oops Then ;if no gems can be eliminated switch gems back ;MsgBox(0, $oops, "") Sleep(200) ;gives em time to realize their error $gem[$sel1[1]][$sel1[2]] = $sel1[0] GUICtrlSetImage($box[$sel1[1]][$sel1[2]], $sel1[0]) $gem[$sel2[1]][$sel2[2]] = $sel2[0] GUICtrlSetImage($box[$sel2[1]][$sel2[2]], $sel2[0]) $gemnum = StringMid($gem[$sel1[1]][$sel1[2]], StringLen($gem[$sel1[1]][$sel1[2]]) - 4, 1) GUICtrlSetImage($box[$sel1[1]][$sel1[2]], "Gems\New\Image" & $gemnum & ".jpg") EndIf nomovechker() EndIf $sel1[0] = "" ;resets sel gems $sel2[0] = "" EndIf EndIf Next Next EndIf WEnd EndFunc Func nomovechker() $move = 0 $gem1 = $gem For $y1 = 1 to 20 For $x1 = 1 To 10 If $gem1[$y1][$x1] = $gem1[$y1+1][($x1+1)] AND $gem1[$y1][$x1] = $gem1[$y1-1][($x1)] Then;upside down L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][($x1-1)] AND $gem1[$y1][$x1] = $gem1[$y1-1][($x1)] Then;upside down backwards L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][($x1)] AND $gem1[$y1][$x1] = $gem1[$y1-1][($x1+1)] Then;L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1-1] Then;backwards L $move = 1 ExitLoop EndIf If $gem1[($y1)][$x1] = $gem1[$y1+1][$x1-1] AND $gem1[($y1)][$x1] = $gem1[$y1-1][$x1-1] Then;middle one sticking out to right $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1+1] Then;middle one sticking out to left $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] Then;upside down L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1+1] Then;sideways upside down L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1-1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+1] Then;Backwards sideways upsidedown L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+1] Then;backwards sideways L $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] Then;middle one sticking down $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1-1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1+1][$x1+1] Then;middle one sticking up $move = 1 ExitLoop EndIf If $x1 > 2 Then If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+2] Then;XX0X $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1-2] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+1] Then;X0XX $move = 1 ExitLoop EndIf EndIf If $y1 > 2 Then If $gem1[$y1][$x1] = $gem1[$y1+1][$x1] AND $gem1[$y1][$x1] = $gem1[$y1-2][$x1] Then;XX0X 45deg clockwise $move = 1 ExitLoop EndIf If $gem1[$y1][$x1] = $gem1[$y1+2][$x1] AND $gem1[$y1][$x1] = $gem1[$y1-1][$x1] Then;X0XX 45deg clockwise $move = 1 ExitLoop EndIf EndIf Next Next If Not $move Then MsgBox(0, "No Moves!", "Game Over! You have run out of possible moves") EndIf EndFunc Func chkformatch($y1, $x1, $y2, $x2) Global $chk = 0 $gem1 = $gem If $gem1[$y1][$x1] = $gem1[$y1][$x1+1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1-1] Then;new gem in 1st sel spot match gem on each side Gemmatch($y1, $x1, $y1, $x1+1, $y1, $x1-1) EndIf If $gem1[$y1][$x1] = $gem1[$y1][$x1+1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1+2] Then;new gem in 1st sel spot match 2 on right Gemmatch($y1, $x1, $y1, $x1+1, $y1, $x1+2) EndIf If $x1 > 2 Then If $gem1[$y1][$x1] = $gem1[$y1][$x1-1] AND $gem1[$y1][$x1] = $gem1[$y1][$x1-2] Then;new gem in 1st sel spot match 2 on left Gemmatch($y1, $x1, $y1, $x1-1, $y1, $x1-2) EndIf EndIf If $gem1[$y1+1][$x1] = $gem1[$y1][$x1] AND $gem1[$y1-1][$x1] = $gem1[$y1][$x1] Then;new gem in 1st sel spot match above and below Gemmatch($y1+1, $x1, $y1-1, $x1, $y1, $x1) EndIf If $gem1[$y1+1][$x1] = $gem1[$y1][$x1] AND $gem1[$y1+2][$x1] = $gem1[$y1][$x1] Then;new gem in 1st sel spot match 2 below Gemmatch($y1+1, $x1, $y1+2, $x1, $y1, $x1) EndIf If $gem1[$y1-1][$x1] = $gem1[$y1][$x1] AND $gem1[$y1-2][$x1] = $gem1[$y1][$x1] Then;new gem in 1st sel spot match 2 above Gemmatch($y1-1, $x1, $y1-2, $x1, $y1, $x1) EndIf if $gem1[$y2][$x2] = $gem1[$y2][$x2+1] AND $gem1[$y2][$x2] = $gem1[$y2][$x2-1] Then;new gem in 2nd sel spot match gem on each side Gemmatch($y2, $x2, $y2, $x2+1, $y2, $x2-1) EndIf If $gem1[$y2][$x2] = $gem1[$y2][$x2+1] AND $gem1[$y2][$x2] = $gem1[$y2][$x2+2] Then;new gem in 2nd sel spot match 2 right Gemmatch($y2, $x2, $y2, $x2+1, $y2, $x2+2) EndIf If $x1 > 2 Then If $gem1[$y2][$x2] = $gem1[$y2][$x2-1] AND $gem1[$y2][$x2] = $gem1[$y2][$x2-2] Then;new gem in 2nd sel spot match 2 left Gemmatch($y2, $x2, $y2, $x2-1, $y2, $x2-2) EndIf EndIf If $gem1[$y2+1][$x2] = $gem1[$y2][$x2] AND $gem1[$y2-1][$x2] = $gem1[$y2][$x2] Then;new gem in 2nd sel spot match above below Gemmatch($y2+1, $x2, $y2-1, $x2, $y2, $x2) EndIf If $gem1[$y2+1][$x2] = $gem1[$y2][$x2] AND $gem1[$y2+2][$x2] = $gem1[$y2][$x2] Then;new gem in 2nd sel spot match 2 below Gemmatch($y2+1, $x2, $y2+2, $x2, $y2, $x2) EndIf If $gem1[$y2-1][$x2] = $gem1[$y2][$x2] AND $gem1[$y2-2][$x2] = $gem1[$y2][$x2] Then;new gem in 2nd sel spot match 2 above Gemmatch($y2-1, $x2, $y2-2, $x2, $y2, $x2) EndIf ;MsgBox(0, "", "point 1") If $chk Then For $y = 1 To 20 For $x = 1 To 10 ;MsgBox(0, "", "point 2") If $gem[$y][$x] = "" Then For $count1 = $y-1 To 1 Step -1 ;MsgBox(0, "", $gonegems[$count][0][1]) $gem[($count1+1)][$x] = $gem[$count1][$x] GUICtrlSetImage($Box[$count1+1][$x], $gem[$count1+1][$x]) Next ;MsgBox(0, "", $gonegems[$count][0][1]) $gem[1][$x] = "Gems\New\Image" & Random(1, 7, 1) & ".jpg" GUICtrlSetImage($Box[1][$x], $gem[1][$x]) Sleep(20) EndIf Next Next ;MsgBox(0, "", "point 3") chaincollapse() EndIf EndFunc Func Gemmatch($gem1x, $gem1y, $gem2x, $gem2y ,$gem3x, $gem3y) ;erase gem func/drop gem func soon If $collapsescore = 0 Then $collapsescore = 30 Else $collapsescore = $collapsescore * 2 EndIf GUICtrlSetImage($box[$gem1x][$gem1y], "");erases gems, soon to be replaced with drop func GUICtrlSetImage($box[$gem2x][$gem2y], "") GUICtrlSetImage($box[$gem3x][$gem3y], "") $gem[$gem1x][$gem1y] = "" $gem[$gem2x][$gem2y] = "" $gem[$gem3x][$gem3y] = "" $chk = 1 $oops = 0 Return(0) EndFunc Func quit() Exit EndFunc My Programs:AInstall - Create a standalone installer for your programUnit Converter - Converts Length, Area, Volume, Weight, Temperature and Pressure to different unitsBinary Clock - Hours, minutes and seconds have 10 columns each to display timeAutoIt Editor - Code Editor with Syntax Highlighting.Laserix Editor & Player - Create, Edit and Play Laserix LevelsLyric Syncer - Create and use Synchronised Lyrics.Connect 4 - 2 Player Connect 4 Game (Local or Online!, Formatted Chat!!)MD5, SHA-1, SHA-256, Tiger and Whirlpool Hash Finder - Dictionary and Brute Force FindCool Text Client - Create Rendered ImageMy UDF's:GUI Enhance - Enhance your GUIs visually.IDEA File Encryption - Encrypt and decrypt files easily! File Rename - Rename files easilyRC4 Text Encryption - Encrypt text using the RC4 AlgorithmPrime Number - Check if a number is primeString Remove - remove lots of strings at onceProgress Bar - made easySound UDF - Play, Pause, Resume, Seek and Stop. Link to comment Share on other sites More sharing options...
NELyon Posted November 22, 2006 Share Posted November 22, 2006 Wow, the game is great! Nice job Link to comment Share on other sites More sharing options...
FuryCell Posted November 22, 2006 Share Posted November 22, 2006 (edited) Nice job. Edited November 22, 2006 by SolidSnake HKTunes:Softpedia | GoogleCodeLyricToy:Softpedia | GoogleCodeRCTunes:Softpedia | GoogleCodeMichtaToolsProgrammer n. - An ingenious device that turns caffeine into code. Link to comment Share on other sites More sharing options...
smstroble Posted November 22, 2006 Author Share Posted November 22, 2006 Thanks Razer M Well done smstroble Use this for a codebox [ autoit ] tags inside [ codebox ] tags Also, I have fixed the four warnings in your script from AU3Check MUHAHAHAHAHA Link to comment Share on other sites More sharing options...
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