Sign in to follow this  
Followers 0
JellyFish666

Fun Number Game

7 posts in this topic

#1 ·  Posted (edited)

I wrote this script because I was bored again I took bits from my unfinished Tic Tac Toe game.

This game is called 10 seconds.

The object of this game is to make sure the 10 buttons don't drop down to 0 other then that your safe.

Really simple game, but who would of guessed the code would be this long, I am sure it can be shorten though.

Posted Image

This picture is to make the game transparent.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Global $i = 0, $Turns = 0 , $Frozen = 0 , $Button[99] , $GameSpeed = InputBox("Game Speed" , "Enter the speed of the game the lower the number the faster the game is." , 1000 , "" , 450 , 50)
If $GameSpeed = 0 Then Exit
$GUI = GUICreate("", 90, 115 , Default , Default , $WS_POPUP , $WS_EX_LAYERED)
$Bg = GUICtrlCreatePic(@ScriptDir & "\Temp.bmp", 0, 0 , 90, 115)
GUICtrlSetState($Bg , $GUI_DISABLE)
$Button[1] = GUICtrlCreateButton("10", 0, 0, 25, 25, 0)
$Button[2] = GUICtrlCreateButton("10", 30, 0, 25, 25, 0)
$Button[3] = GUICtrlCreateButton("10", 60, 0, 25, 25, 0)
$Button[4] = GUICtrlCreateButton("10", 0, 30, 25, 25, 0)
$Button[5] = GUICtrlCreateButton("10", 30, 30, 25, 25, 0)
$Button[6] = GUICtrlCreateButton("10", 60, 30, 25, 25, 0)
$Button[7] = GUICtrlCreateButton("10", 0, 60, 25, 25, 0)
$Button[8] = GUICtrlCreateButton("10", 30, 60, 25, 25, 0)
$Button[9] = GUICtrlCreateButton("10", 60, 60, 25, 25, 0)
$Button[10] = GUICtrlCreateButton("10", 30, 90, 25, 25, 0)
GUISetState(@SW_SHOW)
WinSetOnTop($GUI , "" , 1)
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Button[1]
            _ButAdd(GUICtrlRead($Button[1]) , $Button[1])
        Case $Button[2]
            _ButAdd(GUICtrlRead($Button[2]) , $Button[2])
        Case $Button[3]
            _ButAdd(GUICtrlRead($Button[3]) , $Button[3])
        Case $Button[4]
            _ButAdd(GUICtrlRead($Button[4]) , $Button[4])
        Case $Button[5]
            _ButAdd(GUICtrlRead($Button[5]) , $Button[5])
        Case $Button[6]
            _ButAdd(GUICtrlRead($Button[6]) , $Button[6])
        Case $Button[7]
            _ButAdd(GUICtrlRead($Button[7]) , $Button[7])
        Case $Button[8]
            _ButAdd(GUICtrlRead($Button[8]) , $Button[8])
        Case $Button[9]
            _ButAdd(GUICtrlRead($Button[9]) , $Button[9])
        Case $Button[10]
            _ButAdd(GUICtrlRead($Button[10]) , $Button[10])
    EndSwitch
    If $Frozen = 10 Then _EndGame()
    _Freeze()
    $i = $i +1
    If $i = $GameSpeed Then _ButMinus()
WEnd

Func _ButAdd($Num , $Button)
    If $Num = 10 Then
        ;;;
    Else
        $Turns = $Turns +1
        ToolTip($Turns , 0 , 0 , "Your Score is:")
        GUICtrlSetData($Button , $Num +1)
    EndIf
EndFunc

Func _ButMinus()
    $i = 0
    Do
    $Ran = Random(1 , 10 , 1)
    If $Ran = 1 And GUICtrlRead($Button[1]) = 0 Then 
        $Find = False
    ElseIf $Ran = 2 And GUICtrlRead($Button[2]) = 0 Then 
        $Find = False
    ElseIf $Ran = 3 And GUICtrlRead($Button[3]) = 0 Then 
        $Find = False
    ElseIf $Ran = 4 And GUICtrlRead($Button[4]) = 0 Then 
        $Find = False
    ElseIf $Ran = 5 And GUICtrlRead($Button[5]) = 0 Then 
        $Find = False
    ElseIf $Ran = 6 And GUICtrlRead($Button[6]) = 0 Then 
        $Find = False
    ElseIf $Ran = 7 And GUICtrlRead($Button[7]) = 0 Then 
        $Find = False
    ElseIf $Ran = 8 And GUICtrlRead($Button[8]) = 0 Then 
        $Find = False
    ElseIf $Ran = 9 And GUICtrlRead($Button[9]) = 0 Then 
        $Find = False
    ElseIf $Ran = 10 And GUICtrlRead($Button[10]) = 0 Then 
        $Find = False
    Else
        $Find = True
    EndIf
    Until $Find = True
    GUICtrlSetData($Button[$Ran] , GUICtrlRead($Button[$Ran]) -1)
EndFunc

Func _Freeze()
    For $Num = 1 To 10
        If GUICtrlRead($Button[$Num]) = 1 Then _Frozen($Num)
    Next
