Here is command line one-liner to play snake. Just Ctrl+c and ctrl+v into an open terminal to play.
WASD to move
ver 2:
-Using a font with an aspect ratio close to 1 is recommended.
-While I did know that time could be used to calculate the length of a game tick, it obliviously didn't occur to me (no break; command), until I took a look at dbenham's snake.bat.
-Using a similar method apple can no longer spawn on snake.
-Added parameters: [XLEN=map X-size; YLEN=map Y-size; TICK=game speed (lower is faster); OWDELAY=Adds delay to script writing input to mitigate write+read at the same time error (lower is faster)]
Note that the error doesn't affect gameplay at all except by writing a bunch of text onto the screen. I could move the cursor to somewhere where it wouldn't be intrusive, but that is not possible since I resize the screen (and it's small).
-Note on above note that secret ver 2.1 possibly fixed this issue, added 2 lines to bottom for text space and moved cursor to right below box at the portion of the code where it reads the file.
-Added an online high score using curl. High-score can be toggled ON/OFF with the parameter [HS=(0=OFF; 1=ON)]
Replace {USERNAME} with your username or it will generate a really ugly user Id for you. Try to beat me! Oh and don't cheat pls.
Note that score is separate from length.
- Note that to save your score you need to press retry once you die, as to re-run the game loop. Yes it's disorganized and it's a huge mess, but to be fair just look at it.
- Note that having highscore feature ON can cause an issue where typing during the curl command causes input to go to console.
- If at any point you start typing on console, just spam enter and movement keys and pray.
ver 1:
-Game tick was capped 1 second.
-Apple could very very rarely (not that it occurred, but theoretically) spawn on snake.
-Typing during specific instances of the timeout command could cause input to go to console.
Code: Select all
@echo off & color f & cmd /q /v:on /c (set "NAME={USERNAME}" ^& set/a XLEN=12, YLEN=10, TICK=20, OWDELAY=3, HS=1 ^>nul ^& (if "!HS!" == "1" (if "!NAME!" == "{USERNAME}" set NAME=USER!random:~1,4!)^& set scorelist=,^&set $c=0^& for /f "tokens=* delims=," %a in ^('curl -s https://notes.orga.cat/et2qn'^) do set/a $c+=1 ^& if not "!$c!"=="1" set scorelist=!scorelist! %a) ^& set/a $xd=XLEN+6+HS*13, $xd2=XLEN-1, $xd3=XLEN+3,$yd=YLEN+10, $yd2=YLEN+2, $yd3=YLEN+6, $yd4=YLEN+2, len=2 ^>nul) ^& (set spaces= ^& for /l %a in ^(1,1,!$xd2!^) do set "spaces=!spaces! ") ^& mode con: cols=!$xd! lines=!$yd! ^& for /f "skip=4" %a in ^('echo prompt $E ^^^| cmd'^) do (echo %a[?25l) ^& ((set /a posX=XLEN/2+3, posY=YLEN/2+3, apps=0, redraw=1 ^> nul) ^& (set body=,) ^& set dir=W^) ^& ^(start "" /b cmd /q /c cls ^^^& for /l %v in ^^^(^^^) do ^^^(for /l %z in ^^^(1,1,!OVDELAY!^^^) do rem: ^^^)^^^& for /f %w in ^^^('choice /c wasd /n'^^^) do echo %w^^^>"%temp%\movinput.flag") ^& ^(timeout /t 1 /NOBREAK ^>nul^) ^& for /l %b in ^(^) do (if "!apps!"=="0" set/a aposX=!random!*!XLEN!/32768+4, aposY=!random!*!YLEN!/32768+3, apps=1 ^>nul ^& (if "!posX!-!posY!" == "!aposX!-!aposY!" set apps=0^& set/a aposX=!random!*!XLEN!/32768+4, aposY=!random!*!YLEN!/32768+3 ^>nul) ^& (for %c in ^(!body!^) do if "%c" == "!aposX!-!aposY!" set apps=0^& set/a aposX=!random!*!XLEN!/32768+4, aposY=!random!*!YLEN!/32768+3, apps=0 ^>nul) ^& if "!apps!" == "1" for /f "tokens=1-2 delims= " %c in ^("!aposX! !aposY!"^) do echo %a[%d;%cH%a[101m %a[40m) ^& if "!apps!" == "1" (for /f "tokens=1-4 delims=:.," %a in ("!time: =0!") do set /a "t2=(((1%a*60)+1%b)*60+1%c)*100+1%d-36610100, tDiff=t2-t1" ^>nul) ^& if !tDiff! geq !TICK! (set /a t1=t2 ^>nul) ^& (if "!redraw!" == "1" set /a score=^^^(200-TICK^^^)*^^^(len-2^^^)/XLEN/YLEN, redraw=0, apps=0, len=2 ^>nul ^& (if "!HS!" == "1" ((set HS=2^&for %h in ^(!scorelist!^) do (if "!HS!"=="2" set scorelist=,^& set $c=0^& set HS=1)^& set /a $c+=1 ^& for /f "tokens=1* delims=[" %j in ^("%h"^) do if "!HS!" == "1" (if !score! GTR %j (set HS=0^& if not "!$c!"=="5" (set scorelist=!scorelist! !score