magician13134 Posted July 23, 2007 Share Posted July 23, 2007 (edited) I just got back from computer camp where I learned C++, so that affected my coding style, sorry if it's not as efficient and organized as it could be... Anyway, everyone there was great at counter strike, and I'm not, so I wrote this program to help increase my reflexes... Just thought it might be useful to some people... so, here you go... expandcollapse popup#include <GUIConstants.au3> $width = 45 $height = 45 $color = 0xFF0000 $bestTimeCount = "" $clicks = 0 $totalAverage = 0 $generousAverage = 0 $GUI = GUICreate("Reflex tester", 945, 800, 193, 115) $lastTime = GUICtrlCreateLabel("Last time: ", 16, 688, 200, 17) $bestTime = GUICtrlCreateLabel("Best time: ", 16, 728, 200, 17) $timesGroup = GUICtrlCreateGroup("Times", 8, 656, 249, 105) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("", 8, 8, 929, 641) GUICtrlCreateGroup("", -99, -99, 1, 1) $optionsGroup = GUICtrlCreateGroup("Options", 272, 656, 665, 105) $colorBox = GUICtrlCreateInput("FF0000", 288, 688, 121, 21) $widthBox = GUICtrlCreateInput("45", 456, 688, 121, 21) $heightBox = GUICtrlCreateInput("45", 624, 688, 121, 21) $delayBox = GUICtrlCreateInput("2500", 800, 688, 121, 21) $Label1 = GUICtrlCreateLabel("Color", 344, 728, 28, 17) $Label2 = GUICtrlCreateLabel("Width", 504, 728, 32, 17) $Label3 = GUICtrlCreateLabel("Height", 672, 728, 35, 17) $Label4 = GUICtrlCreateLabel("Max. delay (mS)", 826, 728, 75, 17) $startPause = GUICtrlCreateButton("Pause", (945 - 100) / 2, 768, 100, 25) ;GUICtrlSetState(-1, $GUI_DISABLE) GUICtrlCreateGroup("", -99, -99, 1, 1) GUISetState(@SW_SHOW) $button = GUICtrlCreateButton("Press to begin", (945 - 200) / 2, (641 - 200) / 2, 200, 200) GUICtrlSetBkColor(-1, 0x00FF00) while 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) if $msg = $button then GUICtrlDelete($button) exitLoop endIf wEnd while 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) if execute("0x" & GUICtrlRead($colorBox)) <> $color Then $color = execute("0x" & GUICtrlRead($colorBox)) endIf if GUICtrlRead($widthBox) <> $width Then $width = GUICtrlRead($widthBox) if $width > 450 then $width = 450 GUICtrlSetData($widthBox, 450) endIf endIf if GUICtrlRead($heightBox) <> $height Then $height = GUICtrlRead($heightBox) if $height > 450 then $height = 450 GUICtrlSetData($heightBox, 450) endIf endIf if $msg = $startPause then startPause() for $i = 0 to random(0, GUICtrlRead($delayBox)) step 5 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE Then _exit($clicks, $totalAverage, $generousAverage) next _generate(random(15, 929-($width+10)), random(15, 641-($height+10)), $width, $height) $timer = timerInit() while 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) if $msg = $startPause then startPause() exitLoop endIf if $msg = $button then _hit(timerDiff($timer), $lastTime, $bestTime, $bestTimeCount, $clicks, $totalAverage, $generousAverage) exitLoop endIf wEnd wEnd func _generate($x, $y, ByRef $_width, ByRef $_height) Global $button = GUICtrlCreateButton("", $x, $y, $_width, $_height) GUICtrlSetBkColor(-1, $color) endFunc func startPause() if GUICtrlRead($startPause) == "Pause" then GUICtrlSetData($startPause, "Resume") while 1 $msg = GUIGetMsg() if $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) if $msg = $startPause then GUICtrlSetData($startPause, "Pause") GUICtrlDelete($button) $timer = timerInit() Return EndIf WEnd endIf endFunc func _hit($_time, ByRef $_lastTime, ByRef $_bestTime, Byref $_bestTimeCount, ByRef $_clicks, ByRef $_totalAverage, ByRef $_generousAverage) $_time-=50 ; Accounts for lag from the point your mouse is pressed (actual reflex) to the point it is released (function triggered) GUICtrlSetData($_lastTime, "Last time: " & $_time & " mS") if $bestTimeCount == "" or $_time < $_bestTimeCount Then GUICtrlSetData($_bestTime, "Best time: " & $_time & " mS") $_bestTimeCount = $_time EndIf $_clicks+=1 $_totalAverage+=$_time if $_time < 5000 then $_generousAverage+=$_time endIf GUICtrlDelete($button) endFunc func _exit($_clicks, $_totalAverage, $_generousAverage) if $clicks > 0 then local $date = @MON & "/" & @MDAY & "/" & @YEAR $_totalAverage/=$_clicks $_generousAverage/=$_clicks msgBox(0, "Your scores are:", "Clicks: " & $_clicks & @CRLF & "Average (mS): " & $_totalAverage & @CRLF & "Average excluding those over 5 seconds: " & $_generousAverage) if msgBox(4, "Save your scores", "Save your scores to 'scores.txt'?") == 6 then fileWrite("scores.txt", "Clicks: " & $_clicks & @CRLF & "Average (mS): " & $_totalAverage & @CRLF & "Average excluding those over 5 seconds: " & $_generousAverage & @CRLF & "----------Generated by the Magic Soft Inc. Reflex Tester on " & $date & "----------" & @CRLF) endIf endIf destruct() exit endFunc func destruct() ; I'm sure this isn't helpful at all, but whatever GUIDelete($GUI) $bestTime = "" $_bestTime = "" $bestTimeCount = "" $_bestTimeCount = "" $button = "" $clicks = "" $_clicks = "" $color = "" $_color = "" $colorBox = "" $date = "" $delayBox = "" $generousAverage = "" $Group2 = "" $GUI = "" $height = "" $_height = "" $heightBox = "" $Label1 = "" $Label2 = "" $Label3 = "" $Label4 = "" $lastTime = "" $optionsGroup = "" $width = "" $_width = "" endFunc Edited July 23, 2007 by magician13134 Visit Magic Soft Inc. for some of my software Link to comment Share on other sites More sharing options...
Cristian Posted April 1, 2008 Share Posted April 1, 2008 Nice Link to comment Share on other sites More sharing options...
Toady Posted April 1, 2008 Share Posted April 1, 2008 Good. www.itoady.com A* (A-star) Searching Algorithm - A.I. Artificial Intelligence bot path finding Link to comment Share on other sites More sharing options...
DexterMorgan Posted April 2, 2008 Share Posted April 2, 2008 This is really good. I am very bad at it my avg. is 790.. i have really bad reflexes lol.. Love the game it is fun! Sort of code Link to comment Share on other sites More sharing options...
magician13134 Posted May 28, 2008 Author Share Posted May 28, 2008 It's been awhile since I worked on this, just thought I upload a slightly upgraded script. I know this could have been coded a lot better, but I'm to lazy to fix it now... It works, so... I'll let it be expandcollapse popup#include <GUIConstants.au3> $width = 45 $height = 45 $color = 0xFF0000 $bestTimeCount = "" $clicks = 0 $totalAverage = 0 $generousAverage = 0 $misses = 0 $button = "" $GUI = GUICreate("Reflex tester", 945, 800, -1, 0) $lastTime = GUICtrlCreateLabel("Last time: ", 16, 688, 200, 17) $bestTime = GUICtrlCreateLabel("Best time: ", 16, 708, 200, 17) $missesLabel = GUICtrlCreateLabel("Misses: ", 16, 728, 200, 17) $timesGroup = GUICtrlCreateGroup("Times", 8, 656, 249, 105) GUICtrlCreateGroup("", -99, -99, 1, 1) $Group2 = GUICtrlCreateGroup("", 8, 8, 929, 641) GUICtrlCreateGroup("", -99, -99, 1, 1) $label = GUICtrlCreateLabel("", 8, 8, 929, 641) $optionsGroup = GUICtrlCreateGroup("Options", 272, 656, 665, 110) $colorBox = GUICtrlCreateInput("FF0000", 288, 678, 121, 21) $widthBox = GUICtrlCreateInput("45", 456, 678, 121, 21) $heightBox = GUICtrlCreateInput("45", 624, 678, 121, 21) $delayBox = GUICtrlCreateInput("2500", 800, 678, 121, 21) $Label1 = GUICtrlCreateLabel("Color", 344, 703, 28, 17) $Label2 = GUICtrlCreateLabel("Width", 504, 703, 32, 17) $Label3 = GUICtrlCreateLabel("Height", 672, 703, 35, 17) $Label4 = GUICtrlCreateLabel("Max. delay (mS)", 826, 703, 75, 17) $decoyCheckBox = GUICtrlCreateCheckbox("Decoy?", 800, 738, 121) GUICtrlSetState(-1, $GUI_CHECKED) $decoyColorBox = GUICtrlCreateInput("AA0000", 288, 738, 121, 21) $decoyWidthBox = GUICtrlCreateInput("45", 456, 738, 121, 21) $decoyHeightBox = GUICtrlCreateInput("45", 624, 738, 121, 21) $startPause = GUICtrlCreateButton("Pause", (945 - 100) / 2, 768, 100, 25) GUICtrlCreateGroup("", -99, -99, 1, 1) $decoy = GUICtrlCreateButton("", -200, -200, 0, 0) GUISetState(@SW_SHOW) $button2 = GUICtrlCreateButton("Press to begin", (945 - 200) / 2, (641 - 200) / 2, 200, 200) GUICtrlSetBkColor(-1, 0x00FF00) GUICtrlSetState(-1, $GUI_ONTOP) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) If $msg = $button2 then GUICtrlDelete($button2) exitLoop EndIf WEnd GUICtrlSetState($colorBox, $GUI_DISABLE) GUICtrlSetState($widthBox, $GUI_DISABLE) GUICtrlSetState($heightBox, $GUI_DISABLE) GUICtrlSetState($delayBox, $GUI_DISABLE) GUICtrlSetState($decoyColorBox, $GUI_DISABLE) GUICtrlSetState($decoyWidthBox, $GUI_DISABLE) GUICtrlSetState($decoyHeightBox, $GUI_DISABLE) While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) If execute("0x" & GUICtrlRead($colorBox)) <> $color Then $color = execute("0x" & GUICtrlRead($colorBox)) EndIf If GUICtrlRead($widthBox) <> $width Then $width = GUICtrlRead($widthBox) If $width > 450 then $width = 450 GUICtrlSetData($widthBox, 450) EndIf EndIf If GUICtrlRead($heightBox) <> $height Then $height = GUICtrlRead($heightBox) If $height > 450 then $height = 450 GUICtrlSetData($heightBox, 450) EndIf EndIf If $msg = $startPause then startPause() For $i = 0 to random(0, GUICtrlRead($delayBox)) step 5 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then _exit($clicks, $totalAverage, $generousAverage) Next _generate(random(15, 929-($width+10)), random(15, 641-($height+10)), $width, $height) $timer = timerInit() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) If $msg = $startPause then startPause() ExitLoop EndIf If $msg = $label Then $misses+=1 GUICtrlSetData($missesLabel, "Misses: " & $misses) EndIf If $msg = $button then _hit(timerDIff($timer), $lastTime, $bestTime, $bestTimeCount, $clicks, $totalAverage, $generousAverage) ExitLoop EndIf WEnd wEnd func _generate($x, $y, ByRef $_width, ByRef $_height) $button = GUICtrlCreateButton("", Int($x), Int($y), $_width, $_height) GUICtrlSetBkColor(-1, Execute("0x" & GUICtrlRead($colorBox))) GUICtrlSetState($button, $GUI_ONTOP) If GUICtrlRead($decoyCheckBox) == 1 Then $newX = random(15, 929-($width+10)) $newY = random(15, 641-($height+10)) While $newX + GUICtrlRead($decoyWidthBox) > $x and $newX < $x + $_width and $newY + GUICtrlRead($decoyHeightBox) > $y and $newY < $y + $_height $newX = random(15, 929-($width+10)) $newY = random(15, 641-($height+10)) WEnd GUICtrlSetBkColor($decoy, Execute("0x" & GUICtrlRead($decoyColorBox))) GUICtrlSetPos($decoy, $newX, $newY, GUICtrlRead($decoyWidthBox), GUICtrlRead($decoyHeightBox)) Else GUICtrlSetPos($decoy, -200, -200) EndIf endFunc func startPause() If GUICtrlRead($startPause) == "Pause" then GUICtrlSetState($colorBox, $GUI_ENABLE) GUICtrlSetState($widthBox, $GUI_ENABLE) GUICtrlSetState($heightBox, $GUI_ENABLE) GUICtrlSetState($delayBox, $GUI_ENABLE) GUICtrlSetState($decoyColorBox, $GUI_ENABLE) GUICtrlSetState($decoyWidthBox, $GUI_ENABLE) GUICtrlSetState($decoyHeightBox, $GUI_ENABLE) GUICtrlSetData($startPause, "Resume") While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE then _exit($clicks, $totalAverage, $generousAverage) If $msg = $startPause then GUICtrlSetData($startPause, "Pause") GUICtrlDelete($button) $timer = timerInit() GUICtrlSetState($colorBox, $GUI_DISABLE) GUICtrlSetState($widthBox, $GUI_DISABLE) GUICtrlSetState($heightBox, $GUI_DISABLE) GUICtrlSetState($delayBox, $GUI_DISABLE) GUICtrlSetState($decoyColorBox, $GUI_DISABLE) GUICtrlSetState($decoyWidthBox, $GUI_DISABLE) GUICtrlSetState($decoyHeightBox, $GUI_DISABLE) Return EndIf WEnd EndIf endFunc func _hit($_time, ByRef $_lastTime, ByRef $_bestTime, Byref $_bestTimeCount, ByRef $_clicks, ByRef $_totalAverage, ByRef $_generousAverage) $_time-=50 ; Accounts for lag from the point your mouse is pressed (actual reflex) to the point it is released (function triggered) GUICtrlSetData($_lastTime, "Last time: " & $_time & " mS") If $bestTimeCount == "" or $_time < $_bestTimeCount Then GUICtrlSetData($_bestTime, "Best time: " & $_time & " mS") $_bestTimeCount = $_time EndIf $_clicks+=1 $_totalAverage+=$_time If $_time < 5000 then $_generousAverage+=$_time EndIf GUICtrlDelete($button) endFunc func _exit($_clicks, $_totalAverage, $_generousAverage) If $clicks > 0 then local $date = @MON & "/" & @MDAY & "/" & @YEAR $_totalAverage/=$_clicks $_generousAverage/=$_clicks MsgBox(0, "Your scores are:", "Clicks: " & $_clicks & @CRLF & "Misses: " & $misses & @CRLF & "Average (mS): " & $_totalAverage & @CRLF & "Average excluding those over 5 seconds: " & $_generousAverage) If MsgBox(4, "Save your scores", "Save your scores to 'scores.txt'?") == 6 then FileWrite("scores.txt", "Clicks: " & $_clicks & @CRLF & "Misses: " & $misses & @CRLF & "Average (mS): " & $_totalAverage & @CRLF & "Average excluding those over 5 seconds: " & $_generousAverage & @CRLF & "----------Generated by the Magic Soft Inc. Reflex Tester on " & $date & "----------" & @CRLF) EndIf EndIf destruct() Exit endFunc func destruct() ; I'm sure this isn't helpful at all, but whatever GUIDelete($GUI) $bestTime = "" $_bestTime = "" $bestTimeCount = "" $_bestTimeCount = "" $button = "" $clicks = "" $_clicks = "" $color = "" $_color = "" $colorBox = "" $date = "" $delayBox = "" $generousAverage = "" $Group2 = "" $GUI = "" $height = "" $_height = "" $heightBox = "" $Label1 = "" $Label2 = "" $Label3 = "" $Label4 = "" $lastTime = "" $optionsGroup = "" $width = "" $_width = "" endFunc Heh, try it at 10x10 pixels. Quite challenging! Visit Magic Soft Inc. for some of my software Link to comment Share on other sites More sharing options...
SxyfrG Posted May 29, 2008 Share Posted May 29, 2008 I'm quite good at CS:S and only got 600ms with the decoy. Nice script My scripts:AppLauncherTRAY - Awesome app launcher that runs from the system tray NEW VERSION! | Run Length Encoding - VERY simple compression in pure autoit | Simple Minesweeper Game - Fun little game :)My website Link to comment Share on other sites More sharing options...
Skrip Posted May 29, 2008 Share Posted May 29, 2008 Sweet. I'll give this a shot when I get home. And Sxyfrg mind making your signature a little smaller please? [left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left] 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