Jump to content



Photo

How fast are YOU?


  • Please log in to reply
7 replies to this topic

#1 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 24 August 2010 - 07:49 PM

Hiya!

A few people have asked me to remake my old game "Game: How fast are u?". Well, here it is!
Hope you guys enjoy!

There are still a few game modes I still have to program.

AutoIt         
#include <String.au3> #include <GUIConstantsEx.au3> #include <EditConstants.au3> #include <Timers.au3> Global $Diff, $Mode Global $CurTimer, $Timer MsgBox(64, "Welcome!", "How fast are YOU?"  & @CRLF & @CRLF & "A remake of my old game." & @CRLF & "- AlmarM") _GameStyle() Sleep(500) If ($Mode == "time") Then _TimePlay() If ($Mode == "score") Then _ScorePlay() If ($Mode == "challenge") Then _ChallengePlay() If ($Mode == "reflex") Then _ReflexPlay() Func _GameStyle()     $GUI = GUICreate("Select your gaming style!", 360, 305)     GUIStartGroup()     GUICtrlCreateLabel("Select your skill", 10, 10)     $Easy = GUICtrlCreateRadio("Easy", 10, 30)     $Medium = GUICtrlCreateRadio("Medium", 60, 30)     $Hard = GUICtrlCreateRadio("Hard", 10, 50)     $Insane = GUICtrlCreateRadio("Insane", 60, 50)     GUIStartGroup()     GUICtrlCreateLabel("Select game mode", 10, 90)     $Mode1 = GUICtrlCreateRadio("Mode 1", 10, 110)     GUICtrlCreateLabel("- Time play, click the buttons as fast as you can.", 10, 130)     $Mode2 = GUICtrlCreateRadio("Mode 2", 10, 150)     GUICtrlCreateLabel("- Score play, click as fast as possible to keep your score high.", 10, 170)     $Mode3 = GUICtrlCreateRadio("Mode 3", 10, 190)     GUICtrlCreateLabel("- Challenge play, click as many buttons as possible before time runs out.", 10, 210)     $Mode4 = GUICtrlCreateRadio("Mode 4", 10, 230)     GUICtrlCreateLabel("- Reflex play, click the button before it disappears.", 10, 250)     $Select = GUICtrlCreateButton("Select", 80, 275, 200, 20)     GUICtrlSetState($Easy, 1)     GUICtrlSetState($Mode1, 1)     GUISetState()     While Sleep(10)         Switch GUIGetMsg()             Case -3                 Exit             Case $Select                 If (GUICtrlRead($Easy) = 1) Then $Diff = "easy"                 If (GUICtrlRead($Medium) = 1) Then $Diff =  "medium"                 If (GUICtrlRead($Hard) = 1) Then $Diff = "hard"                 If (GUICtrlRead($Insane) = 1) Then $Diff = "insane"                 If (GUICtrlRead($Mode1) = 1) Then $Mode = "time"                 If (GUICtrlRead($Mode2) = 1) Then $Mode = "score"                 If (GUICtrlRead($Mode3) = 1) Then $Mode = "challenge"                 If (GUICtrlRead($Mode4) = 1) Then $Mode = "reflex"                 GUIDelete($GUI)                 ExitLoop         EndSwitch     WEnd EndFunc Func _TimePlay()     Local $aBtns[36]     Local $iCurBtn, $iNum = 1, $aLength = UBound($aBtns) - 1     Local $aAVG[1], $iAVGNum = -1     $GUI = GUICreate("* Difficulty: " & _StringProper($Diff) & " | Mode: Time Play *", 340, 530)     Local $Left, $Top, $Size, $RLeft     If ($Diff == "easy") Then         $Size = 45         $Left = 10         $RLeft = $Left         $Top = 10     EndIf     If ($Diff == "medium") Then         $Size = 35         $Left = 15         $RLeft = $Left         $Top = 15     EndIf     If ($Diff == "hard") Then         $Size = 25         $Left = 20         $RLeft = $Left         $Top = 20     EndIf     If ($Diff == "insane") Then         $Size = 15         $Left = 23         $RLeft = $Left         $Top = 23     EndIf     For $i = 0 To $aLength         $aBtns[$i] = GUICtrlCreateButton("", $Left, $Top, $Size, $Size)         GUICtrlSetState(-1, $GUI_DISABLE)         $Left += 55         For $x = 5 To 35 Step 6             Switch ($i)                 Case $x                     $Left = $RLeft                     $Top += 55             EndSwitch         Next     Next     GUICtrlSetData($aBtns[0], "x")     GUICtrlSetState($aBtns[0], $GUI_ENABLE)     $Edit = GUICtrlCreateEdit("Last saved time:" & @CRLF & @CRLF, 10, 345, 320, 150, $ES_READONLY + $ES_AUTOVSCROLL)     $Input = GUICtrlCreateInput("Avg: -", 10, 500, 60, 20, $ES_READONLY)     GUICtrlCreateLabel("seconds.", 75, 503)     $CurTimer = GUICtrlCreateInput("", 300, 500, 30)     GUISetState()     While 1         Switch GUIGetMsg()             Case -3                 Exit             Case $aBtns[0]                 GUICtrlSetData($aBtns[0], "")                 GUICtrlSetState($aBtns[0], $GUI_DISABLE)                 $Timer = _Timer_Init()              AdlibRegister("__setTime", 100)                 $R = Random(1, $aLength - 1, 1)                 GUICtrlSetState($aBtns[$R], $GUI_ENABLE)                 GUICtrlSetData($aBtns[$R], "x")                 $iCurBtn = $R                 $iNum += 1             Case $aBtns[$iCurBtn]                 If ($iNum < 25) Then                     GUICtrlSetData($aBtns[$iCurBtn], "")                     GUICtrlSetState($aBtns[$iCurBtn], $GUI_DISABLE)                     $iCurBtn = Random(1, $aLength - 1, 1)                     $iNum += 1                     GUICtrlSetData($aBtns[$iCurBtn], "x")                     GUICtrlSetState($aBtns[$iCurBtn], $GUI_ENABLE)                 Else                     GUICtrlSetData($aBtns[$iCurBtn], "")                     GUICtrlSetState($aBtns[$iCurBtn], $GUI_DISABLE)                     GUICtrlSetData($aBtns[$aLength], "x")                     GUICtrlSetState($aBtns[$aLength], $GUI_ENABLE)                 EndIf             Case $aBtns[$aLength]               AdlibUnRegister("__setTime")                 $Time = _Timer_Diff($Timer)              _Timer_KillTimer($GUI, $Timer)                 GUICtrlSetData($aBtns[$aLength], "")                 GUICtrlSetState($aBtns[$aLength], $GUI_DISABLE)                 GUICtrlSetData($aBtns[0], "x")                 GUICtrlSetState($aBtns[0], $GUI_ENABLE)                 $iNum = 0                 $iAVGNum += 1                 ReDim $aAVG[$iAVGNum + 1]                 $aAVG[$iAVGNum] = Round($Time / 1000, 1)                 GUICtrlSetData($Edit, Round($Time / 1000, 1) & " seconds." & @CRLF, "|")                 GUICtrlSetData($Input, "Avg: " & Round(_ArrayAverage($aAVG), 1))         EndSwitch     WEnd EndFunc Func __setTime()     GUICtrlSetData($CurTimer, Round((_Timer_Diff($Timer) / 1000) , 1)) EndFunc Func _ScorePlay()     Local $aBtns[36], $Play = False     Local $iCurBtn, $iNum = 1, $aLength = UBound($aBtns) - 1     Local $aAVG[1], $iAVGNum = -1, $Score = 2500     $GUI = GUICreate("* Difficulty: " & _StringProper($Diff) & " | Mode: Time Play *", 340, 530)     Local $Left, $Top, $Size, $RLeft     If ($Diff == "easy") Then         $Size = 45         $Left = 10         $RLeft = $Left         $Top = 10     EndIf     If ($Diff == "medium") Then         $Size = 35         $Left = 15         $RLeft = $Left         $Top = 15     EndIf     If ($Diff == "hard") Then         $Size = 25         $Left = 20         $RLeft = $Left         $Top = 20     EndIf     If ($Diff == "insane") Then         $Size = 15         $Left = 23         $RLeft = $Left         $Top = 23     EndIf     For $i = 0 To $aLength         $aBtns[$i] = GUICtrlCreateButton("", $Left, $Top, $Size, $Size)         GUICtrlSetState(-1, $GUI_DISABLE)         $Left += 55         For $x = 5 To 35 Step 6             Switch ($i)                 Case $x                     $Left = $RLeft                     $Top += 55             EndSwitch         Next     Next     GUICtrlSetData($aBtns[0], "x")     GUICtrlSetState($aBtns[0], $GUI_ENABLE)     $Edit = GUICtrlCreateEdit("Last saved score:" & @CRLF & @CRLF, 10, 345, 320, 150, $ES_READONLY + $ES_AUTOVSCROLL)     $Input = GUICtrlCreateInput("Avg: -", 10, 500, 60, 20, $ES_READONLY)     GUICtrlCreateLabel("score.", 75, 503)     $CurScore = GUICtrlCreateInput("", 300, 500, 30)     GUISetState()     While 1         Switch GUIGetMsg()             Case -3                 Exit             Case $aBtns[0]               $Score = 2500               GUICtrlSetData($CurScore, $Score)                 GUICtrlSetData($aBtns[0], "")                 GUICtrlSetState($aBtns[0], $GUI_DISABLE)                 $R = Random(1, $aLength - 1, 1)                 GUICtrlSetState($aBtns[$R], $GUI_ENABLE)                 GUICtrlSetData($aBtns[$R], "x")                 $iCurBtn = $R                 $iNum += 1                 $Play = True             Case $aBtns[$iCurBtn]               GUICtrlSetData($CurScore, $Score)                 If ($iNum < 25) Then                     $Score += 100                     GUICtrlSetData($aBtns[$iCurBtn], "")                     GUICtrlSetState($aBtns[$iCurBtn], $GUI_DISABLE)                     $iCurBtn = Random(1, $aLength - 1, 1)                     $iNum += 1                     GUICtrlSetData($aBtns[$iCurBtn], "x")                     GUICtrlSetState($aBtns[$iCurBtn], $GUI_ENABLE)                 Else                     GUICtrlSetData($aBtns[$iCurBtn], "")                     GUICtrlSetState($aBtns[$iCurBtn], $GUI_DISABLE)                     GUICtrlSetData($aBtns[$aLength], "x")                     GUICtrlSetState($aBtns[$aLength], $GUI_ENABLE)                 EndIf             Case $aBtns[$aLength]                 $Play = False                 GUICtrlSetData($aBtns[$aLength], "")                 GUICtrlSetState($aBtns[$aLength], $GUI_DISABLE)                 GUICtrlSetData($aBtns[0], "x")                 GUICtrlSetState($aBtns[0], $GUI_ENABLE)                 $iNum = 0                 $iAVGNum += 1                 ReDim $aAVG[$iAVGNum + 1]                 $aAVG[$iAVGNum] = $Score                 GUICtrlSetData($Edit, $Score & " score." & @CRLF, "|")                 GUICtrlSetData($Input, "Avg: " & _ArrayAverage($aAVG, 1))         EndSwitch         If ($Play) Then             Sleep(25)             $Score -= 4         EndIf     WEnd EndFunc Func _ChallengePlay()     Local $aBtns[36], $btnCount = 0, $R, $Play = False     Local $iCurBtn, $aLength = UBound($aBtns) - 1     Local $aAVG[1], $iAVGNum = -1     $GUI = GUICreate("* Difficulty: " & _StringProper($Diff) & " | Mode: Challenge Play *", 340, 530)     Local $Left, $Top, $Size, $RLeft     If ($Diff == "easy") Then         $Size = 45         $Left = 10         $RLeft = $Left         $Top = 10     EndIf     If ($Diff == "medium") Then         $Size = 35         $Left = 15         $RLeft = $Left         $Top = 15     EndIf     If ($Diff == "hard") Then         $Size = 25         $Left = 20         $RLeft = $Left         $Top = 20     EndIf     If ($Diff == "insane") Then         $Size = 15         $Left = 23         $RLeft = $Left         $Top = 23     EndIf     For $i = 0 To $aLength         $aBtns[$i] = GUICtrlCreateButton("", $Left, $Top, $Size, $Size)         GUICtrlSetState(-1, $GUI_DISABLE)         $Left += 55         For $x = 5 To 35 Step 6             Switch ($i)                 Case $x                     $Left = $RLeft                     $Top += 55             EndSwitch         Next     Next     GUICtrlSetData($aBtns[0], "x")     GUICtrlSetState($aBtns[0], $GUI_ENABLE)     $Edit = GUICtrlCreateEdit("Last saved count:" & @CRLF & @CRLF, 10, 345, 320, 150, $ES_READONLY + $ES_AUTOVSCROLL)     $Input = GUICtrlCreateInput("Avg: -", 10, 500, 60, 20, $ES_READONLY)     GUICtrlCreateLabel("buttons.", 75, 503)     $CurTimer = GUICtrlCreateInput("", 300, 500, 30)     GUISetState()     While 1         Switch GUIGetMsg()             Case -3                 Exit             Case $aBtns[0]             $btnCount = 0             $Timer = _Timer_Init()              AdlibRegister("__setTimer", 100)              $Play = True                 GUICtrlSetData($aBtns[0], "")                 GUICtrlSetState($aBtns[0], $GUI_DISABLE)                 $R = Random(1, $aLength - 1, 1)                 GUICtrlSetState($aBtns[$R], $GUI_ENABLE)                 GUICtrlSetData($aBtns[$R], "x")                 $iCurBtn = $R             Case $aBtns[$iCurBtn]             $btnCount += 1             GUICtrlSetData($aBtns[$iCurBtn], "")             GUICtrlSetState($aBtns[$iCurBtn], $GUI_DISABLE)             $iCurBtn = Random(1, $aLength - 1, 1)                GUICtrlSetData($aBtns[$iCurBtn], "x")                GUICtrlSetState($aBtns[$iCurBtn], $GUI_ENABLE)             Case $aBtns[$aLength]               AdlibUnRegister("__setTimer")              _Timer_KillTimer($GUI, $Timer)              GUICtrlSetData($CurTimer, 0)                 GUICtrlSetData($aBtns[$aLength], "")                 GUICtrlSetState($aBtns[$aLength], $GUI_DISABLE)                 GUICtrlSetData($aBtns[0], "x")                 GUICtrlSetState($aBtns[0], $GUI_ENABLE)                 $iAVGNum += 1                 ReDim $aAVG[$iAVGNum + 1]                 $aAVG[$iAVGNum] = $btnCount                 GUICtrlSetData($Edit, $btnCount & " buttons clicked." & @CRLF, "|")                 GUICtrlSetData($Input, "Avg: " & Round(_ArrayAverage($aAVG), 1))         EndSwitch         If ($Play) Then             If (Round(_Timer_Diff($Timer) / 1000, 1) > 20) Then                 GUICtrlSetData($aBtns[$iCurBtn], "")                 GUICtrlSetState($aBtns[$iCurBtn], $GUI_DISABLE)                 GUICtrlSetData($aBtns[$aLength], "x")                 GUICtrlSetState($aBtns[$aLength], $GUI_ENABLE)                 AdlibUnRegister("__setTimer")                 $Play = False             EndIf         EndIf     WEnd EndFunc Func __setTimer()     GUICtrlSetData($CurTimer, Round(_Timer_Diff($Timer) / 1000, 1)) EndFunc Func _ReflexPlay()     $GUI = GUICreate("* Difficulty: " & _StringProper($Diff) & " | Mode: Reflex Play *", 150, 30)     GUICtrlCreateLabel("*** Under construction ***", 14, 10)     GUISetState()     While 1         Switch GUIGetMsg()             Case -3                 Exit         EndSwitch     WEnd EndFunc ; # --------------------------- Func _ArrayAverage(ByRef $Array, $iRound = 0)     Local $aTotal = _ArrayTotal($Array, 1)     If ($iRound == 0) Then Return ($aTotal[1] / $aTotal[0])     If ($iRound == 1) Then Return Round(($aTotal[1] / $aTotal[0]), 0) EndFunc Func _ArrayTotal(ByRef $Array, $iOption = 0, $iRound = 0)     If Not IsArray($Array) Then Return SetError(1, 0, 0)     Local $iTmp = 0     For $i = 0 To UBound($Array) - 1         $iTmp2 = $iTmp         $iTmp = $Array[$i] + $iTmp2     Next     Switch ($iOption)         Case 0             If ($iRound == 0) Then Return $iTmp             If ($iRound == 1) Then Return Round($iTmp, 0)         Case 1             Local $aReturn[2]             $aReturn[0] = UBound($Array)             If ($iRound == 0) Then $aReturn[1] = $iTmp             If ($iRound == 1) Then $aReturn[1] = Round($iTmp, 0)             Return $aReturn     EndSwitch EndFunc


