Sign in to follow this  
Followers 0
AlmarM

A littble bit help is welcome ;)

8 posts in this topic

Hello,

Im trying to re-make my first game 'How fast are u?'.

Well, I have some problems with enable a random button and disable the previous button.

#include <GUIConstants.au3>

Global $Left, $Top, $Width, $Height, $Title
Global $Button[37]
Global $Num = 1

Skill()

Func Skill()
    $GUI = GUICreate("Select Skill", 120, 130, -1, -1)
    $Easy = GUICtrlCreateRadio("Easy", 10, 10)
    $Normal = GUICtrlCreateRadio("Normal", 10, 30)
    $Hard = GUICtrlCreateRadio("Hard", 10, 50)
    $Why = GUICtrlCreateRadio("Dont choose me...", 10, 70)
    GUICtrlSetState($Normal, 1)
    $Select = GUICtrlCreateButton("Select", 10, 100, 100)
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Select
            If GUICtrlRead($Easy) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 50
                $Height = 50
                $Title = "Easy"
            ElseIf GUICtrlRead($Normal) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 25
                $Height = 25
                $Title = "Normal"
            ElseIf GUICtrlRead($Hard) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 15
                $Height = 15
                $Title = "Hard"
            Else
                $Left = 10
                $Top = 10
                $Width = 5
                $Height = 5
                $Title = "Dont choose me..."
            EndIf
            GUIDelete($GUI)
            Game()
        EndSelect
    WEnd
EndFunc

Func Game()
    $GUI = GUICreate("How fast are u? * " & $Title & " *", 370, 500, -1, -1)
    
    For $i = 1 To UBound($Button) - 1
        $Button[$i] = GUICtrlCreateButton("", $Left, $Top, $Width, $Height)
        $Left += 60
        
        If $i == 6 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 12 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 18 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 24 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 30 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 36 Then
            $Top += 60
            $Left = 10
        EndIf
    Next
    
    For $x = 1 To 36 Step 1
        GUICtrlSetData($Button[$x], "Click")
    Next
    
    For $y = 2 To 36 Step 1
        GUICtrlSetState($Button[$y], $GUI_DISABLE)
    Next
    
    $HighScore = GUICtrlCreateEdit("MyScore", 10, 370, 350, 120)
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Button[1]
            $Start = TimerInit()
            For $a = 1 To 36
                $R = Random(1, 36, 1)
                GUICtrlSetState($Button[$R], $GUI_ENABLE)
                If GUIGetMsg() = $Button[$R] Then
                    GUICtrlSetState($Button[$R], $GUI_DISABLE)
                    $Ra = Random(1, 36, 1)
                    GUICtrlSetData($Button[$Ra], $GUI_ENABLE)
                EndIf
            Next
        EndSelect
    WEnd
EndFunc

Any help is welcome :)

AlmarM


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites



I'm trying to code this up for you, but here is the code in question;

Case $nMsg = $Button[1]
            $Start = TimerInit()
            For $a = 1 To 36
                $R = Random(1, 36, 1)
                GUICtrlSetState($Button[$R], $GUI_ENABLE)
                If GUIGetMsg() = $Button[$R] Then
                    GUICtrlSetState($Button[$R], $GUI_DISABLE)
                    $Ra = Random(1, 36, 1)
                    GUICtrlSetData($Button[$Ra], $GUI_ENABLE)
                EndIf
            Next
        EndSelect

