Sign in to follow this  
Followers 0
Rad

Need help with a formula

5 posts in this topic

#1 ·  Posted (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 by Rad

Share this post


Link to post
Share on other sites



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

#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

Share this post


Link to post
Share on other sites

Heres more complete game and i am done with it, lol take a look

Share this post


Link to post
Share on other sites

Heres more complete game and i am done with it, lol take a look

Good 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.

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