Rad Posted April 5, 2007 Share Posted April 5, 2007 (edited) Im making a game where theres a bunch of buttons, and one of the buttons randomly chosen is the "key" to the next level. Each level increases the amount of buttons, its a 2d array and its pretty simple concept. Level one just shows what to do and has one box in the center. Level two (2x2), 3 is (3x3) etc. Im using two for loops, but i cant really figure out how to make the buttons (Well, colored labels) automatically position themselves... I got it in my head but I just cant figure out what it would look like: For $count = 0 to $i - 1 For $count2 = 0 to $i - 1 $Buttons[$i-1][$count2] = GUICtrlCreateLabel("",(400 / $I) * $count,(400 / $I) * $count2, 100,100) Next Next What exactly should I use for the left/top, width/height... What i have now isnt working at all lol Edited April 5, 2007 by Rad Link to comment Share on other sites More sharing options...
Uten Posted April 5, 2007 Share Posted April 5, 2007 Don't know, maybe this grid sample can give you some ideas? Please keep your sig. small! Use the help file. Search the forum. Then ask unresolved questions :) Script plugin demo, Simple Trace udf, TrayMenuEx udf, IOChatter demo, freebasic multithreaded dll sample, PostMessage, Aspell, Code profiling Link to comment Share on other sites More sharing options...
Rad Posted April 5, 2007 Author Share Posted April 5, 2007 I was ready to give up but after a bit more trial and error this seemed to work a bit: $Buttons[$i][$ii] = GUICtrlCreateLabel("", 40 + ($i * 400 / $level + 5) + $i, 40 + ($ii * 400 / $level + 5) + $ii, (400 / $level ), (400 / $level )) heres the entire script if anyone wants to see it... Its not finished but the basic concept works. Need to fix the spacing so its a little more.... static expandcollapse popup#Include <GUIConstants.au3> #Include <Misc.au3> $Window = GUICreate("Button Game", 500, 500) $CurLevel = 1 $BG = 0x444444 $WinBG = 0x44ff44 Global $Winner = "" $winstate = 0 Dim $Buttons[1][1] LevelGenerate($CurLevel) GUISetState() While 1 $msg = GUIGetMsg() $mouse = GUIGetCursorInfo() if $msg = $GUI_EVENT_CLOSE Then Exit If $msg = $winner then $CurLevel = $CurLevel + 1 LevelGenerate($CurLevel) EndIf If IsArray($mouse) Then If $Mouse[4] = $Winner Then If $Winstate = 0 Then $Winstate = 1 GUICtrlSetBkColor($winner, $WinBG) EndIf Else If $Winstate = 1 Then $Winstate = 0 GUICtrlSetBkColor($winner, $BG) EndIf EndIf EndIf WEnd func LevelGenerate($Level) if $Level = 1 Then $winner = GUICtrlCreateLabel("",250,250,100,100) GUICtrlSetBkColor(-1, $BG) Else GUICtrlDelete($winner) For $i = 0 to UBound($Buttons) - 1 For $ii = 0 to Ubound($Buttons) - 1 GUICtrlDelete($Buttons[$i][$ii]) Next Next Dim $Buttons[$level][$level] For $i = 0 to $level - 1 For $ii = 0 to $level - 1 $Buttons[$i][$ii] = GUICtrlCreateLabel("", 40 + ($i * 400 / $level + 5) + $i, 40 + ($ii * 400 / $level + 5) + $ii, (400 / $level ), (400 / $level )) GUICtrlSetBkColor(-1,$BG) Next Next $winner = $buttons[Random(0, $level - 1,1)][Random(0,$level-1,1)] guictrlsetbkcolor($winner, 0xffffff) EndIf EndFunc Link to comment Share on other sites More sharing options...
Rad Posted April 6, 2007 Author Share Posted April 6, 2007 Heres more complete game and i am done with it, lol take a look Link to comment Share on other sites More sharing options...
jvanegmond Posted April 6, 2007 Share Posted April 6, 2007 Heres more complete game and i am done with it, lol take a lookGood to see you finished it! I was going to give you the formule, as I had it laying around, but I didn't have any time at the time I read this topic. github.com/jvanegmond 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