EndFunc

Func _Frozen($Freeze)
    $Frozen = $Frozen +1
    GUICtrlSetData($Button[$Freeze] , 0)
    GUICtrlSetState($Button[$Freeze] , $GUI_DISABLE)
EndFunc

Func _NewGame()
    $i = 0
    $Turns = 0
    $Frozen = 0
    For $Num = 1 To 10
      GUICtrlSetData($Button[$Num] , 10)
      GUICtrlSetState($Button[$Num] , $GUI_ENABLE)
    Next
EndFunc

Func _EndGame()
    ToolTip("")
    $Msg = MsgBox(4,"Game Over" , "Your Score is " & $Turns & @CRLF & "" & @CRLF & "want to start a new game?")
    Select
    Case $Msg = 6
        _NewGame()
    Case $Msg = 7 
        Exit
    EndSelect
EndFunc
Edited by JellyFish666

Share this post


Link to post
Share on other sites



543 without cheating :)

I can't edit my first post because of autoit tags :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Function NewGame and Freeze can be shortened a TON by arrays. Example:

Func _Freeze()
    For $nNum = 1 to 10
            If GUICtrlRead($Button[$nNum]) = 1 Then _Frozen($nNum)
        Next
EndFunc

Func _NewGame()
    $i = 0
    $Turns = 0
    $Frozen = 0
    For $nNum = 1 to 10
        GUICtrlSetData($Button[$nNum] , 10)
        GUICtrlSetState($Button[$nNum] , $GUI_ENABLE)
    Next
EndFunc

Now see how the rest can be shortened.

EDIT: And why allocate 99 dimensions when you only use 10? Isn't that wasted memory?

Edited by KentonBomb

Share this post


Link to post
Share on other sites

Function NewGame and Freeze can be shortened a TON by arrays. Example:

Func _Freeze()
    For $nNum = 1 to 10
            If GUICtrlRead($Button[$nNum]) = 1 Then _Frozen($nNum)
        Next
EndFunc

Func _NewGame()
    $i = 0
    $Turns = 0
    $Frozen = 0
    For $nNum = 1 to 10
        GUICtrlSetData($Button[$nNum] , 10)
        GUICtrlSetState($Button[$nNum] , $GUI_ENABLE)
    Next
EndFunc

Now see how the rest can be shortened.

EDIT: And why allocate 99 dimensions when you only use 10? Isn't that wasted memory?

I didn't think it would waste to much memory, unless I actually used that many, but I think you are right and also thanks for posting shorter functions.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

How do you play?

