Jump to content



Photo

Reflex game


  • Please log in to reply
9 replies to this topic

#1 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 24 October 2007 - 12:40 PM

I'm bored and created that little game.
First game = Try click 10 correct button fast as you can.
Second game = Try click more correct button as you can in 10 second.

Posted Image
Posted Image

AutoIt         
#include <GUIConstants.au3> #include <GuiStatusBar.au3> #include <GuiListBox.au3> #include <File.au3> Global $Button[6][6], $List[3], $Game, $Found = False, $Myini = "GameScores.ini", $Check = False, $Timerr Local $aParts[2] = [135, 300] $Gui = GUICreate("FLEXY", 270, 320) $hStatus = _GUICtrlStatusBar_Create ($Gui) _GUICtrlStatusBar_SetMinHeight ($hStatus, 20) _GUICtrlStatusBar_SetParts ($hStatus, $aParts) If @OSTYPE = "WIN32_WINDOWS" Then     $progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)     $hProgress = GUICtrlGetHandle($progress)     _GUICtrlStatusBar_EmbedControl ($hStatus, 1, $hProgress) Else     $progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)     $hProgress = GUICtrlGetHandle($progress)     _GUICtrlStatusBar_EmbedControl ($hStatus, 1, $hProgress)     _SendMessage($hProgress, $PBM_SETMARQUEE, True, 200) EndIf For $x = 1 To 5     For $y = 1 To 5         $Left = ($x * 50) - 40         $Top = ($y * 50) - 10         $Button[$x][$y] = GUICtrlCreateButton("", $Left, $Top, 50, 50)         GUICtrlSetFont(-1, 28, 800, 0, "Comic Sans MS")     Next Next $Button1 = GUICtrlCreateButton("Start first game", 10, 8, 102, 25, 0) $Button2 = GUICtrlCreateButton("Start second game", 112, 8, 104, 25, 0) $Button3 = GUICtrlCreateButton("Scores", 216, 8, 49, 25, 0) GUICtrlSetTip($Button1, "Try click 10 correct button fast as you can.") GUICtrlSetTip($Button2, "Try click more correct button as you can in 10 second.") GUICtrlSetTip($Button3, "Showing high scores.") $Gui2 = GUICreate("High Scores", 235, 167, 250, 311, BitOR($WS_SYSMENU, $WS_CAPTION, $WS_POPUP, $WS_POPUPWINDOW, $WS_BORDER, $WS_CLIPSIBLINGS)) $List[1] = GUICtrlCreateList("", 8, 24, 105, 136, $WS_BORDER) $List[2] = GUICtrlCreateList("", 120, 24, 105, 136, $WS_BORDER) GUICtrlSetData($List[1], "1.|2.|3.|4.|5.|6.|7.|8.|9.|10.") GUICtrlSetData($List[2], "1.|2.|3.|4.|5.|6.|7.|8.|9.|10.") $Label1 = GUICtrlCreateLabel("Game 1 High Scores", 8, 8, 102, 17) $Label2 = GUICtrlCreateLabel("Game 2 High Scores", 120, 8, 102, 17) GUISetState(@SW_SHOW, $Gui) Load() While 1     $msg = GUIGetMsg(1)     Select         Case $msg[0] = $Button1             $Var = 0             $Score = Start(1)         Case $msg[0] = $Button2             $Var = 0             $Score = Start(2)         Case $msg[0] = $Button3             GUISetState(@SW_SHOW, $Gui2)             Load()         Case $msg[0] = $GUI_EVENT_CLOSE             If $msg[1] = $Gui Then Exit             If $msg[1] = $Gui2 Then GUISetState(@SW_HIDE, $Gui2)             Save()     EndSelect WEnd Func Start($Game)     GUISetState(@SW_HIDE, $Gui2)     $Begin = TimerInit()     While 1         $x = Random(1, 5, 1)         $y = Random(1, 5, 1)         GUICtrlSetData($Button[$x][$y], "X")         While 1             $Flicker = TimerInit()             $msg = GUIGetMsg()             Switch $msg                 Case $Button[$x][$y]                     SoundPlay(@WindowsDir & "\media\ding.wav")                     $Var += 1                     ExitLoop                 Case $GUI_EVENT_CLOSE                     Exit             EndSwitch             For $xx = 1 To 5                 For $yy = 1 To 5                     If $Button[$x][$y] <> $Button[$xx][$yy] Then                         If $msg = $Button[$xx][$yy] Then                             SoundPlay(@WindowsDir & "\media\chimes.wav")                             $Var -= 1                             If $Game = 1 Then                                 $Bar = $Var * 10                                 GUICtrlSetData($progress, $Bar)                             EndIf                         EndIf                     EndIf                 Next             Next             _Timer($Flicker, 0.1)             If $Game = 2 Then                 $Timer = Round(TimerDiff($Begin), 0) / 1000                 $Bar = ($Timer / 10) * 100                 GUICtrlSetData($progress, $Bar)                 If $Check = True Then                     _GUICtrlStatusBar_SetText ($hStatus, "Current score : " & $Var)                     $Check = False                 EndIf                 If $Timer >= 10 Then                     MsgBox("", "", "Game 2 score : " & $Var & " points in 10 second.")                     ExitLoop 2                 EndIf             Else                 If $Check = True Then                     $Timer = Round(TimerDiff($Begin), 0)                     _GUICtrlStatusBar_SetText ($hStatus, "Current score : " & $Timer)                     $Check = False                 EndIf             EndIf         WEnd         If $Game = 1 Then             $Bar = $Var * 10             GUICtrlSetData($progress, $Bar)             If $Var = 10 Then                 $Timer = TimerDiff($Begin)                 $Var = Round($Timer, 0)                 MsgBox("", "", "Game 1 score : " & $Var & " ms.")                 ExitLoop             EndIf         EndIf         GUICtrlSetData($Button[$x][$y], "")     WEnd     Reset()     Highscore($Var, $Game) EndFunc   ;==>Start Func Reset()     GUICtrlSetData($Button[$x][$y], "")     _GUICtrlStatusBar_SetText ($hStatus, "")     GUICtrlSetData($progress, 0) EndFunc   ;==>Reset Func Highscore($Score, $z)     For $i = 1 To 10         If $Found = False Then             $String = StringSplit(_GUICtrlListBox_GetText ($List[$z], $i - 1), ".")             If $z = 1 Then                 If $String[2] > $Score Or $String[2] = "" Or $String[2] = " " Then                     _GUICtrlListBox_InsertString ($List[$z], $i & ". " & $Score, $i - 1)                     $Var = $i                     $Found = True                 EndIf             Else                 If $String[2] < $Score Or $String[2] = "" Or $String[2] = " " Then                     _GUICtrlListBox_InsertString ($List[$z], $i & ". " & $Score, $i - 1)                     $Var = $i                     $Found = True                 EndIf             EndIf         Else             ExitLoop         EndIf     Next     $Found = False     Arrange()     GUISetState(@SW_SHOW, $Gui2)     _GUICtrlListBox_SelectString ($List[$z], $Var & ".") EndFunc   ;==>Highscore Func Save()     FileDelete($Myini)     For $Items = 1 To 10         IniWrite(@TempDir & $Myini, "GameScores", $Items, _GUICtrlListBox_GetText ($List[1], $Items - 1))     Next     For $Items = 1 To 10         IniWrite(@TempDir & $Myini, "GameScores", $Items + 10, _GUICtrlListBox_GetText ($List[2], $Items - 1))     Next EndFunc   ;==>Save Func Load()     If FileExists(@TempDir & $Myini) Then         For $Index = 1 To 10             $Initem = IniRead(@TempDir & $Myini, "GameScores", $Index, "")             _GUICtrlListBox_ReplaceString ($List[1], $Index - 1, $Initem)         Next         For $Index = 11 To 20             $Initem = IniRead(@TempDir & $Myini, "GameScores", $Index, "")             _GUICtrlListBox_ReplaceString ($List[2], $Index - 11, $Initem)         Next     Else         GUICtrlSetData($List[1], "1.|2.|3.|4.|5.|6.|7.|8.|9.|10.")         GUICtrlSetData($List[2], "1.|2.|3.|4.|5.|6.|7.|8.|9.|10.")         Save()     EndIf     Arrange() EndFunc   ;==>Load Func Arrange()     For $z = 1 To 2         For $i = 1 To 10             $Array = StringSplit(_GUICtrlListBox_GetText ($List[$z], $i - 1), ".")             _GUICtrlListBox_ReplaceString ($List[$z], $i - 1, $i & "." & $Array[2])         Next         _GUICtrlListBox_DeleteString ($List[$z], 10)     Next EndFunc   ;==>Arrange Func _Timer($Varr, $Secc)     $TimerDifff = TimerDiff($Varr)     $Timerr += $TimerDifff / 1000     If $Timerr > $Secc Then         $Timerr = 0         $Check = True     EndIf EndFunc   ;==>_Timer