You are only checking $nMsg for $Button[1]. Its going to jump through that For loop pretty quickly, and then only wait for input from $Button[1].


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Are you trying to make the game so after you click the 1st box, you have to click ALL of them(that aren't greyed out) or find the 'magic' one, then find the next 'magic' one...


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Took a little bit of a leap of faith cause I'm not 100% sure what your trying to accomplish... but its always fun to figure something out. This will disable the button clicked on, not sure what you wanted though.

#include <GUIConstants.au3>

Global $Left, $Top, $Width, $Height, $Title
Global $Button[37]
Global $Num = 1

Skill()

Func Skill()
    $GUI = GUICreate("Select Skill", 120, 130, -1, -1)
    $Easy = GUICtrlCreateRadio("Easy", 10, 10)
    $Normal = GUICtrlCreateRadio("Normal", 10, 30)
    $Hard = GUICtrlCreateRadio("Hard", 10, 50)
    $Why = GUICtrlCreateRadio("Dont choose me...", 10, 70)
    GUICtrlSetState($Normal, 1)
    $Select = GUICtrlCreateButton("Select", 10, 100, 100)
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Select
            If GUICtrlRead($Easy) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 50
                $Height = 50
                $Title = "Easy"
            ElseIf GUICtrlRead($Normal) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 25
                $Height = 25
                $Title = "Normal"
            ElseIf GUICtrlRead($Hard) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 15
                $Height = 15
                $Title = "Hard"
            Else
                $Left = 10
                $Top = 10
                $Width = 5
                $Height = 5
                $Title = "Dont choose me..."
            EndIf
            GUIDelete($GUI)
            Game()
        EndSelect
    WEnd
EndFunc

Func Game()
    $GUI = GUICreate("How fast are u? * " & $Title & " *", 370, 500, -1, -1)
    
    For $i = 1 To UBound($Button) - 1
        $Button[$i] = GUICtrlCreateButton("", $Left, $Top, $Width, $Height)
        $Left += 60
        Switch $i
            Case 6
                $Top += 60
                $Left = 10
            Case 12
                $Top += 60
                $Left = 10
            Case 18
                $Top += 60
                $Left = 10
            Case 24 
                $Top += 60
                $Left = 10
            Case 30
                $Top += 60
                $Left = 10
            Case 36
                $Top += 60
                $Left = 10
        EndSwitch
    Next
    
    For $x = 1 To 36 Step 1
        GUICtrlSetData($Button[$x], "Click")
    Next
    
    For $y = 2 To 36 Step 1
        GUICtrlSetState($Button[$y], $GUI_DISABLE)
    Next
    
    $HighScore = GUICtrlCreateEdit("MyScore", 10, 370, 350, 120)
    
    GUISetState()
    
    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = -3
                Exit
            Case $nMsg = $Button[1]
                For $a = 1 To 36
                    $R = Random(1, 36, 1)
                    GUICtrlSetState($Button[$R], $GUI_ENABLE)
                Next
                $Start = TimerInit()
                ExitLoop
        EndSelect
    WEnd
    
    While 1
        $nMsg = GUIGetMsg()
        If $nMsg = -3 Then Exit
        
            For $i = 1 To 36
                If $nMsg = $Button[$i] Then
                    ;MsgBox(0, "", "clicked " & $i)
                    GUICtrlSetState($Button[$i], $GUI_DISABLE)
                EndIf
            Next
        
    WEnd
EndFunc

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Well im trying to enable a random button, if cliked disable the previous button and enable another random one.

AlmarM

EDIT: Typo

Edited by AlmarM

Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Well im trying to enable a random button, if cliked disable the previous button and enable another random one.

AlmarM

EDIT: Typo

Is this what you tried to obtain ? :)

#include <GUIConstants.au3>

Global $Left, $Top, $Width, $Height, $Title
Global $Button[37]
Global $Num = 1
Global $StartTime, $EndTime, $TotalTime

Skill()

Func Skill()
    $GUI = GUICreate("Select Skill", 120, 130, -1, -1)
    $Easy = GUICtrlCreateRadio("Easy", 10, 10)
    $Normal = GUICtrlCreateRadio("Normal", 10, 30)
    $Hard = GUICtrlCreateRadio("Hard", 10, 50)
    $Why = GUICtrlCreateRadio("Dont choose me...", 10, 70)
    GUICtrlSetState($Normal, 1)
    $Select = GUICtrlCreateButton("Select", 10, 100, 100)
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Select
            If GUICtrlRead($Easy) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 50
                $Height = 50
                $Title = "Easy"
            ElseIf GUICtrlRead($Normal) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 25
                $Height = 25
                $Title = "Normal"
            ElseIf GUICtrlRead($Hard) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 15
                $Height = 15
                $Title = "Hard"
            Else
                $Left = 10
                $Top = 10
                $Width = 5
                $Height = 5
                $Title = "Dont choose me..."
            EndIf
            GUIDelete($GUI)
            Game()
        EndSelect
    WEnd
EndFunc

Func Game()
    $GUI = GUICreate("How fast are you? * " & $Title & " *", 370, 500, -1, -1)
    
    For $i = 1 To UBound($Button) - 1
        $Button[$i] = GUICtrlCreateButton("", $Left, $Top, $Width, $Height)
        $Left += 60
        
        If $i == 6 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 12 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 18 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 24 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 30 Then
            $Top += 60
            $Left = 10
        EndIf
        
        If $i == 36 Then
            $Top += 60
            $Left = 10
        EndIf
    Next
    
    For $x = 1 To 36
        GUICtrlSetData($Button[$x], "Click")
        GUICtrlSetState($Button[$x], $GUI_DISABLE)
    Next
    
    $HighScore = GUICtrlCreateEdit("MyScore", 10, 370, 350, 120)
    $R = Random(1, 36, 1); added
    GUICtrlSetState($Button[$R], $GUI_ENABLE); added
    $StartTime = TimerInit()
    GUISetState()
    
    While 1
        $nMsg = GUIGetMsg()
        Select
            Case $nMsg = -3
                Exit
        EndSelect
        For $i = 1 To 36
            Select
                Case $nMsg = $Button[$i]
                    If $i = $R Then
                        $EndTime = TimerInit()
                        $TotalTime += $EndTime-$StartTime
                        GUICtrlSetData($Highscore, "Score: " & $TotalTime)
                        Do
                            $Ra = Random(1, 36, 1)
                        Until $Ra <> $R
                        GUICtrlSetState($Button[$R], $GUI_DISABLE)
                        $R = $Ra
                        GUICtrlSetState($Button[$Ra], $GUI_ENABLE)
                    EndIf
            EndSelect
        Next
    WEnd
 EndFunc

