Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off
- ==================================================
- ::: Snake by T3RRY Version 1.4 11/12/2020
- ::: *** To play Download is REQUIRED from https://drive.google.com/file/d/1_ivtZsSzxEiig3bdCurNFg7SqGES4T53/view?usp=sharing
- ::: * This paste is a newer version than contained in the download file *
- ::: Download contains:
- ::: Getkey.Exe by Antonio {https://stackoverflow.com/users/778560/aacini} for Extended key controls.
- ::: Snake.bat by T3RRY {https://stackoverflow.com/users/12343998/t3rr0r}
- ==================================================
- If "!![" == "[" (Echo/Delayed expansion Must not be enabled prior to starting %~n0.bat & Pause & Exit /B 0)
- CHCP 65001 > nul
- (Set \n=^^^
- %= Macro Newline Do not Modify this code block =%)
- wmic OS get OSArchitecture,caption | FIND "10" > nul || (ECHO/Windows 10 required for ascii escape codes & Exit /B)
- for /F "delims=#" %%a in ('"prompt #$E# & for %%a in (1) do rem"') do set "\E=%%a"
- For /F "Delims=" %%C in ('dir "%~dp0*GetKey.exe" /B /S') Do If not defined GetKey Set "GetKey="%%C" /n"
- Echo/%GetKey%|findstr.exe /LIC:"GetKey.exe" > nul || (Echo/GetKey.Exe not found in Directory. Game cannot be played without GetKey.exe &Pause &Exit /B 0)
- (For /F "Tokens=1,2 Delims==" %%G in ('Set "}" 2^> Nul ')Do Set "%%~G=") 2> nul
- If not exist "%TEMP%" (Set "Save.Dir=%~dp0")Else Set "Save.Dir=%TEMP%\"
- break >"%Save.Dir%%~n0_testpermission.com" || (
- Echo/You do not have write permission in %Save.Dir%
- Pause
- exit /B 0
- )
- Set Background="%Save.Dir%%~n0_background.~tmp"
- Set Foreground="%Save.Dir%%~n0_foreground.~tmp"
- Set Save="%Save.Dir%%~n0_File.~sav"
- mode 80,26
- Set "\C=%\E%[1X"
- Set Background.Border=Set "Border=" ^& For %%n in (1 2)Do If %%n==2 (%\n%
- For /F "Tokens=1,2,3,4,5,6 Delims={}" %%G in ("!Border!")Do If not "%%L" == "" (%\n%
- Set /A ".Xmin=%%H,.Xmax=%%I,.Ymin=%%J,.Ymax=%%K"%\n%
- Set ".Char=%%L"%\n%
- For %%w in (%%H %%I)Do for /L %%h in (%%J,1,%%K)Do (%\n%
- Set "}%%h;%%w=%\E%[%%h;%%wH%\E%[%%~Gm%%~L"%\n%
- For %%i in (%%J %%K)Do If %%h Equ %%i (%\n%
- For /L %%W in (%%H 1 %%I)Do (%\n%
- Set "}%%h;%%W=%\E%[%%h;%%WH%\E%[%%~Gm%%~L"%\n%
- ))))Else ( Echo/Missing Args for %%Background.Border%% ^& Pause ^> nul )%\n%
- )Else Set Border=
- Set "UPDATE.Background=Set /A ".End=!.Ymax! + 1" & ((For /F "Tokens=2* Delims==" %%G in ('Set "}"')Do (< nul Set /P "=%%~G") & < nul Set /P "=%\E%[!.END!;1H%\E%[0m%\E%[?25l")) >%Background% & Type %Background%"
- Set show.snake=For %%n in (1 2)Do if %%n==2 ( %\n%
- (For /F "Tokens=1,2 Delims={}" %%A in ("!Chars!")Do ( %\n%
- For %%h in ("!head:#=%%~A!")Do ( %\n%
- ^<nul Set /P "=%%~h%\E%[!.End!H" %\n%
- ) %\n%
- For %%t in (!tail!)Do ( %\n%
- ^<nul Set /P "=%\E%[%%~tH%\E%[!Tail.Color!m%%B%\E%[!.End!H%\E%[0m" %\n%
- )))^>%Foreground% ^& Type %foreground% %\n%
- )Else Set Chars=
- Set "Left={x}{-}"&Set "Right={x}{+}"&Set "Up={y}{-}"&Set "Down={y}{+}"
- Set Move.Snake=For %%n in (1 2) Do if %%n==2 ( %\n%
- Set "valid=1" %\n%
- For /F "Tokens=1,2,3,4 Delims={}" %%G in ("!Move.Dir!")Do If not "%%~J" == "" ( %\n%
- If /I "%%G" == "x" (Set /A "lx0=!x0!,ly0=!y0!,nx0= !x0! %%H 1")Else (Set /A "nx0=!x0!") %\n%
- If /I "%%G" == "y" (Set /A "lx0=!x0!,ly0=!y0!,ny0= !y0! %%H 1")Else (Set /A "ny0=!y0!") %\n%
- For /F "Delims=" %%p in ("!ny0!;!nx0!")Do If not "!{%%p!" == "" ( %\n%
- Set "valid=0" %\n%
- For /F "Delims=" %%v in ("!{%%p!")Do ( %\n%
- Set "Cell=%%v" %\n%
- Set "?tail=!Cell:%%I=!" %\n%
- If Not "!?Tail!" == "!Cell!" (Goto :Gameover) %\n%
- ) %\n%
- Set "?tail=!Cell:%%J=!" %\n%
- If Not "!?Tail!" == "!Cell!" ( %\n%
- Set "{!fy!;!fx!="^& Set "fy="^& Set "fx=" %\n%
- Set "Valid=1" %\n%
- Set /A "Score+=50" %\n%
- If !Delay! LSS 5 Set /A "Score+=50" %\n%
- Call :makePi %\n%
- Set /A "tail.len+=1" %\n%
- Set "Tail="!y0!;!x0!",!Tail!" %\n%
- Set "{!ny0!;!nx0!=!Snake.Head!" %\n%
- )) %\n%
- If "!valid!" == "1" ( %\n%
- If !n%%G0! LEQ !.%%Gmin! (Goto :Gameover)else If !n%%G0! GEQ !.%%Gmax! (Goto :Gameover)Else ( %\n%
- If "!Tail.len!" == "0" ( %\n%
- Set "{!y0!;!x0!=" %\n%
- ^<nul Set /P "=%\E%[!y0!;!x0!!H%\C%" %\n%
- )Else ( %\n%
- Set "Tail="!y0!;!x0!",!Tail!" %\n%
- Set "Tail.{i}=0" %\n%
- For %%r in (!Tail!)Do ( %\n%
- If !Tail.{i}! EQU !Tail.Len! ( %\n%
- Set "Tail=!Tail:,"%%~r"=,!" ^& Set "{%%~r="^&^<nul Set /P "=%\E%[%%~r!H%\C%" %\n%
- )Else ( %\n%
- Set "{%%~r=!Snake.Tail!" %\n%
- Set /A "Tail.{i}+=1" %\n%
- ))) %\n%
- Set "{!ny0!;!nx0!=!Snake.Head!" %\n%
- Set /A "%%G0=!n%%G0!" %\n%
- ))))Else Set Move.Dir=
- Set "head=%\E%[!y0!;!x0!H%\E%[!head.color!m#%\E%[0m"
- Set "DefArray=For %%n in (1 2)Do if %%n==2 (Set /A "{i}=0"& For %%G in (!list!)Do (Set "$V[!{i}!]=%%G"& Set /A "{i}+=1"))Else Set List="
- Set "Info=For %%i in (!Theme!)Do <nul Set /P "=%\E%[9;55HTheme - 0~9 %\E%[!Border.Color[%%i]!m!Theme!%\E%[0m%\E%[10;55HScore: !Score!%\E%[11;55HHigh Score:!HighScore!%\E%[12;55HPi Eaten:!Tail.Len!%\E%[0m%\E%[13;55HDelay:%\E%[K + !Delay! -%\E%[15;55H%\E%[K%\E%[90mHeading: !Dir:space=Pause! %\E%[16;55H%\E%[90mLast Move: !Key! ""
- Set "k-72=Up"&Set "k-80=Down"&Set "k-75=Left"&Set "k-77=Right"&Set "k32=space"&Set "k43=plus"&Set "k45=minus"&Set "k27=ESC"
- Set /A "k48=0,k49=1,k50=2,k51=3,k52=4,k53=5,k54=6,k55=7,k56=8,k57=9,Theme=0,HighScore=0"
- Set ".Left=Right"&Set ".Right=Left"&Set ".Up=Down"&Set ".Down=Up"
- Set "Dir=Space"
- Set "Pi.char=%\E%(0{%\E%(B" & set "Pi.color=37"
- Set "}2;55=%\E%[2;55H%\E%[33mControls:"
- Set "}3;55=%\E%[3;55H ▲ - Up"
- Set "}4;55=%\E%[4;55H ◄ - Left"
- Set "}5;55=%\E%[5;55H ▼ - Down"
- Set "}6;55=%\E%[6;55H ► - Right"
- Set "}7;55=%\E%[7;55HSpace - Pause"
- Set "}8;55=%\E%[8;55HEscape - Quit"
- CLS
- Echo/Select Playfield Size:
- Echo/ [ X ] [ Y ] Area
- Echo/{0} 1;50 x 1;25 1104
- Echo/{1} 2;48 x 2;24 945
- Echo/{2} 6;47 x 4;23 663
- Echo/{3} 7;45 x 5;22 540
- Echo/{4} 10;40 x 6;21 364
- For /F "Delims=" %%z in ('Choice /N /C:01234')Do Set "[s]=[%%z]"
- Set "Delay=10"
- :start
- If exist %Save:File=Theme% (
- <%Save:File=Theme% (
- Set /P "Theme="
- ))
- If exist %Save:File=Delay% (
- <%Save:File=Delay% (
- Set /P "Delay="
- ))
- Title Snake by T3RRY & CLS
- Setlocal EnableExtensions EnableDelayedExpansion
- %DefArray:$V=Head.Color% 32 33 34 35 36 37 93 94 95 96
- %DefArray:$V=Tail.Color% 96 95 94 93 37 36 35 33 34 32
- %DefArray:$V=Snake.Head% ☺ ☻ ♂ ♀ ☼ § @ D O K
- %DefArray:$V=Snake.Tail% # ░ ▒ ▓ ▬ æ « » [ ]
- %DefArray:$V=Border.Char%♥ ♦ ♣ ♠ • ◘ ○ ◙ ♫ ¶
- %DefArray:$V=Border.Color% 31 93 33 92 "48;2;155;125;60" 35 96 32 36 24
- %DefArray:$V=Border.Size% {1}{50}{1}{25} {2}{48}{2}{24} {6}{47}{4}{23} {7}{45}{5}{22} {10}{40}{6}{21}
- For %%i in (%Theme%)Do For %%o in (head tail)Do If not "!%%o.Color[%%i]!" == "" (Set "%%o.Color=!%%o.Color[%%i]!"&Set "Snake.%%o=!Snake.%%o[%%i]!"&Set "Border.Color=!Border.Color[%%i]!"&Set "Border.Char=!Border.Char[%%i]!")
- %Background.Border%{!Border.Color[%Theme%]!}!Border.Size%[s]%!{!Border.Char[%Theme%]!}
- Set /A "MidX=(.Xmax / 2) + (.Xmin / 2),MidY=(.Ymax / 2) + (.Ymin / 2)"
- Set /A "x0=Midx,y0=MidY,tail.len=0,Score=0"
- %UPDATE.Background%
- Call :makePi
- If exist %Save:File=highscore% (
- <%Save:File=highscore% (
- Set /P "HighScore="
- )
- )
- set /A Highscore+=0
- :gameloop
- If Defined Last.Dir If /I Not "!Dir!" == "Space" (
- Set "Dir=!Last.Dir!" & Set "Last.Dir="
- )
- If %Score% GTR %HighScore% (
- Set /A "Highscore=%Score%"
- >%Save:File=highscore% Echo/%Score%
- )
- %INFO%
- If /I not "!Dir!" == "Space" For %%D in (!%Dir%!)Do %Move.Snake%%%D{%Snake.Tail%}{%Pi.char%}
- %Show.Snake%{!Snake.Head!}{!Snake.Tail!}
- %getKey%
- For %%e in (!Errorlevel!)Do If not "!k%%e!" == "" For %%v in (!Dir!)Do if not "!k%%e!" == "!.%%v!" (
- Set "cc=0"
- For %%i in (!k%%e!)Do For %%o in (head tail)Do If not "!%%o.Color[%%i]!" == "" (
- Set "%%o.Color=!%%o.Color[%%i]!"&Set "Snake.%%o=!Snake.%%o[%%i]!"&Set /A "cc=1,Theme=%%i"
- >"%Save:File=Theme%" (Echo/!Theme!)
- %Background.Border%{!Border.Color[%%i]!}{!.Xmin!}{!.Xmax!}{!.Ymin!}{!.Ymax!}{!Border.Char[%%i]!}
- %UPDATE.Background%
- )
- If Not "!cc!" == "1" (Set "Key=!k%%e!")Else Goto :gameloop
- If not defined Last.dir If /I "!Key!" == "Space" If /I not "!Dir!" == "!Space!" Set "Last.Dir=!Dir!"
- If /I "!Key!" == "plus" (If !Delay! LSS 75 (Set /A "Delay+=1" & >"%Save:File=Delay%" (Echo/!Delay!)) & Goto :gameloop)
- If /I "!Key!" == "minus" (If !Delay! GEQ 1 (Set /A "Delay-=1" & >"%Save:File=Delay%" (Echo/!Delay!)) & Goto :gameloop)
- If /I not "!Key!" == "minus" If /I not "!key!" == "plus" Set "Dir=!k%%e!"
- )
- If "!Key!" == "" (goto :gameloop)
- If /I "!Key!" == "ESC" (goto :End)
- If %Delay% GTR 0 ( For /L %%d in (1 1 !Delay!)Do Call :Delay 2> nul )Else Call :Delay 2> nul
- Goto :gameloop
- :Gameover
- Title Game over
- Set "Tail.Color=90"
- Echo/|Choice.exe /N /C:n 2> nul
- %Background.Border%{48;2;75;75;165}{!.Xmin!}{!.Xmax!}{!.Ymin!}{!.Ymax!}{!Border.Char[%%i]!}{#}
- %UPDATE.Background%
- %Show.Snake%{%\E%[31m!Snake.Head!}{!Snake.Tail!}
- Timeout /T 2 /NoBreak > nul
- Del "%Save.Dir%%~n0*.~tmp"
- Pause > Nul
- CLS
- Endlocal
- Goto :Start
- :End
- <nul Set /P "=%\E%[?25h"
- Del "%Save.Dir%%~n0*.~tmp"
- Endlocal
- Goto :Eof
- :makePi function
- Setlocal enableDelayedExpansion
- :confirmpos
- If not "!fy!" == "" If not "!fx!" == "" ( <nul Set /P "=%\E%[!fy!;!fx!H %\E%[0m" )
- Set "fValid=1"
- Set /A "fXmax=(.Xmax-.Xmin)-1,fYmax=(.Ymax-.Ymin)-1"
- Set /a "nfy=(!random! %% fYmax) + .Ymin ,nfx=(!random! %% fXmax) + .Xmin "
- For /F "delims=" %%g in ("{!nfy!;!nfx!")Do If Not "!%%g!" == "" (Set "fValid=0")
- For /F "delims=" %%h in ("}!nfy!;!nfx!")Do If Not "!%%h!" == "" (Set "fValid=0")
- Set "ftq=!tail:"%nfy%;%nfx%"=!"
- If not %tail.len% EQU 0 (If not "!tail!" == "!ftq!" (Set "fValid=0"))
- If "!fValid!" == "1" (
- <nul Set /P "=%\E%[!nfy!;!nfx!H%\E%[%Pi.color%m!Pi.char!%\E%[0m"
- Endlocal & Set "fy=%nfy%" & Set "fx=%nfx%" & Set "{%nfy%;%nfx%=%Pi.char%"
- Exit /B 0
- ) Else (Set "nfy=" & Set "nfx=")
- Goto :confirmpos
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement