Jump to content

[Game] Minefield Extreme


 Share

Recommended Posts

This is another old script I made but never published (like I did with Starshooter, except this is older)

NOTE: This script is VERY OLD and pretty inefficient!

The game consists of alot of labels, which are blocks on a minefield, you are on one of these blocks.

Your goal: get from the left to the right side of the screen. (sounds pretty simple?)

The script was intended to place you more inside minesweeper; that is, instead of being able to hover over your area, you have to tread carefully through it.

Like Minesweeper, the number of surrounding mines gets printed on a block - but unlike Minesweeper, you can only uncover the area after you've moved directly to it. (only in 4 directions)

Posted Image

For added suspense, Beep() is called when you are next to a mine, it is called more often when you are surrounded by more mines (like your heartbeat might race)

Don't ask me why It counts rads instead of mines, it's just what it reminded me of at the time it was made.

Opt("GUIOnEventMode",1)
Global $farea, $fblocks, $cblocks, $gui, $nfo
Global $aplayer[2]
Global $BeepDelay=2000
Global $Uncovered=''
Global $SM=False


;config variables
Global $StartX=1                            ;staring coords for the Player
Global $StartY=1
Global $CtrlWidth=17                        ;width of the minefield blocks on the gui (in pixels)
Global $CtrlHeight=17
Global $fwidth=20                           ;width of the virtual field (in blocks)
Global $fheight=20
Global $SafeDistance=2                      ;Distance on all sides of the starting position that is safe from mines
Global $Mines=Int(0.20*($fwidth*$fheight))  ; maximum number of mines - Default: no more than 20% of the blocks.
;end config



_interface_create()
_interface_reset()
GUISetState()
_HotKeys_Hook()
While 1
    _nfom_update()
    sleep(500)
WEnd








Func _RadDetector_Calibrate($rads)
    AdlibDisable()
    $rads2=9*250/($rads+1)
    If $rads=0 Then Return 0
    ConsoleWrite("Rad Detector: "&$rads&@CRLF)
    _RadDetector_Beep()
    AdlibEnable("_RadDetector_Beep", $rads2)
EndFunc
Func _RadDetector_Beep()
    Beep(100,200)
EndFunc
Func _RadDetector_Beep2()
    Beep(100,2000)
EndFunc
Func _HotKeys_Hook()
    HotKeySet("{LEFT}","_HotKey_Left")
    HotKeySet("{RIGHT}","_HotKey_Right")
    HotKeySet("{UP}","_HotKey_Up")
    HotKeySet("{DOWN}","_HotKey_Down")
    HotKeySet("^c","_HotKey_ShowMines") ;CHEAT!!!!111on1eone1one!!!
EndFunc
Func _HotKeys_UnHook()
    HotKeySet("{LEFT}")
    HotKeySet("{RIGHT}")
    HotKeySet("{UP}")
    HotKeySet("{DOWN}")
EndFunc
Func _HotKey_Left()
    _HotKeys_UnHook()
    _interface_moveplayer($aplayer[0]-1,$aplayer[1])
    _HotKeys_Hook()
EndFunc
Func _HotKey_Right()
    _HotKeys_UnHook()
    _interface_moveplayer($aplayer[0]+1,$aplayer[1])
    _HotKeys_Hook()
EndFunc
Func _HotKey_Up()
    _HotKeys_UnHook()
    _interface_moveplayer($aplayer[0],$aplayer[1]-1)
    _HotKeys_Hook()
EndFunc
Func _HotKey_Down()
    _HotKeys_UnHook()
    _interface_moveplayer($aplayer[0],$aplayer[1]+1)
    _HotKeys_Hook()
EndFunc
Func _HotKey_ShowMines()
    _HotKeys_UnHook()
    Switch $SM
        Case False
            $SM=True
        Case True
            $SM=False
    EndSwitch
    _ctrls_showplayer()
    _HotKeys_Hook()
EndFunc



Func _interface_create()
    _field_create($fwidth,$fheight)
    _guic_create($CtrlWidth,$CtrlHeight)
    _ctrls_create($CtrlWidth,$CtrlHeight)