You still need to make the score accordingly to your wishes.

Have fun!

PS: Leuk spelletje !! :)

Share this post


Link to post
Share on other sites

Thx for your reply, only it keeps going forever, I just want it to stop afther 36 times.

AlmarM

P.S.

Dankje ;P


Minesweeper

A minesweeper game created in autoit, source available.

_Mouse_UDF

An UDF for registering functions to mouse events, made in pure autoit.

2D Hitbox Editor

A 2D hitbox editor for quick creation of 2D sphere and rectangle hitboxes.

Share this post


Link to post
Share on other sites

Thx for your reply, only it keeps going forever, I just want it to stop afther 36 times.

AlmarM

P.S.

Dankje ;P

Try this out

#include <GUIConstants.au3>

Global $Left, $Top, $Width, $Height, $Title
Global $Button[37]
Global $Num = 1
Global $count = 1
Global $aR[37]
Global $GUI2

Skill()
 
Func Skill()
    $GUI = GUICreate("Select Skill", 120, 130, -1, -1)
    $Easy = GUICtrlCreateRadio("Easy", 10, 10)
    $Normal = GUICtrlCreateRadio("Normal", 10, 30)
    $Hard = GUICtrlCreateRadio("Hard", 10, 50)
    $Why = GUICtrlCreateRadio("Dont choose me...", 10, 70)
    GUICtrlSetState($Normal, 1)
    $Select = GUICtrlCreateButton("Select", 10, 100, 100)
    
    GUISetState()
    While 1
        $nMsg = GUIGetMsg()
        Select
        Case $nMsg = -3
            Exit
        Case $nMsg = $Select
            If GUICtrlRead($Easy) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 50
                $Height = 50
                $Title = "Easy"
            ElseIf GUICtrlRead($Normal) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 25
                $Height = 25
                $Title = "Normal"
            ElseIf GUICtrlRead($Hard) = 1 Then
                $Left = 10
                $Top = 10
                $Width = 15
                $Height = 15
                $Title = "Hard"
            Else
                $Left = 10
                $Top = 10
                $Width = 5
                $Height = 5
                $Title = "Dont choose me..."
            EndIf
            GUISetState(@SW_HIDE, $GUI)
            $count = 1
            Dim $aR[37]
            Game()
            GUISetState(@SW_HIDE, $GUI2)
            GUISetState(@SW_SHOW, $GUI)
        EndSelect
    WEnd
EndFunc

Func Game()
    $GUI2 = GUICreate("How fast are u? * " & $Title & " *", 370, 500, -1, -1)
    
    For $i = 1 To UBound($Button) - 1
        $Button[$i] = GUICtrlCreateButton("", $Left, $Top, $Width, $Height)
        $Left += 60
        Switch $i
            Case 6
                $Top += 60
                $Left = 10
            Case 12
                $Top += 60
                $Left = 10
            Case 18
                $Top += 60
                $Left = 10
            Case 24 
                $Top += 60
                $Left = 10
            Case 30
                $Top += 60
                $Left = 10
            Case 36
                $Top += 60
                $Left = 10
        EndSwitch
    Next
    
    For $x = 1 To 36 Step 1
        GUICtrlSetData($Button[$x], "Click")
    Next
    
    For $y = 2 To 36 Step 1
        GUICtrlSetState($Button[$y], $GUI_DISABLE)
    Next
    
    $HighScore = GUICtrlCreateEdit("MyScore", 10, 370, 350, 120)
    
    GUISetState()
    $Start = TimerInit()
    
    While 1
        $nMsg = GUIGetMsg()
        If $nMsg = -3 Then Exit
            For $i = 1 To 36
                If $nMsg = $Button[$i] Then
                    $R = _RandomUsed()
                    If @error Then
                        $End = TimerDiff($Start)
                        GUICtrlSetData($Highscore, "Score: " & Round($End))
                        MsgBox(0, "HighScore", "Score: " & Round($End))
                        ExitLoop(2)
                    EndIf
                    GUICtrlSetState($Button[$i], $GUI_DISABLE)
                    GUICtrlSetState($Button[$R], $GUI_ENABLE)
                    GUICtrlSetState($Button[$R], $GUI_FOCUS) ; just used so you can press space alot to test
                EndIf
            Next
    WEnd
EndFunc

Func _RandomUsed()  
    Do
        $R = Random(1, 36, 1)
        If $aR[$R] <> 1 Then 
            $aR[$R] = 1
            $count += 1
            ;ToolTip($count)
            Return $R
        EndIf
        If $count = 37 Then Return SetError(1);1 +36 randoms
    Until False
EndFunc

@charvi, I like the way you made the score go up.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

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