HankHell Posted August 29, 2020 Posted August 29, 2020 (edited) made this quite a while back and never bothered to post it... was having a discussion with a friend I was talking to about code and figured I might as well post it.... to win: click on the squares in the order of R, G, B. Game lasts 100 seconds. Score is deducted for pressing the wrong color expandcollapse popup#include <GUIConstants.au3> Global $button1 Global $button2 Global $time Global $counter = 1 Global $colorstate1 = 1 Global $colorstate2 = 1 Global $colorstate3 = 1 HotKeySet("{ESC}", "Close") Global $score = 0 $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) $randomness3 = Random(1, 450) $randomnumber3 = Round($randomness3) $randomness4 = Random(1, 350) $randomnumber4 = Round($randomness4) $randomness5 = Random(1, 450) $randomnumber5 = Round($randomness5) $randomness6 = Random(1, 350) $randomnumber6 = Round($randomness6) Global $posx1 = $randomnumber1 Global $posy1 = $randomnumber2 Global $posx2 = $randomnumber3 Global $posy2 = $randomnumber4 Global $posx3 = $randomnumber5 Global $posy3 = $randomnumber6 GUICreate("random", 600, 500, @DesktopWidth / 4, @DesktopHeight / 4) $scorelabel = GUICtrlCreateLabel("Score: ", 150, 10) $scoregui = GUICtrlCreateLabel("", 200, 10, 100, 18) $timegui = GUICtrlCreateLabel("", 100, 450, 100, 18) GUICtrlSetColor($timegui, 0x085785) GUISetState(@SW_SHOW) $button1 = GUICtrlCreateButton("", $posx1, $posy1, 50, 50) $button2 = GUICtrlCreateButton("", $posx2, $posy2, 50, 50) $button3 = GUICtrlCreateButton("", $posx3, $posy3, 50, 50) GUICtrlSetBkColor($button1, 0x0000FF) GUICtrlSetBkColor($button2, 0x00FF00) GUICtrlSetBkColor($button3, 0xFF0000) While 1 If $counter = 1 Then Timer() EndIf SwitchCheck() WEnd Func Timer() $time += 1 GUICtrlSetData($timegui, $time) If $time = 10000 Then $counter = 0 GUICtrlSetState($button1, $GUI_DISABLE) GUICtrlSetState($button2, $GUI_DISABLE) GUICtrlSetState($button3, $GUI_DISABLE) GUICtrlCreateLabel("GAME OVER", 100, 435, 100, 15) EndIf EndFunc Func SwitchCheck() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button1 RandomFunc() $score -= 10 GUICtrlSetData($scoregui, $score) $colorstate1 += 1 If $colorstate1 = 1 Then GUICtrlSetBkColor($button1, 0x0000FF) EndIf If $colorstate1 = 2 Then GUICtrlSetBkColor($button1, 0xFF0000) EndIf If $colorstate1= 3 Then GUICtrlSetBkColor($button1, 0x00FF00) $colorstate1 = 0 EndIf $colorstate2 += 1 If $colorstate2 = 1 Then GUICtrlSetBkColor($button2, 0x00FF00) EndIf If $colorstate2 = 2 Then GUICtrlSetBkColor($button2, 0x0000FF) EndIf If $colorstate2 = 3 Then GUICtrlSetBkColor($button2, 0xFF0000) $colorstate2 = 0 EndIf $score += 3 GUICtrlSetData($scoregui, $score) $colorstate3 += 1 If $colorstate3 = 1 Then GUICtrlSetBkColor($button3, 0xFF0000) EndIf If $colorstate3 = 2 Then GUICtrlSetBkColor($button3, 0x00FF00) EndIf If $colorstate3 = 3 Then GUICtrlSetBkColor($button3, 0x0000FF) $colorstate3 = 0 EndIf Case $button2 RandomFunc() $score -= 20 GUICtrlSetData($scoregui, $score) $colorstate2 += 1 If $colorstate2 = 1 Then GUICtrlSetBkColor($button2, 0x00FF00) EndIf If $colorstate2 = 2 Then GUICtrlSetBkColor($button2, 0x0000FF) EndIf If $colorstate2 = 3 Then GUICtrlSetBkColor($button2, 0xFF0000) $colorstate2 = 0 EndIf $colorstate1 += 1 If $colorstate1 = 1 Then GUICtrlSetBkColor($button1, 0x0000FF) EndIf If $colorstate1 = 2 Then GUICtrlSetBkColor($button1, 0xFF0000) EndIf If $colorstate1= 3 Then GUICtrlSetBkColor($button1, 0x00FF00) $colorstate1 = 0 EndIf $score += 3 GUICtrlSetData($scoregui, $score) $colorstate3 += 1 If $colorstate3 = 1 Then GUICtrlSetBkColor($button3, 0xFF0000) EndIf If $colorstate3 = 2 Then GUICtrlSetBkColor($button3, 0x00FF00) EndIf If $colorstate3 = 3 Then GUICtrlSetBkColor($button3, 0x0000FF) $colorstate3 = 0 EndIf Case $button3 RandomFunc() $score += 3 GUICtrlSetData($scoregui, $score) $colorstate3 += 1 If $colorstate3 = 1 Then GUICtrlSetBkColor($button3, 0xFF0000) EndIf If $colorstate3 = 2 Then GUICtrlSetBkColor($button3, 0x00FF00) EndIf If $colorstate3 = 3 Then GUICtrlSetBkColor($button3, 0x0000FF) $colorstate3 = 0 EndIf $colorstate2 += 1 If $colorstate2 = 1 Then GUICtrlSetBkColor($button2, 0x00FF00) EndIf If $colorstate2 = 2 Then GUICtrlSetBkColor($button2, 0x0000FF) EndIf If $colorstate2 = 3 Then GUICtrlSetBkColor($button2, 0xFF0000) $colorstate2 = 0 EndIf $colorstate1 += 1 If $colorstate1 = 1 Then GUICtrlSetBkColor($button1, 0x0000FF) EndIf If $colorstate1 = 2 Then GUICtrlSetBkColor($button1, 0xFF0000) EndIf If $colorstate1= 3 Then GUICtrlSetBkColor($button1, 0x00FF00) $colorstate1 = 0 EndIf EndSwitch EndFunc Func RandomFunc() $RandomNumber = Random(1, 3) $RandomNumber = Round($RandomNumber) If $RandomNumber = 1 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button1, $randomnumber1, $randomnumber2) $Randomnumber = 2 EndIf If $RandomNumber = 2 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button2, $randomnumber1, $randomnumber2) $Randomnumber = 3 EndIf If $RandomNumber = 3 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button3, $randomnumber1, $randomnumber2) $Randomnumber = 1 EndIf ;--------------- If $RandomNumber = 1 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button1, $randomnumber1, $randomnumber2) $Randomnumber = 2 EndIf If $RandomNumber = 2 Then $randomness1 = Random(1, 450) $randomnumber1 = Round($randomness1) $randomness2 = Random(1, 350) $randomnumber2 = Round($randomness2) GUICtrlSetPos($button2, $randomnumber1, $randomnumber2) $Randomnumber = 3 EndIf EndFunc Func Close() Exit EndFunc Edited August 29, 2020 by HankHell Musashi and Gianni 2
CarlD Posted August 29, 2020 Posted August 29, 2020 (edited) Nice. A good mind-clearing exercise. (Playing the game, I mean.) Edited August 29, 2020 by CarlD HankHell 1
Gianni Posted August 30, 2020 Posted August 30, 2020 A nice fun toy thanks for sharing vaguely reminds me of this documentary: (https://www.autoitscript.com/forum/topic/189136-cool-stuff-on-youtube/?do=findComment&comment=1374877) On 8/29/2020 at 1:35 PM, HankHell said: ... was having a discussion with a friend I was talking to about code and figured I might as well post it.... Expand ... if you allow, speaking of the code, with a little revision it could be tweaked a bit ... expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Close") Global $iWinWidth = 600, $iWinHeight = 400, $iButtonXSide = 100, $iButtonYSide = Int(($iButtonXSide / 16) * 9), $sWinTitle = "RGB Game", $iTimeout = 10000 ; 10 seconds Global $aX[Int($iWinWidth / $iButtonXSide)], $aY[Int($iWinHeight / $iButtonYSide)], $iNdx = 0, $aPoints[3], $score, $iTimer, $iProgressHeight = 15 For $i = 0 To (Int($iWinWidth / $iButtonXSide) - 1) * $iButtonXSide Step $iButtonXSide $aX[$iNdx] = $i $iNdx += 1 Next $iNdx = 0 For $i = 0 To (Int($iWinHeight / $iButtonYSide) - 1) * $iButtonYSide Step $iButtonYSide $aY[$iNdx] = $i $iNdx += 1 Next Global $hGUI = GUICreate($sWinTitle, $iWinWidth, $iWinHeight + $iProgressHeight, @DesktopWidth / 4, @DesktopHeight / 5) Global $idProgressbar = GUICtrlCreateProgress(0, $iWinHeight + 1, $iWinWidth, $iProgressHeight) Global $button1 = GUICtrlCreateButton("R", 0, 0, $iButtonXSide, $iButtonYSide) Global $button2 = GUICtrlCreateButton("G", 0, 0, $iButtonXSide, $iButtonYSide) Global $button3 = GUICtrlCreateButton("B", 0, 0, $iButtonXSide, $iButtonYSide) GUICtrlSetBkColor($button1, 0xFF0000) GUICtrlSetBkColor($button2, 0x00FF00) GUICtrlSetBkColor($button3, 0x0000FF) GUISetState(@SW_SHOW) ; --- Main loop --- Do ; New match _RandomizeButtons() $aPoints[0] = 1 $aPoints[1] = -1 $aPoints[2] = -1 $score = 0 $iTimer = TimerInit() GUICtrlSetData($idProgressbar, 100) While TimerDiff($iTimer) < $iTimeout ; play until timeout Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Close() Case $button1 _SetNext(0) Case $button2 _SetNext(1) Case $button3 _SetNext(2) EndSwitch GUICtrlSetData($idProgressbar, 100 - (100 / $iTimeout * TimerDiff($iTimer))) WinSetTitle($hGUI, '', $sWinTitle & ' (Score: ' & StringFormat("%02d", $score) & ' points)') WEnd Until MsgBox(36 + 8192 + 65536, "Game over", "you have scored " & $score & " points" & @CRLF & @CRLF & "do you want to try again?") <> 6 Func _SetNext($ChosenColor) $score += $aPoints[$ChosenColor] ConsoleWrite($score & @CRLF) _ArrayPush($aPoints, $aPoints[UBound($aPoints) - 1], 1) ; rotate scores by 1 _RandomizeButtons() EndFunc ;==>_SetNext Func _RandomizeButtons() _ArrayShuffle($aX) _ArrayShuffle($aY) GUICtrlSetPos($button1, $aX[0], $aY[0]) GUICtrlSetPos($button2, $aX[1], $aY[1]) GUICtrlSetPos($button3, $aX[2], $aY[2]) EndFunc ;==>_RandomizeButtons Func Close() Exit EndFunc ;==>Close Musashi and HankHell 2 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
HankHell Posted August 30, 2020 Author Posted August 30, 2020 On 8/30/2020 at 9:35 AM, Chimp said: A nice fun toy thanks for sharing vaguely reminds me of this documentary: (https://www.autoitscript.com/forum/topic/189136-cool-stuff-on-youtube/?do=findComment&comment=1374877) ... if you allow, speaking of the code, with a little revision it could be tweaked a bit ... expandcollapse popup#include <GUIConstants.au3> #include <Array.au3> HotKeySet("{ESC}", "Close") Global $iWinWidth = 600, $iWinHeight = 400, $iButtonXSide = 100, $iButtonYSide = Int(($iButtonXSide / 16) * 9), $sWinTitle = "RGB Game", $iTimeout = 10000 ; 10 seconds Global $aX[Int($iWinWidth / $iButtonXSide)], $aY[Int($iWinHeight / $iButtonYSide)], $iNdx = 0, $aPoints[3], $score, $iTimer, $iProgressHeight = 15 For $i = 0 To (Int($iWinWidth / $iButtonXSide) - 1) * $iButtonXSide Step $iButtonXSide $aX[$iNdx] = $i $iNdx += 1 Next $iNdx = 0 For $i = 0 To (Int($iWinHeight / $iButtonYSide) - 1) * $iButtonYSide Step $iButtonYSide $aY[$iNdx] = $i $iNdx += 1 Next Global $hGUI = GUICreate($sWinTitle, $iWinWidth, $iWinHeight + $iProgressHeight, @DesktopWidth / 4, @DesktopHeight / 5) Global $idProgressbar = GUICtrlCreateProgress(0, $iWinHeight + 1, $iWinWidth, $iProgressHeight) Global $button1 = GUICtrlCreateButton("R", 0, 0, $iButtonXSide, $iButtonYSide) Global $button2 = GUICtrlCreateButton("G", 0, 0, $iButtonXSide, $iButtonYSide) Global $button3 = GUICtrlCreateButton("B", 0, 0, $iButtonXSide, $iButtonYSide) GUICtrlSetBkColor($button1, 0xFF0000) GUICtrlSetBkColor($button2, 0x00FF00) GUICtrlSetBkColor($button3, 0x0000FF) GUISetState(@SW_SHOW) ; --- Main loop --- Do ; New match _RandomizeButtons() $aPoints[0] = 1 $aPoints[1] = -1 $aPoints[2] = -1 $score = 0 $iTimer = TimerInit() GUICtrlSetData($idProgressbar, 100) While TimerDiff($iTimer) < $iTimeout ; play until timeout Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Close() Case $button1 _SetNext(0) Case $button2 _SetNext(1) Case $button3 _SetNext(2) EndSwitch GUICtrlSetData($idProgressbar, 100 - (100 / $iTimeout * TimerDiff($iTimer))) WinSetTitle($hGUI, '', $sWinTitle & ' (Score: ' & StringFormat("%02d", $score) & ' points)') WEnd Until MsgBox(36 + 8192 + 65536, "Game over", "you have scored " & $score & " points" & @CRLF & @CRLF & "do you want to try again?") <> 6 Func _SetNext($ChosenColor) $score += $aPoints[$ChosenColor] ConsoleWrite($score & @CRLF) _ArrayPush($aPoints, $aPoints[UBound($aPoints) - 1], 1) ; rotate scores by 1 _RandomizeButtons() EndFunc ;==>_SetNext Func _RandomizeButtons() _ArrayShuffle($aX) _ArrayShuffle($aY) GUICtrlSetPos($button1, $aX[0], $aY[0]) GUICtrlSetPos($button2, $aX[1], $aY[1]) GUICtrlSetPos($button3, $aX[2], $aY[2]) EndFunc ;==>_RandomizeButtons Func Close() Exit EndFunc ;==>Close Expand badass
Gianni Posted May 26, 2021 Posted May 26, 2021 for those who like this kind of games, here is a "similar" one: https://www.autoitscript.com/forum/topic/203788-are-you-smarter-than-a-chimp/ Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....
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