when I run the script I get an InputBox asking for the game speed (but the rest of the text goes off the window so I can't read it)

After pressing OK I get a tooltip telling me my score that flashes (refreshing quite quickly)

and that's all.

if this is how it is supposed to run maybe you can post some instructions?

( Screenshots below )

Edited by crashdemons

My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

How do you play?

when I run the script I get an InputBox asking for the game speed (but the rest of the text goes off the window so I can't read it)

After pressing OK I get a tooltip telling me my score that flashes (refreshing quite quickly)

and that's all.

if this is how it is supposed to run maybe you can post some instructions?

( Screenshots below )

when I run the script I get an InputBox asking for the game speed (but the rest of the text goes off the window so I can't read it)

The game speed is to be set for how fast you want the game and it all depends on how fast your computer is I fine 300-500 speed is fine for my computer but 1000 for others, and the inputbox is cut off I didn't notice it because I quickly add that in there the actual script on my pc has it set for the speed of my computer,

After pressing OK I get a tooltip telling me my score that flashes (refreshing quite quickly)

The tooltip on my computer doesn't seem to updates till the score goes up, which is odd since it is in a loop.

and that's all.

I think the problem is it doesn't like the transparent background and may be because you didn't save the image as temp.bmp in the script directory but I should of said that in my first post, if the problem continues try this code...

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
Global $i = 0, $Turns = 0 , $Frozen = 0 , $Button[99] , $GameSpeed = InputBox("Game Speed" , "Enter the speed of the game the lower the number the faster the game is." , 1000 , "" , 450 , 50)
If $GameSpeed = 0 Then Exit
$GUI = GUICreate("", 90, 115 , Default , Default , $WS_POPUP)
;$Bg = GUICtrlCreatePic(@ScriptDir & "\Temp.bmp", 0, 0 , 90, 115)
;GUICtrlSetState($Bg , $GUI_DISABLE)
$Button[1] = GUICtrlCreateButton("10", 0, 0, 25, 25, 0)
$Button[2] = GUICtrlCreateButton("10", 30, 0, 25, 25, 0)
$Button[3] = GUICtrlCreateButton("10", 60, 0, 25, 25, 0)
$Button[4] = GUICtrlCreateButton("10", 0, 30, 25, 25, 0)
$Button[5] = GUICtrlCreateButton("10", 30, 30, 25, 25, 0)
$Button[6] = GUICtrlCreateButton("10", 60, 30, 25, 25, 0)
$Button[7] = GUICtrlCreateButton("10", 0, 60, 25, 25, 0)
$Button[8] = GUICtrlCreateButton("10", 30, 60, 25, 25, 0)
$Button[9] = GUICtrlCreateButton("10", 60, 60, 25, 25, 0)
$Button[10] = GUICtrlCreateButton("10", 30, 90, 25, 25, 0)
GUISetState(@SW_SHOW)
WinSetOnTop($GUI , "" , 1)
While 1
    $Msg = GUIGetMsg()
    Switch $Msg
        Case $Button[1]
            _ButAdd(GUICtrlRead($Button[1]) , $Button[1])
        Case $Button[2]
            _ButAdd(GUICtrlRead($Button[2]) , $Button[2])
        Case $Button[3]
            _ButAdd(GUICtrlRead($Button[3]) , $Button[3])
        Case $Button[4]
            _ButAdd(GUICtrlRead($Button[4]) , $Button[4])
        Case $Button[5]
            _ButAdd(GUICtrlRead($Button[5]) , $Button[5])
        Case $Button[6]
            _ButAdd(GUICtrlRead($Button[6]) , $Button[6])
        Case $Button[7]
            _ButAdd(GUICtrlRead($Button[7]) , $Button[7])
        Case $Button[8]
            _ButAdd(GUICtrlRead($Button[8]) , $Button[8])
        Case $Button[9]
            _ButAdd(GUICtrlRead($Button[9]) , $Button[9])
        Case $Button[10]
            _ButAdd(GUICtrlRead($Button[10]) , $Button[10])
    EndSwitch
    If $Frozen = 10 Then _EndGame()
    _Freeze()
    $i = $i +1
    If $i = $GameSpeed Then _ButMinus()
WEnd

Func _ButAdd($Num , $Button)
    If $Num = 10 Then
        ;;;
    Else
        $Turns = $Turns +1
        ToolTip($Turns , 0 , 0 , "Your Score is:")
        GUICtrlSetData($Button , $Num +1)
    EndIf
EndFunc

Func _ButMinus()
    $i = 0
    Do
    $Ran = Random(1 , 10 , 1)
    If $Ran = 1 And GUICtrlRead($Button[1]) = 0 Then 
        $Find = False
    ElseIf $Ran = 2 And GUICtrlRead($Button[2]) = 0 Then 
        $Find = False
    ElseIf $Ran = 3 And GUICtrlRead($Button[3]) = 0 Then 
        $Find = False
    ElseIf $Ran = 4 And GUICtrlRead($Button[4]) = 0 Then 
        $Find = False
    ElseIf $Ran = 5 And GUICtrlRead($Button[5]) = 0 Then 
        $Find = False
    ElseIf $Ran = 6 And GUICtrlRead($Button[6]) = 0 Then 
        $Find = False
    ElseIf $Ran = 7 And GUICtrlRead($Button[7]) = 0 Then 
        $Find = False
    ElseIf $Ran = 8 And GUICtrlRead($Button[8]) = 0 Then 
        $Find = False
    ElseIf $Ran = 9 And GUICtrlRead($Button[9]) = 0 Then 
        $Find = False
    ElseIf $Ran = 10 And GUICtrlRead($Button[10]) = 0 Then 
        $Find = False
    Else
        $Find = True
    EndIf
    Until $Find = True
    GUICtrlSetData($Button[$Ran] , GUICtrlRead($Button[$Ran]) -1)
EndFunc

Func _Freeze()
    For $Num = 1 To 10
        If GUICtrlRead($Button[$Num]) = 1 Then _Frozen($Num)
    Next
EndFunc

Func _Frozen($Freeze)
    $Frozen = $Frozen +1
    GUICtrlSetData($Button[$Freeze] , 0)
    GUICtrlSetState($Button[$Freeze] , $GUI_DISABLE)
EndFunc

Func _NewGame()
    $i = 0
    $Turns = 0
    $Frozen = 0
    For $Num = 1 To 10
      GUICtrlSetData($Button[$Num] , 10)
      GUICtrlSetState($Button[$Num] , $GUI_ENABLE)
    Next
EndFunc

Func _EndGame()
    ToolTip("")
    $Msg = MsgBox(4,"Game Over" , "Your Score is " & $Turns & @CRLF & "" & @CRLF & "want to start a new game?")
    Select
    Case $Msg = 6
        _NewGame()
    Case $Msg = 7 
        Exit
    EndSelect
EndFunc
Edited by JellyFish666

Share this post


Link to post
Share on other sites

second version works.

btw @ making games processor-speed reliant, wouldn't it be more reliable to just toss in some Sleeps and/or timers?

(I mean, otherwise, a game might play differently on a 500Mhz than a 1.5Ghz)

Might save some CPU too. :/


My Projects - WindowDarken (Darken except the active window) Yahsmosis Chat Client (Discontinued) StarShooter Game (Red alert! All hands to battlestations!) YMSG Protocol Support (Discontinued) Circular Keyboard and OSK example. (aka Iris KB) Target Screensaver Drive Toolbar Thingy Rollup Pro (Minimize-to-Titlebar & More!) 2D Launcher physics example Ascii Screenshot AutoIt3 Quine Example ("Is a Quine" is a Quine.) USB Lock (Another system keydrive - with a toast.)

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0