Edited by Jex, 25 October 2007 - 04:06 AM.






#2 Manadar

Manadar

    Taking a REST.

  • MVPs
  • 10,714 posts

Posted 24 October 2007 - 01:29 PM

Awesome game!

Here are a few bugs I found:

Clicking the button that you are not supposed to click can result in a negative score.
The bottom status bar flickers a lot. It might be better if you would only update it when you need.


Suggestions:

10 high scores are a bit much for me. I would rather see 3 high scores or 5.

#3 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 24 October 2007 - 03:23 PM

Very thanks for your comment.

Clicking the button that you are not supposed to click can result in a negative score.

That not bug.

The bottom status bar flickers a lot. It might be better if you would only update it when you need.

I'm added timer for status bar. Now refresh every 100ms and haven't flickers.

Edited by Jex, 24 October 2007 - 03:24 PM.


#4 Achilles

Achilles

    Achilles == Ichigo

  • Active Members
  • PipPipPipPipPipPip
  • 2,897 posts

Posted 25 October 2007 - 03:50 AM

Great game! I like the sounds...

EDIT: The picture you posted looks a lot better then the game does on XP <_< I want Vista...

Edited by Piano_Man, 25 October 2007 - 03:50 AM.


#5 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 25 October 2007 - 03:56 AM

Thanks <_<
That WindowBlinds 6 theme ( http://www.wincustomize.com/skins.aspx?ski...814&libid=1 )

Edited by Jex, 25 October 2007 - 03:58 AM.


#6 gseller

gseller

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 1,057 posts

Posted 25 October 2007 - 06:32 AM

I can't find GuiListBox.au3

#7 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 25 October 2007 - 10:45 AM

gesller you need use Autoit Beta ( http://www.autoitscript.com/autoit3/files/beta/autoit )

#8 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 25 October 2007 - 10:52 AM

Is the first game and second game meant to have different "point" systems?

#9 Jex

Jex

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 25 October 2007 - 10:59 AM

If you mean Point = Score then yes first game point = time, second game point = button click count.

#10 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 25 October 2007 - 09:37 PM

ahhhhhhhh...... awesome! <_<




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users