EndFunc
Func _interface_reset()
    _field_clear()
    _player_move($StartX,$StartY)
    _field_addmines($Mines)
    _ctrls_showplayer()
    _ctrl_coverup()
    _ctrls_moveplayer_prx($StartX,$StartY)
    Global $Uncovered=''
    Global $MovesT=0
    Global $Timer=TimerInit()
EndFunc
Func _interface_moveplayer($x,$y)
    If $x<1 Then $x=1
    If $y<1 Then $y=1
    If $x>$fwidth Then $x=$fwidth
    If $y>$fheight Then $y=$fheight
    $MovesT+=1
    _ctrls_moveplayer_prx($x,$y)
    _ctrls_showplayer()
    _nfom_update()
    If StringInStr(_player_get(),'m') Then
        AdlibDisable()
        _ctrls_showmines()
        _RadDetector_Beep2()
        MsgBox(0,'Oops!', 'Sorry, your legs just got blown off by a mine'&@CRLF&'- press OK to retry -')
        _interface_reset()
        Return -1
    EndIf
    If $aplayer[0]=$fwidth Then
        _ctrls_showmines()
        MsgBox(0,'Yay!!', 'Great! you made it all the way across without even losing a finger!'&@CRLF&'- press OK to retry -')
        _interface_reset()
        Return 1
    EndIf
    Return 0
EndFunc
Func _nfom_update()
    Local $elapsed=Int(TimerDiff($Timer)/1000)
    GUICtrlSetData($nfo, 'Time: '&$elapsed&' - Moves: '&$MovesT&' - Rads: '&_player_radiate())
EndFunc
Func _guic_create($cW,$cH)
    $gui=GUICreate('Minefield Extreme',$cW*$fwidth,$cH*$fheight+20)
    GUISetOnEvent(-3, '_exit',$gui)
    $nfo=GUICtrlCreateLabel('',0,$cH*$fheight,$cW*$fwidth-100,20)
    GUICtrlSetBkColor(-1,0x0)
    GUICtrlSetColor(-1,0x00FF00)
EndFunc
Func _exit()
    Exit
EndFunc
Func _ctrls_showmines()
    For $x=1 To $fwidth
        For $y=1 To $fheight
            $disp=' '
            If StringInStr(_block_get($x,$y),'m') Then $disp='m'
            $cid=_ctrls_get($x,$y)
            If GUICtrlRead($cid)==$disp Then ContinueLoop
            GUICtrlSetData($cid,$disp)
        Next
    Next
EndFunc
Func _ctrls_showplayer()
    For $x=1 To $fwidth
        For $y=1 To $fheight
            $disp=' '
            $blck=String(_block_get($x,$y))
            If StringLen($blck)>=1 Then $disp=StringMid($blck,1,1)
            If ($disp='m' And $SM=False) or $disp='0' Then $disp=' '
            If $x=$aplayer[0] And $y=$aplayer[1] Then $disp='P'
            $cid=_ctrls_get($x,$y)
            If GUICtrlRead($cid)==$disp Then ContinueLoop
            GUICtrlSetData($cid,$disp)
        Next
    Next
    _RadDetector_Calibrate(_player_radiate())
EndFunc
Func _ctrls_moveplayer_prx($x,$y)
    _ctrl_uncover($aplayer[0],$aplayer[1])
    _player_move($x,$y)
    _ctrl_active($x,$y)
    $Uncovered&=$x&','&$y&';'
EndFunc


Func _ctrl_coverup()
    $unca=StringSplit($Uncovered,';')
    $uncax=UBound($unca)-1
    For $i=1 To $uncax
        If $unca[$i]='' Then ContinueLoop
        $unca2=StringSplit($unca[$i],',')
        _ctrl_cover($unca2[1],$unca2[2])
    Next
EndFunc
Func _ctrl_active($x,$y)
    $ctrl=_ctrls_get($x,$y)
    GUICtrlSetBkColor($ctrl, 0xFF0000)
    GUICtrlSetColor($ctrl,0x000000)
