Steven Vandenhoute Posted October 13, 2006 Posted October 13, 2006 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? expandcollapse popup#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)
Vindicator209 Posted October 13, 2006 Posted October 13, 2006 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]
gamerman2360 Posted October 14, 2006 Posted October 14, 2006 Lol, cool. I made one of these. It's somewhere on the fourms.
Steven Vandenhoute Posted October 14, 2006 Author Posted October 14, 2006 Well, as another example I will try to work with a dropdown box where I can choice between witch numbers the game will work. I want to try as much items I can work with it. "You cannot solve a problem with the mind that created it" (Albert Einstein)
Steven Vandenhoute Posted October 14, 2006 Author Posted October 14, 2006 (edited) 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 expandcollapse popup #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 October 14, 2006 by Steven Vandenhoute "You cannot solve a problem with the mind that created it" (Albert Einstein) Developers Jos Posted October 14, 2006 Jos Developers 34.7k 169 Je maintiendrai Developers Posted October 14, 2006 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.
Steven Vandenhoute Posted October 14, 2006 Author Posted October 14, 2006 thx for the quick repley that was idd the case "You cannot solve a problem with the mind that created it" (Albert Einstein)
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