Jump to content

guessing the number


Recommended Posts

Hello, I'm new to this, but I am learning it myself.

I wrote a simple guessing game. You had to gues a number between 0 and 100.

It's very simple.

Are there things that I can write much simplyer? can you suggest something to chanche so I can learn to write it better?

#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

#include <GuiConstants.au3>

GuiCreate("guess number between 0 and 100", 256, 120,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Label_1 = GuiCtrlCreateLabel("", 70, 80, 110, 30)
$Input_2 = GuiCtrlCreateInput("", 10, 10, 80, 30)
$Button_3 = GuiCtrlCreateButton("Input", 160, 10, 80, 30)
$random=Random(1,100,1)
$try=0

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
        
        
        
        Case $msg = $Button_3
        $waarde=GUICtrlRead($Input_2)
        
        if $waarde < $random Then
            GUICtrlSetData($Label_1, "number is bigger")
            guictrlsetdata($Input_2,"")
            $try=$try + 1
            ElseIf $waarde > $random Then
            GUICtrlSetData($Label_1, "number is smaller")       
            guictrlsetdata($Input_2,"")
            $try=$try + 1
        Else
        ;GUICtrlSetData($Label_1, "Number is correct")      
            MsgBox(0, "Gewonnen", "Het getal was:" & $waarde)
            MsgBox(0, "Gewonnen", "try:" & $try)
            Exit
            EndIf

EndSelect   
    
WEnd
Exit
#endregion --- GuiBuilder generated code End ---

"You cannot solve a problem with the mind that created it" (Albert Einstein)

Link to comment
Share on other sites

haha, I was going to make a guess the number game for my mini game collection, but I guess you beat me to it...oh well, and good job by the way

[center]"When you look at old, classic games like Snake, you often put it off because it's such a simple game, but it's only when you actually try and create your own unique game from scratch, do you finally appreciate those games."[/center][center]Don't ask for answers if you haven't TRIED yet![/center][center]Most answers can be answered in the help file! Use it![/center]

Link to comment
Share on other sites

I tried to remake the game with a dropdownbox, but I have a little problem

The problem is where do I out the red line? at the place it is places the random value always returns 0

can you help me

#include <GuiConstants.au3>
#include <GuiCombo.au3>

Opt('MustDeclareVars',1)

Dim $Combo,$Btn_start, $Btn_Exit, $btn_go, $value, $msg, $Label, $Input, $try, $value,$random, $choice

GuiCreate("Guess the number", 392, 254)
$Combo = GuiCtrlCreateCombo("Max number", 70, 10, 270, 120)
GUICtrlSetData($Combo,"100|500|1000|1500|2000|3000|10000")


$Label = GuiCtrlCreateLabel("", 150, 50, 90, 30)
$Input = GuiCtrlCreateInput("", 150, 90, 90, 30)

$btn_go= GUICtrlCreateButton("GO", 150,140,90,30)
$Btn_Exit = GuiCtrlCreateButton("Exit", 150, 180, 90, 30)
$try=0


$random=random(1,GUICtrlRead($combo),1)


GUISetState()



    $try=$try+1

while 1
    $msg=GUIGetMsg()


    Select

        case $msg=$GUI_EVENT_CLOSE or $msg=$Btn_Exit
            ExitLoop
        case $msg=$btn_go




$value=GUICtrlRead($Input)
if $value < $random Then
            GUICtrlSetData($Label, "The number is bigger")
            guictrlsetdata($Input,"")
            $try=$try + 1
            ElseIf $value > $random Then
            GUICtrlSetData($Label, "The number is smaller")
            guictrlsetdata($Input,"")
            $try=$try + 1
        Else
            GUICtrlSetData($Label, "The number is correct!")
            ;beep()
            MsgBox(0, "You've won!", "The number was:" & $value)
            MsgBox(0, "You've won!", "Tries:" & $try)
            Exit
            EndIf






            EndSelect
        WEnd
        Exit


            
                


    Edited  by Steven Vandenhoute
    
    

            
        

        

        
            

    
        

        
            "You cannot solve a problem with the mind that created it" (Albert Einstein)
        
    

        
    

    

    




    Link to comment
    
        
    
    
    

    
    Share on other sites
    

    
        
            

    

        
            

    

        
            

    

        
            

    

        
    


    
    More sharing options...

    


    

                    
                    
                    
                

                    

                    
                    





    

    
        
            
                
                    Developers
                
                
                
                
            
        
    

    
        
            
                


    
        
    

                
                
                
                
                    
                        

                    
                
            
        
        
            
                


Jos
            
            
                Posted 
                
            
        
    
    
        


Jos
            
        
        
            
                
                    


    
        
    

                    
                        
                    
                    
                        

                    
                
            
            
                Developers
                
                    
                
            
            
                
                    
                        
                            
                                
                            
                                 34.3k
                            
                                
                            
                        
                        
                            
                                
                                    
                                        
                                        156
                                
                                    
                                
                            
                        
                    
                
            
            
                

    
    
        
Je maintiendrai
    
    

            
        
    
    
        



    
        
            
                
                    
                    
                        Developers
                    
                    
                    
                    
                
            
            
                
                    
                    
                        
                        
                            Share
                        
                        
                        
                        
                        
                            
                                
                            
                            
                            
                            
                            
                            
                        
                    
                
                
            
        

        
            Posted 
            
            
                
                
            
        
    

    

    

    
        
        
            You need to put your Random in the Loop:

#include <GuiConstants.au3>
#include <GuiCombo.au3>

Opt('MustDeclareVars', 1)

Dim $Combo, $Btn_start, $Btn_Exit, $btn_go, $value, $msg, $Label, $Input, $try, $value, $random, $choice

GUICreate("Guess the number", 392, 254)
$Combo = GUICtrlCreateCombo("Max number", 70, 10, 270, 120)
GUICtrlSetData($Combo, "100|500|1000|1500|2000|3000|10000")


$Label = GUICtrlCreateLabel("", 150, 50, 90, 30)
$Input = GUICtrlCreateInput("", 150, 90, 90, 30)

$btn_go = GUICtrlCreateButton("GO", 150, 140, 90, 30)
$Btn_Exit = GUICtrlCreateButton("Exit", 150, 180, 90, 30)
$try = 0

GUISetState()
$msg = GUIGetMsg()

$try = $try + 1
While 1
    $msg = GUIGetMsg()
    Select
        Case $msg = $GUI_EVENT_CLOSE Or $msg = $Btn_Exit
            ExitLoop
        Case $msg = $Combo  
            $random = Random(1, GUICtrlRead($Combo), 1)
        Case $msg = $btn_go
            $value = GUICtrlRead($Input)
            If $value < $random Then
                GUICtrlSetData($Label, "The number is bigger")
                GUICtrlSetData($Input, "")
                $try = $try + 1
            ElseIf $value > $random Then
                GUICtrlSetData($Label, "The number is smaller")
                GUICtrlSetData($Input, "")
                $try = $try + 1
            Else
                GUICtrlSetData($Label, "The number is correct!")
                ;beep()
                MsgBox(0, "You've won!", "The number was:" & $value)
                MsgBox(0, "You've won!", "Tries:" & $try)
                Exit
            EndIf
    EndSelect
WEnd
Exit

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...