EndFunc
Func _ctrl_cover($x,$y)
    $ctrl=_ctrls_get($x,$y)
    GUICtrlSetBkColor($ctrl,0xFFFFFF)
    GUICtrlSetColor($ctrl,0x000000)
EndFunc
Func _ctrl_uncover($x,$y)
    $ctrl=_ctrls_get($x,$y)
    $rads=_player_radiate()
    _block_set($x,$y,$rads)
    $hex=0x000000
    Switch $rads
        Case 1
            $hex=0x0000FF
        Case 2
            $hex=0x00FF00
        Case 3 To 9
            $hex=0xFF0000
    EndSwitch
    GUICtrlSetBkColor($ctrl,0xCCCCCC)
    GUICtrlSetColor($ctrl,$hex)
EndFunc
Func _ctrls_get($x,$y)
    $ya=$cblocks[$x-1]
    Return $ya[$y-1]
EndFunc
Func _ctrls_create($cW,$cH)
    Global $cblocks[$fwidth]
    For $i=0 To ($fwidth-1)
        Local $yarr[$fheight]
        For $ii=0 To ($fheight-1)
            $yarr[$ii]=GUICtrlCreateLabel(' ',$i*$cW,$ii*$cH,$cW,$cH,0x1000)
            GUICtrlSetBkColor($yarr[$ii],0xFFFFFF)
        Next
        $cblocks[$i]=$yarr
    Next
EndFunc
Func _ctrls_delete()
    For $i=0 To ($fwidth-1)
        $ya=$cblocks[$i]
        For $ii=0 To ($fheight-1)
            GUICtrlDelete($ya[$ii])
        Next
    Next
    $cblocks=''
EndFunc
Func _player_get()
    Return _block_get($aplayer[0],$aplayer[1])
EndFunc
Func _player_radiate()
    $rads=0
    For $x=-1 To 1
        For $y=-1 To 1
            $mine=0
            $xx=$x+$aplayer[0]
            $yy=$y+$aplayer[1]
            If $xx<1 Or $yy<1 Or $xx>$fwidth Or $yy>$fheight Then ContinueLoop
            If StringInStr(_block_get($xx,$yy),'m') Then
                $mine=1
                $rads+=1
                If $x=0 And $y=0 Then Return 9; you're already dead!!!
            EndIf
        Next
    Next
    Return $rads
EndFunc
Func _player_move($x,$y)
    $aplayer[0]=$x
    $aplayer[1]=$y
EndFunc
Func _field_create($w,$h)
    Global $fwidth, $fheight, $farea
    $fwidth=$w
    $fheight=$h
    $farea=$w*$h
    _field_clear()
EndFunc
Func _field_clear()
    Local $yarr[$fheight]
    Global $fblocks[$fwidth]
    For $i=0 To ($fheight-1)
        $yarr[$i]=''
    Next
    For $i=0 To ($fwidth-1)
        $fblocks[$i]=$yarr
    Next
EndFunc
Func _field_addmines($n)
    Local $i, $x, $y, $go, $ii
    For $i=1 To $n
        $x=0
        $y=0
        $go=1
        $ii=1
        While $go=1
            If $ii>=100 Then
                ConsoleWrite('! Took too long to find a safe spot for mine #'&$i)
                ExitLoop 2
            EndIf
            $x=Random(1,$fwidth,1)
            $y=Random(1,$fheight,1)
            $go=0
            If $x<1 Then $go=1
            If $y<1 Then $go=1
            If _math_within($x,$aplayer[0]-$SafeDistance,$aplayer[0]+$SafeDistance)=0 And _math_within($y,$aplayer[1]-$SafeDistance,$aplayer[1]+$SafeDistance)=0 Then
                $go=1
            EndIf
            $ii+=1
        WEnd
        _block_append($x,$y,'m')
    Next
EndFunc
Func _block_append($x,$y,$att)
    $ya=$fblocks[$x-1]
    $ya[$y-1]&=$att
    $fblocks[$x-1]=$ya
EndFunc
Func _block_set($x,$y,$att)
    $ya=$fblocks[$x-1]
    $ya[$y-1]=$att
    $fblocks[$x-1]=$ya