Post your personal records!

AlmarM ;)

EDIT [25-08-'10]: Added Mode 2!
EDIT [28-08-'10]: Added Mode 3!

Edited by AlmarM, 28 August 2010 - 11:20 AM.








#2 MrCreatoR

MrCreatoR

    Must AutoIt!

  • MVPs
  • 3,241 posts

Posted 24 August 2010 - 10:05 PM

Niiice.

14 secs is my avarage, i think i can do faster, but my mouse hand is tierd ;) .
Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

Posted Image AutoIt Russian CommunityPosted Image Projects: ATT - Application Translate Tool [new] | BlockIt - Block files & folders [new] | SIP - Selected Image Preview [new] | SISCABMAN - SciTE Abbreviations Manager [new] | AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramPosted Image UDFs: OnAutoItErrorRegister - Handle AutoIt critical errors [new] | AutoIt Syntax Highlight [new] | Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDFPosted Image Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation DemoLike the examples/UDFs? Please rate the topic (up-right corner of the post header: Rating Posted Image)* === My topics === *

==========================================================Posted Image==========================================================

AutoIt is simple, subtle, elegant. © AutoIt Team


#3 TinyHacker

TinyHacker

    Seeker

  • Banned (NOT IN USE)
  • 41 posts

Posted 24 August 2010 - 10:16 PM

great, waiting for the other games Posted Image

#4 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 25 August 2010 - 06:49 AM

I'm at work now, mayby I can put some time on the other game-mode while having a coffee break. ;)

EDIT: Tested on XP, wow looks awful. :)

Edited by AlmarM, 25 August 2010 - 12:23 PM.


#5 FinalVersion

FinalVersion

    0 ^ 1

  • Active Members
  • PipPipPipPipPipPip
  • 599 posts

Posted 25 August 2010 - 12:26 PM

Can't wait for Mode 4.

#6 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 25 August 2010 - 12:32 PM

I'm not sure if I can make those modes at work, im using XP here and it looks awful. ;)

I'll do my best.

Edited by AlmarM, 25 August 2010 - 01:04 PM.


#7 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 25 August 2010 - 01:02 PM

Made 'Mode 2: Score Play'!

Have fun ;)

#8 AlmarM

AlmarM

    Programming my way.

  • Active Members
  • PipPipPipPipPipPip
  • 1,642 posts

Posted 28 August 2010 - 11:20 AM

Made 'Mode 3: Challenge Play'!

Have fun ;)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users