EndFunc
Func _block_get($x,$y)
    $ya=$fblocks[$x-1]
    Return $ya[$y-1]
EndFunc
Func _block_clear($x,$y)
    _block_set($x,$y,'')
EndFunc


Func _math_within($i,$n,$x)
    If $i>$x Then Return ($i-$x)
    If $i<$n Then Return ($i-$n)
    Return 0
EndFunc
Func _ConvertRange($i, $n, $x, $nb, $xb)
    ;converts a number in a range of numbers
    ;proportionally to number in another range
    ;despite whether the numbers are negative or not
    ;based upon $P=100*(($i-$n)/($x-$n));
    $C = ((($i - $n) / ($x - $n)) * ($xb - $nb)) + $nb
    Return $C
EndFunc   ;==>_ConvertRange

Because you obviously cannot turn down the volume on your internal speaker, you might want to leave this to be played at home.

If the field is too big, you can always change it (under config in the script)

I doubt the statistics of winning are in your favor, but you can always edit the number of mines (by default max 20% of the blocks)

Please do not critique me by how lame this script is :) it is NOT a recent creation.

The cheat code is CTRL+C

Edit: code posted.

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.)

Link to comment
Share on other sites

I'm using the Luna Element visual style. (Blue Compact)

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.)

Link to comment
Share on other sites

I got this :

C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(305,153) : ERROR: syntax error
            If _math_within($x,$aplayer[0]-$SafeDistance,$aplayer[0]+$SafeDistance)=0 And _math_within($y,$aplayer[1]-$SafeDistance,$aplayer[1]+$SafeDistance)=0 Then
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(307,4) : ERROR: missing Wend.
            EndIf
            ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(296,20) : REF: missing Wend.
            If $ii>=100 Then
            ~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(307,4) : ERROR: missing Next.
            EndIf
            ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(295,3) : REF: missing Next.
        While
        ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(307,4) : ERROR: syntax error
            EndIf
            ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(113,27) : WARNING: $Timer: declared global in function only. Prefer top of file.
    Global $Timer=TimerInit()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(158,35) : ERROR: _block_get(): undefined function.
            If StringInStr(_block_get($x,$y)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(210,24) : ERROR: _block_set(): undefined function.
    _block_set($x,$y,$rads)
    ~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(305,149) : ERROR: _math_within(): undefined function.
            If _math_within($x,$aplayer[0]-$SafeDistance,$aplayer[0]+$SafeDistance)=0 And _math_within($y,$aplayer[1]-$SafeDistance,$aplayer[1]+$SafeDistance)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3 - 12 error(s), 4 warning(s)
Edited by logmein
Link to comment
Share on other sites

I got this :

C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(305,153) : ERROR: syntax error
            If _math_within($x,$aplayer[0]-$SafeDistance,$aplayer[0]+$SafeDistance)=0 And _math_within($y,$aplayer[1]-$SafeDistance,$aplayer[1]+$SafeDistance)=0 Then
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(307,4) : ERROR: missing Wend.
            EndIf
            ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(296,20) : REF: missing Wend.
            If $ii>=100 Then
            ~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(307,4) : ERROR: missing Next.
            EndIf
            ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(295,3) : REF: missing Next.
        While
        ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(307,4) : ERROR: syntax error
            EndIf
            ^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(113,27) : WARNING: $Timer: declared global in function only. Prefer top of file.
    Global $Timer=TimerInit()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(158,35) : ERROR: _block_get(): undefined function.
            If StringInStr(_block_get($x,$y)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(210,24) : ERROR: _block_set(): undefined function.
    _block_set($x,$y,$rads)
    ~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3(305,149) : ERROR: _math_within(): undefined function.
            If _math_within($x,$aplayer[0]-$SafeDistance,$aplayer[0]+$SafeDistance)=0 And _math_within($y,$aplayer[1]-$SafeDistance,$aplayer[1]+$SafeDistance)
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
C:\Documents and Settings\Welcome\Desktop\Y Utilities\Script\spam.au3 - 12 error(s), 4 warning(s)
Ahh, weird - I see a parenthesis that didn't save, adding it fixed the errors (not the Warnings though, of course), the fixed script is posted.

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.)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...