loading
This is a snake game and it's made in batch script and graphics are text based the only thing you need to make this is notepad

Step 1: Open Notepad

Step 2: Then Copy and Paste This Code on Notepad

@echo off
if "%~1" == "startGame" goto :game
if "%~1" == "startController" goto :controller


::---------------------------------------------------------------------
:: setup some global variables used by both the game and the controller

setlocal disableDelayedExpansion
:getSession
if defined temp (set "tempFileBase=%temp%\") else if defined tmp set "tempFileBase=%tmp%\"
set "tempFileBase=%tempFileBase%Snake%time::=_%"
set "keyFile=%tempFileBase%_key.txt"
set "cmdFile=%tempFileBase%_cmd.txt"
set "gameLock=%tempFileBase%_gameLock.txt"
set "gameLog=%tempFileBase%_gameLog.txt"
set "signal=%tempFileBase%_signal.txt"
set "saveLoc=%userprofile%\Snake"
set "userPref=%saveLoc%\SnakeUserPref.txt"
set "hiFile=%saveLoc%\Snake!growth!Hi"


::------------------------------------------
:: Lock this game session and launch.
:: Loop back and try a new session if failure.
:: Cleanup and exit when finished

call :launch 7>"%gameLock%" || goto :getSession
del "%tempFileBase%*"
exit /b


::------------------------------------------
:launch the game and the controller

call :fixLogs
copy nul "%keyFile%" >nul
copy nul "%cmdFile%" >nul
start "" /b cmd /c ^""%~f0" startController 9^>^>"%keyFile%" 8^<"%cmdFile%" 2^>nul ^>nul^"
cmd /c ^""%~f0" startGame 9^<"%keyFile%" 8^>^>"%cmdFile%" ^echo(


::--------------------------------------------------------------
:: Upon exit, wait for the controller to close before returning

:close
2>nul (>>"%keyFile%" call )||goto :close
if not exist "%~dp0CursorPos.exe" (
echo Game play can be improved by installing
echo Aacini's CursorPos.exe, available at
echo http://goo.gl/hr6Kkn
echo(
echo %cmdcmdline%|find /i "%~f0">nul&&pause
)
exit /b 0


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:game
title %~nx0
cls

::---------------------------------------
:: Playfield size
:: max playing field: (width-2)*(height-2) <= 1365

set "width=40" max=99
set "height=25" max=99

::----------------------------
:: resize the console window

set /a cols=width+1, lines=height+10, area=(width-2)*(height-2)
if %area% gtr 1365 (
echo ERROR: Playfield area too large
%sendCmd% quit
exit
)
if %lines% lss 14 set lines=14
if %cols% lss 46 set cols=46
mode con: cols=%cols% lines=%lines%


::----------------------------
:: define variables

set "configOptions=diffCode difficulty growth moveKeys up down left right"
set "configOptionCnt=9"

set "moveKeys=4"

set "up=W"
set "down=S"
set "left=A"
set "right=D"
set "pause=P"

set "space= "
set "bound=#"
set "food=+"
set "head=@"
set "body=O"
set "death=X"

set "growth=1"

if exist "%userPref%" for /f "usebackq delims=" %%V in ("%userPref%") do set "%%V"

set "spinner1=-"
set "spinner2=\"
set "spinner3=|"
set "spinner4=/"
set "spinner= spinner1 spinner2 spinner3 spinner4 "

set "delay1=20"
set "delay2=15"
set "delay3=10"
set "delay4=7"
set "delay5=5"
set "delay6=3"

set "desc1=Sluggard"
set "desc2=Crawl"
set "desc3=Slow"
set "desc4=Normal"
set "desc5=Fast"
set "desc6=Insane"

set "spinnerDelay=3"

set /a "width-=1, height-=1"

:: define LF as a Line Feed (newline) character
set ^"LF=^

^" Above empty line is required - do not remove

:: define CR as a Carriage Return character
for /f %%A in ('copy /Z "%~dpf0" nul') do set "CR=%%A"

:: define BS as a BackSpace character
for /f %%A in ('"prompt $H&for %%B in (1) do rem"') do set "BS=%%A"

set "upper=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
set "invalid=*~="


::---------------------------
:: define macros

if exist "%~dp0CursorPos.exe" (
set "cls=CursorPos 0 0"
set "ClearLine=echo( &CursorPos 0 -1"
set "ClearPrev=CursorPos 0 -0&echo( "
) else (
set "cls=cls"
set "ClearLine="
set "ClearPrev="
)

:: define a newline with line continuation
set ^"\n=^^^%LF%%LF%^%LF%%LF%^^"

:: setErr
::: Sets the ERRORLEVEL to 1
set "setErr=(call)"

:: clrErr
::: Sets the ERRORLEVEL to 0
set "clrErr=(call )"


:: sendCmd command
::: sends a command to the controller
set "sendCmd=>&8 echo"


:: getKey [ValidKey] [ValidKey...]
::: Check for keypress from the controller. Only accept a ValidKey.
::: Token delimiters and poison characters must be quoted.
::: Accept any key if no ValidKey specified.
::: Return result in Key variable. Key is undefined if no valid keypress.
set getKey=%\n%
for %%# in (1 2) do if %%#==2 (%\n%
set key=%\n%
set inKey=%\n%
set keyTest=%\n%
^<^&9 set /p "inKey="%\n%
if defined inKey (%\n%
set inKey=!inKey:~0,-1!%\n%
for %%C in (!args!) do set /a keyTest=1^&if /i !inKey! equ %%~C set key=!inKey!%\n%
)%\n%
if not defined keyTest set key=!inKey!%\n%
) else set args=


:: draw
::: draws the board
set draw=%\n%
set screen=%\n%
for /l %%Y in (0,1,%height%) do set screen=!screen!!line%%Y!!LF!%\n%
set screen=!screen!Speed = !Difficulty! !replay!!LF!Growth Rate = !growth! HighScore = !hi!!LF!Score = !score! Time = !m!:!s!%\n%
if defined replay if not defined replayFinished (%\n%
set screen=!screen!!LF!!LF!Press a key to abort the replay%\n%
)%\n%
%cls%^&echo(!screen!

:: test X Y ValueListVar
::: tests if value at coordinates X,Y is within contents of ValueListVar
set test=%\n%
for %%# in (1 2) do if %%#==2 (for /f "tokens=1-3" %%1 in ("!args!") do (%\n%
for %%A in ("!line%%2:~%%1,1!") do if "!%%3:%%~A=!" neq "!%%3!" %clrErr% else %setErr%%\n%
)) else set args=


:: plot X Y ValueVar
::: places contents of ValueVar at coordinates X,Y
set plot=%\n%
for %%# in (1 2) do if %%#==2 (for /f "tokens=1-3" %%1 in ("!args!") do (%\n%
set "part2=!line%%2:~%%1!"%\n%
set "line%%2=!line%%2:~0,%%1!!%%3!!part2:~1!"%\n%
)) else set args=


::--------------------------------------
:: start the game
setlocal enableDelayedExpansion
if not exist "%saveLoc%\" md "%saveLoc%"
set "replay= Aborting... "
set "replayAvailable="
call :loadHighScores
call :mainMenu


::--------------------------------------
:: main loop (infinite loop)
for /l %%. in () do (

%=== check for and process abort signal if in replay mode ===%
if defined replay if exist "%signal%" (
del "%signal%"
set "replayFinished=1"
%draw%
echo(
%ClearLine%
call :purge
for %%A in (!configOptions!) do set "%%A=!%%ASave!"
call :mainMenu
)

%=== compute time since last move ===%
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"
if !tDiff! lss 0 set /a tDiff+=24*60*60*100

if !tDiff! geq !delay! (
%=== delay has expired, so time for movement ===%
set /a t1=t2

%=== compute game time ===%
if not defined gameStart set "gameStart=!t2!"
set /a "gameTime=(t2-gameStart)"
if !gameTime! lss 0 set /a "gameTime+=24*60*60*100"
set /a "gameTime=(gameTime-pauseTime)/100, m=gameTime/60, s=gameTime%%60"
if !m! lss 10 set "m=0!m!"
if !s! lss 10 set "s=0!s!"

%=== get keypress ===%
%getKey% !keys!
if /i !key! equ !pause! (

%=== pause game ===%
echo(
call :ask "PAUSED - Press a key to continue..."
%ClearPrev%
%sendCmd% go
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"
if !tDiff! lss 0 set /a tDiff+=24*60*60*100
set /a pauseTime+=tDiff

) else (

%=== establish direction ===%
if not defined replay (echo(!key!.) >>"!gameLog!"
for %%K in (!key!) do if !moveKeys! equ 2 (
set /a "xDiff=xTurn%%K*!yDiff!, yDiff=yTurn%%K*!xDiff!"
) else if "!%%KAxis!" neq "!axis!" (
set /a "xDiff=xDiff%%K, yDiff=yDiff%%K"
set "axis=!%%KAxis!"
)

%=== erase the tail ===%
set "TX=!snakeX:~-2!"
set "TY=!snakeY:~-2!"
set "snakeX=!snakeX:~0,-2!"
set "snakeY=!snakeY:~0,-2!"
%plot% !TX! !TY! space

%=== compute new head location and attempt to move ===%
set /a "X=PX+xDiff, Y=PY+yDiff"
set "X= !X!"
set "Y= !Y!"
set "X=!X:~-2!"
set "Y=!Y:~-2!"
(%test% !X! !Y! playerSpace) && (

%=== move successful ===%

%=== remove the new head location from the empty list ===%
for %%X in ("!X!") do for %%Y in ("!Y!") do set "empty=!empty:#%%~X %%~Y=!"

%=== eat any food that may be present ===%
(%test% !X! !Y! food) && (
%=== initiate growth ===%
set /a grow+=growth

%=== locate and draw new food ===%
if defined replay (
<&9 set /p "F="
) else (
set /a "F=(!random!%%(emptyCnt-1))*6+1"
(echo !F!) >>"!gameLog!"
)
for %%F in (!F!) do (%plot% !empty:~%%F,5! food)
)

if !grow! gtr 0 (
%=== restore the tail ===%
%plot% !TX! !TY! body
set "snakeX=!snakeX!!TX!"
set "snakeY=!snakeY!!TY!"
set /a emptyCnt-=1

%=== manage score ===%
set /a "score+=1, grow-=1"
if not defined replay if !score! gtr !hi! set /a "hi+=1, newHi=1"

) else (
%=== add the former tail position to the empty list ===%
set "empty=!empty!#!TX! !TY!"
)

%=== draw the new head ===%
if defined snakeX (%plot% !PX! !PY! body)
%plot% !X! !Y! head

%=== Add the new head position to the snake strings ===%
set "snakeX=!X!!snakeX!"
set "snakeY=!Y!!snakeY!"
set "PX=!X!"
set "PY=!Y!"

%draw%

) || (

%=== failed move - game over ===%
set "replayFinished=1"
%plot% !TX! !TY! body
call :spinner !PX! !PY! death
%draw%
if defined newHi (
echo(
echo New High Score - Congratulations^^!
set "hi!diffCode!=!score!"
copy "!gameLog!" "%hiFile%!diffCode!.txt" >nul
>>"%hiFile%!diffCode!.txt" echo ::!score!
)
echo(
%ClearLine%
call :ask "Press a key to continue..."
for %%A in (!configOptions!) do set "%%A=!%%ASave!"
call :mainMenu
)
)
)
)


::-------------------------------------
:getString Prompt Var MaxLen
:: Prompt for a string with max lengh of MaxLen.
:: Valid keys are alpha-numeric, space, underscore, and dash
:: String is terminated by Enter
:: Backspace works to delete previous character
:: Result is returned in Var
set /a "maxLen=%3"
set "%2="
%sendCmd% prompt
call :purge
:getStringLoop
(%getKey% !upper! 0 1 2 3 4 5 6 7 8 9 " " _ - {Enter} !BS!)
if defined key (
if !key! equ {Enter} (
echo(
exit /b
)
if !key! neq !BS! if !maxLen! gtr 0 (
set /a maxLen-=1
set "%2=!%2!!key!
)
if !key! equ !BS! if defined %2 (
set /a maxLen+=1
set "%2=!%2:~0,-1!"
)
)
if defined inKey %sendCmd% one
goto :getStringLoop


::-------------------------------------
:ask Prompt ValidKey [Validkey]...
:: Prompt for a keypress.
:: Wait until a ValidKey is pressed and return result in Key variable.
:: Token delimiters, ), and poison characters must be quoted.
%sendCmd% prompt
(set validKeys=%*)
(set validKeys=!validKeys:%1=!)
call :purge
:getResponse
(%getKey% !validKeys!)
if not defined key (
if defined inKey %sendCmd% one
goto :getResponse
)
exit /b


:purge
set "inKey="
for /l %%N in (1 1 1000) do (
set /p "inKey="
if "!inKey!" equ "{purged}." exit /b
)<&9
goto :purge


::-------------------------------------
:spinner X Y ValueVar
set /a d1=-1000000
for /l %%N in (1 1 5) do for %%C in (%spinner%) do (
call :spinnerDelay
%plot% %1 %2 %%C
%draw%
)
call :spinnerDelay
(%plot% %1 %2 %3)
exit /b


::-------------------------------------
:delay centiSeconds
setlocal
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "spinnerDelay=%1, d1=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100"
:: fall through to :spinnerDelay

::-------------------------------------
:spinnerDelay
for /f "tokens=1-4 delims=:.," %%a in ("!time: =0!") do set /a "d2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, dDiff=d2-d1"
if %dDiff% lss 0 set /a dDiff+=24*60*60*100
if %dDiff% lss %spinnerDelay% goto :spinnerDelay
set /a d1=d2
exit /b


::-------------------------------------
:mainMenu
cls
set "loadAvailable="
echo Growth rate = !growth!
echo(
echo Main Menu:
echo(
echo N - New game
if defined replayAvailable echo R - Replay previous game
if defined saveAvailable echo S - Save a game
if exist *.snake.txt echo L - Load and watch a saved game&set "loadAvailable=L"

echo C - Control options
echo G - Graphic options
echo Q - Quit
echo(
set "hiAvailable="
for /l %%N in (1 1 6) do if defined hi%%N (
if not defined hiAvailable (
echo Replay High Score:
echo(
)
set "desc=!desc%%N!........"
set "hiAvailable=!hiAvailable! %%N"
echo %%N - !desc:~0,8! !hi%%N!
)
if defined hiAvailable echo(
set "keys=N C G Q !hiAvailable! !replayAvailable! !saveAvailable! !loadAvailable!"
call :ask ">" !keys!
if /i !key! equ Q (
%sendCmd% quit
cls
exit
)
if /i !key! equ N (
set "replay="
set "replayAvailable=R"
set "saveAvailable=S"
goto :initialize
)
if /i !key! equ S (
if defined replayAvailable (
call :ask "HighScore # or P for Previous:" !hiAvailable! P
) else (
call :ask "HighScore #:" !hiAvailable!
)
echo !key!
if /i !key! equ P (set "src=!gameLog!") else set "src=%hiFile%!key!.txt"
call :getString "Save file name:" file 20
copy "!src!" "!file!.snake.txt"
call :ask "Press a key to continue..."
)
if /i !key! equ L (
call :getString "Load file name:" file 20
if exist "!file!.snake.txt" (
set "replay=!file!.snake.txt"
goto :initialize
)
echo Error: File "!file!.snake.txt" not found
call :ask "Press a key to continue..."
)
if /i !key! equ R (
set "replay=!gameLog!"
goto :initialize
)
if !key! geq 1 if !key! leq 6 (
set "replay=%hiFile%!key!.txt"
goto :initialize
)
if /i !key! equ C call :controlOptions
if /i !key! equ G call :graphicOptions
goto :mainMenu


::-------------------------------------
:controlOptions
cls
set "keys={Enter} T L R P"
if !moveKeys! equ 4 set "keys=!keys! U D"
echo Control Options:
echo(
echo T - Type... = !moveKeys! keys
echo(
echo L - Left... = !left!
echo R - Right.. = !right!
if !moveKeys! equ 4 echo U - Up..... = !up!
if !moveKeys! equ 4 echo D - Down... = !down!
echo(
echo P - Pause.. = !pause!
echo(
echo {Enter} - Return to Main Menu
echo(
call :ask ">" !keys!
if !key! equ {Enter} goto :saveUserPrefs
if /i !key! equ T (
if !moveKeys! equ 2 (set "moveKeys=4") else set "moveKeys=2"
goto :controlOptions
)
set "option= LLeft RRight UUp DDown PPause"
for /f %%O in ("!option:* %key%=!") do (
call :ask "Press a key for %%O:"
for %%K in (0 1 2) do if "!key!" equ "!invalid:~%%K,1!" goto :controlOptions
for %%C in (!upper!) do set "key=!key:%%C=%%C!"
set "%%O=!key!"
)
goto :controlOptions


::-------------------------------------
:graphicOptions
cls
echo Graphic Options:
echo(
echo B - Border...... = !bound!
echo E - Empty space. = !space!
echo H - snake Head.. = !head!
echo S - Snake body.. = !body!
echo F - Food........ = !food!
echo D - Death....... = !death!
echo(
echo G - Growth rate. = !growth!
echo(
echo {Enter} - Rturn to Main Menu
echo(
call :ask ">" B E H S F D G {Enter}
if !key! equ {Enter} goto :saveUserPrefs
if /i !key! equ G (
call :ask "Press a digit for growth rate (0 = 10)" 0 1 2 3 4 5 6 7 8 9
if !key! equ 0 set "key=10"
set "growth=!key!"
call :loadHighScores
) else (
set "option=-BBorder:bound:-EEmpty Space:space:-HSnake Head:head:-SSnake Body:body:-FFood:food:-DDeath:death:"
for /f "tokens=1,2 delims=:" %%A in ("!option:*-%key%=!") do (
call :ask "Press a key for %%A"
for %%K in (0 1 2) do if "!key!" equ "!invalid:~%%K,1!" goto :graphicOptions
set "%%B=!key!"
)
)
goto :graphicOptions


::------------------------------------
:saveUserPrefs
(for %%V in (moveKeys up down left right space bound food head body death pause growth) do echo %%V=!%%V!) >"%userPref%"
exit /b


::-------------------------------------
:initialize
cls
if defined replay (
echo Replay Speed Options:
) else (
echo Speed Options:
)
echo delay
echo # Description (seconds)
echo --- ----------- ---------
for /l %%N in (1 1 6) do (
set "delay=0!delay%%N!"
set "desc=!desc%%N! "
echo %%N !desc:~0,11! 0.!delay:~-2!
)
echo(
call :ask "Pick a speed (1-6):" 1 2 3 4 5 6
set "difficulty=!desc%key%!"
set "delay=!delay%key%!"
set "diffCode=%key%"
echo %key% - %difficulty%
echo(
set "axis=X"
set "xDiff=+1"
set "yDiff=+0"
set "empty="
set /a "PX=1, PY=height/2, FX=width/2+1, FY=PY, score=0, emptyCnt=0, t1=-1000000"
set "gameStart="
set "m=00"
set "s=00"
set "snakeX= %PX%"
set "snakeY= %PY%"
set "snakeX=%snakeX:~-2%"
set "snakeY=%snakeY:~-2%"
for /l %%Y in (0 1 %height%) do (
set "line%%Y="
for /l %%X in (0,1,%width%) do (
set "cell="
if %%Y equ 0 set "cell=%bound%"
if %%Y equ %height% set "cell=%bound%"
if %%X equ 0 set "cell=%bound%"
if %%X equ %width% set "cell=%bound%"
if %%X equ %PX% if %%Y equ %PY% set "cell=%head%"
if not defined cell (
set "cell=%space%"
set "eX= %%X"
set "eY= %%Y"
set "empty=!empty!#!eX:~-2! !eY:~-2!"
set /a emptyCnt+=1
)
if %%X equ %FX% if %%Y equ %FY% set "cell=%food%"
set "line%%Y=!line%%Y!!cell!"
)
)
for %%A in (!configOptions!) do set "%%ASave=!%%A!"
set "replayFinished="
if defined replay (
%sendCmd% replay
%sendCmd% !replay!
call :waitForSignal
set "replay=(REPLAY at !difficulty!)"
set "read=1"
<&9 (
for /l %%N in (1 1 !configOptionCnt!) do if defined read (
set /p "ln="
if "!ln!" equ "END" (set read=) else set "!ln!"
)
)
set "keys="
set "hi=0"
for /f "delims=:" %%A in ('findstr "^::" "%hiFile%!diffCode!.txt" 2^>nul') do set "hi=%%A"
(%draw%)
call :delay 100
) else (
if defined hi%diffCode% (set "hi=!hi%diffCode%!") else set "hi=0"
(%draw%)
>"!gameLog!" (
for %%A in (!configOptions!) do (echo %%A=!%%A!)
(echo END)
)
echo(
if !moveKeys! equ 4 (
echo Controls: !up!=up !down!=down !left!=left !right!=right !pause!=pause
) else (
echo Controls: !left!=left !right!=right !pause!=pause
)
echo Avoid running into yourself (!body!!body!!head!^) or wall (!bound!^)
echo Eat food (!food!^) to grow.
echo(
call :ask "Press a key to start..."
%sendCmd% go
)
set "pauseTime=0"
set "xDiff!up!=+0"
set "xDiff!down!=+0"
set "xDiff!left!=-1"
set "xDiff!right!=+1"
set "yDiff!up!=-1"
set "yDiff!down!=+1"
set "yDiff!left!=+0"
set "yDiff!right!=+0"
set "!up!Axis=Y"
set "!down!Axis=Y"
set "!left!Axis=X"
set "!right!Axis=X"
set "xTurn!left!=1"
set "xTurn!right!=-1"
set "yTurn!left!=-1"
set "yTurn!right!=1"
set "playerSpace=!space!!food!"
set ^"keys="!left!" "!right!" "!pause!"^"
set "newHi="
set "grow=0"
if !moveKeys! equ 4 set ^"keys=!keys! "!up!" "!down!"^"
cls
exit /b


::-------------------------------------
:waitForSignal
if not exist "%signal%" goto :waitForSignal
del "%signal%"
exit /b


::-------------------------------------
:loadHighScores
set "saveAvailable="
for /l %%N in (1 1 6) do (
set "hi%%N="
for /f "delims=:" %%A in ('findstr "^::" "%hiFile%%%N.txt" 2^>nul') do (
set "hi%%N=%%A"
set "saveAvailable=S"
)
)
exit /b


::-------------------------------------
:fixLogs
setlocal enableDelayedExpansion
for %%F in (*.snake) do (
ren "%%F" "%%F.txt"
call :fixLog "%%F.txt"
)
pushd "%SaveLoc%"
for /f "delims=" %%F in ('dir /b SnakeHi*.txt 2^>nul') do (
set "file=%%~nF"
set "file=Snake1Hi!file:~-1!.txt"
ren "%%F" "!file!"
call :fixLog "!file!"
)
popd
exit /b

:fixLog filePath
>"%~1.new" (
<"%~1" (
for %%A in (diffCode difficulty moveKeys up down left right) do (
set /p "val="
(echo %%A=!val!)
)
)
(echo growth=1)
(echo END)
more +7 "%~1"
)
move /y "%~1.new" "%~1" >nul
exit /b


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:controller
:: Detects keypresses and sends the information to the game via a key file.
:: The controller has various modes of input that are activated by commands sent
:: from the game via a cmd file.
::
:: Modes:
::
:: hold - No input, wait for command
::
:: go - Continuously get/send key presses
::
:: prompt - Send {purged} marker to allow game to purge input buffer, then
:: get/send a single key press and hold
::
:: one - Get/send a single key press and hold
::
:: replay - Copy a game log to the key file. The next line in cmd file
:: specifies name of log file to copy. During replay, the controller
:: will send an abort signal to the game if a key is pressed.
::
:: quit - Immediately exit the controller process
::
:: As written, this routine incorrectly reports ! as ), but that doesn't matter
:: since we don't need that key. Both and Enter key are reported as {Enter}.
:: An extra character is appended to the output to preserve any control chars
:: when read by SET /P.

setlocal enableDelayedExpansion
for /f %%a in ('copy /Z "%~dpf0" nul') do set "CR=%%a"
set "cmd=hold"
set "inCmd="
set "key="
for /l %%. in () do (
if "!cmd!" neq "hold" (
for /f "delims=" %%A in ('xcopy /w "%~f0" "%~f0" 2^>nul') do (
if not defined key set "key=%%A"
)
set "key=!key:~-1!"
if !key! equ !CR! set "key={Enter}"
)
<&8 set /p "inCmd="
if defined inCmd (
if !inCmd! equ quit exit
set "cmd=!inCmd!"
if !inCmd! equ replay (
<&8 set /p "file="
type "!file!" >&9
copy nul "%signal%"
)
set "inCmd="
)
if defined key (
if "!cmd!" equ "prompt" (echo {purged}.)
if "!cmd!" equ "replay" (
copy nul "%signal%" >nul
(echo {purged}.)
set "cmd=go"
) else (echo(!key!.)
if "!cmd!" neq "go" set "cmd=hold"
set "key="
)>&9
)

Step 3: How to Save

Then goto file on the top left and select save as please listen properly to this part then click on desktop then you can save it as any name but it MUST have .bat at the end for example if I want to save it as snake game il have to do it like this snake game.bat it must have .bat at the end

Step 4: Enjoy

This game also has settings for controls ingame and if you want to do a new game you press n and etc it will show you what things to press
<p>and also gyes if even this code in the description doesent work for you or the code in the instructable goto this website of mine il paste a link here that should work if not it may be compatibility issue</p><p>http://copy-batch-codes-for-free.webs.com/snake-game</p>
<p>it is frozen</p>
<p>your web site is Froszen</p>
<p>hey gyes i made this is the code above doesent work try this</p><p>@echo off<br>if &quot;%~1&quot; == &quot;startGame&quot; goto :game<br>if &quot;%~1&quot; == &quot;startController&quot; goto :controller<br><br><br>::---------------------------------------------------------------------<br>:: setup some global variables used by both the game and the controller<br><br>setlocal disableDelayedExpansion<br>:getSession<br>if defined temp (set &quot;tempFileBase=%temp%\&quot;) else if defined tmp set &quot;tempFileBase=%tmp%\&quot;<br>set &quot;tempFileBase=%tempFileBase%Snake%time::=_%&quot;<br>set &quot;keyFile=%tempFileBase%_key.txt&quot;<br>set &quot;cmdFile=%tempFileBase%_cmd.txt&quot;<br>set &quot;gameLock=%tempFileBase%_gameLock.txt&quot;<br>set &quot;gameLog=%tempFileBase%_gameLog.txt&quot;<br>set &quot;signal=%tempFileBase%_signal.txt&quot;<br>set &quot;saveLoc=%userprofile%\Snake&quot;<br>set &quot;userPref=%saveLoc%\SnakeUserPref.txt&quot;<br>set &quot;hiFile=%saveLoc%\Snake!growth!Hi&quot;<br><br><br>::------------------------------------------<br>:: Lock this game session and launch.<br>:: Loop back and try a new session if failure.<br>:: Cleanup and exit when finished<br><br>call :launch 7&gt;&quot;%gameLock%&quot; || goto :getSession<br>del &quot;%tempFileBase%*&quot;<br>exit /b<br><br><br>::------------------------------------------<br>:launch the game and the controller<br><br>call :fixLogs<br>copy nul &quot;%keyFile%&quot; &gt;nul<br>copy nul &quot;%cmdFile%&quot; &gt;nul<br>start &quot;&quot; /b cmd /c ^&quot;&quot;%~f0&quot; startController 9^&gt;^&gt;&quot;%keyFile%&quot; 8^&lt;&quot;%cmdFile%&quot; 2^&gt;nul ^&gt;nul^&quot;<br>cmd /c ^&quot;&quot;%~f0&quot; startGame 9^&lt;&quot;%keyFile%&quot; 8^&gt;^&gt;&quot;%cmdFile%&quot; ^&lt;nul^&quot;<br>echo(<br><br><br>::--------------------------------------------------------------<br>:: Upon exit, wait for the controller to close before returning<br><br>:close<br>2&gt;nul (&gt;&gt;&quot;%keyFile%&quot; call )||goto :close<br>if not exist &quot;%~dp0CursorPos.exe&quot; (<br> echo Game play can be improved by installing<br> echo Aacini's CursorPos.exe, available at<br> echo http://goo.gl/hr6Kkn<br> echo(<br> echo %cmdcmdline%|find /i &quot;%~f0&quot;&gt;nul&amp;&amp;pause<br>)<br>exit /b 0<br><br><br>::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br>:game<br>title %~nx0<br>cls<br><br>::---------------------------------------<br>:: Playfield size<br>:: max playing field: (width-2)*(height-2) &lt;= 1365<br><br>set &quot;width=40&quot; max=99<br>set &quot;height=25&quot; max=99<br><br>::----------------------------<br>:: resize the console window<br><br>set /a cols=width+1, lines=height+10, area=(width-2)*(height-2)<br>if %area% gtr 1365 (<br> echo ERROR: Playfield area too large<br> %sendCmd% quit<br> exit<br>)<br>if %lines% lss 14 set lines=14<br>if %cols% lss 46 set cols=46<br>mode con: cols=%cols% lines=%lines%<br><br><br>::----------------------------<br>:: define variables<br><br>set &quot;configOptions=diffCode difficulty growth moveKeys up down left right&quot;<br>set &quot;configOptionCnt=9&quot;<br><br>set &quot;moveKeys=4&quot;<br><br>set &quot;up=W&quot;<br>set &quot;down=S&quot;<br>set &quot;left=A&quot;<br>set &quot;right=D&quot;<br>set &quot;pause=P&quot;<br><br>set &quot;space= &quot;<br>set &quot;bound=#&quot;<br>set &quot;food=+&quot;<br>set &quot;head=@&quot;<br>set &quot;body=O&quot;<br>set &quot;death=X&quot;<br><br>set &quot;growth=1&quot;<br><br>if exist &quot;%userPref%&quot; for /f &quot;usebackq delims=&quot; %%V in (&quot;%userPref%&quot;) do set &quot;%%V&quot;<br><br>set &quot;spinner1=-&quot;<br>set &quot;spinner2=\&quot;<br>set &quot;spinner3=|&quot;<br>set &quot;spinner4=/&quot;<br>set &quot;spinner= spinner1 spinner2 spinner3 spinner4 &quot;<br><br>set &quot;delay1=20&quot;<br>set &quot;delay2=15&quot;<br>set &quot;delay3=10&quot;<br>set &quot;delay4=7&quot;<br>set &quot;delay5=5&quot;<br>set &quot;delay6=3&quot;<br><br>set &quot;desc1=Sluggard&quot;<br>set &quot;desc2=Crawl&quot;<br>set &quot;desc3=Slow&quot;<br>set &quot;desc4=Normal&quot;<br>set &quot;desc5=Fast&quot;<br>set &quot;desc6=Insane&quot;<br><br>set &quot;spinnerDelay=3&quot;<br><br>set /a &quot;width-=1, height-=1&quot;<br><br>:: define LF as a Line Feed (newline) character<br>set ^&quot;LF=^<br><br>^&quot; Above empty line is required - do not remove<br><br>:: define CR as a Carriage Return character<br>for /f %%A in ('copy /Z &quot;%~dpf0&quot; nul') do set &quot;CR=%%A&quot;<br><br>:: define BS as a BackSpace character<br>for /f %%A in ('&quot;prompt $H&amp;for %%B in (1) do rem&quot;') do set &quot;BS=%%A&quot;<br><br>set &quot;upper=A B C D E F G H I J K L M N O P Q R S T U V W X Y Z&quot;<br>set &quot;invalid=*~=&quot;<br><br><br>::---------------------------<br>:: define macros<br><br>if exist &quot;%~dp0CursorPos.exe&quot; (<br> set &quot;cls=CursorPos 0 0&quot;<br> set &quot;ClearLine=echo( &amp;CursorPos 0 -1&quot;<br> set &quot;ClearPrev=CursorPos 0 -0&amp;echo( &quot;<br>) else (<br> set &quot;cls=cls&quot;<br> set &quot;ClearLine=&quot;<br> set &quot;ClearPrev=&quot;<br>)<br><br>:: define a newline with line continuation<br>set ^&quot;\n=^^^%LF%%LF%^%LF%%LF%^^&quot;<br><br>:: setErr<br>::: Sets the ERRORLEVEL to 1<br>set &quot;setErr=(call)&quot;<br><br>:: clrErr<br>::: Sets the ERRORLEVEL to 0<br>set &quot;clrErr=(call )&quot;<br><br><br>:: sendCmd command<br>::: sends a command to the controller<br>set &quot;sendCmd=&gt;&amp;8 echo&quot;<br><br><br>:: getKey [ValidKey] [ValidKey...]<br>::: Check for keypress from the controller. Only accept a ValidKey.<br>::: Token delimiters and poison characters must be quoted.<br>::: Accept any key if no ValidKey specified.<br>::: Return result in Key variable. Key is undefined if no valid keypress.<br>set getKey=%\n%<br>for %%# in (1 2) do if %%#==2 (%\n%<br> set key=%\n%<br> set inKey=%\n%<br> set keyTest=%\n%<br> ^&lt;^&amp;9 set /p &quot;inKey=&quot;%\n%<br> if defined inKey (%\n%<br> set inKey=!inKey:~0,-1!%\n%<br> for %%C in (!args!) do set /a keyTest=1^&amp;if /i !inKey! equ %%~C set key=!inKey!%\n%<br> )%\n%<br> if not defined keyTest set key=!inKey!%\n%<br>) else set args=<br><br><br>:: draw<br>::: draws the board<br>set draw=%\n%<br>set screen=%\n%<br>for /l %%Y in (0,1,%height%) do set screen=!screen!!line%%Y!!LF!%\n%<br>set screen=!screen!Speed = !Difficulty! !replay!!LF!Growth Rate = !growth! HighScore = !hi!!LF!Score = !score! Time = !m!:!s!%\n%<br>if defined replay if not defined replayFinished (%\n%<br> set screen=!screen!!LF!!LF!Press a key to abort the replay%\n%<br>)%\n%<br>%cls%^&amp;echo(!screen!<br><br>:: test X Y ValueListVar<br>::: tests if value at coordinates X,Y is within contents of ValueListVar<br>set test=%\n%<br>for %%# in (1 2) do if %%#==2 (for /f &quot;tokens=1-3&quot; %%1 in (&quot;!args!&quot;) do (%\n%<br> for %%A in (&quot;!line%%2:~%%1,1!&quot;) do if &quot;!%%3:%%~A=!&quot; neq &quot;!%%3!&quot; %clrErr% else %setErr%%\n%<br>)) else set args=<br><br><br>:: plot X Y ValueVar<br>::: places contents of ValueVar at coordinates X,Y<br>set plot=%\n%<br>for %%# in (1 2) do if %%#==2 (for /f &quot;tokens=1-3&quot; %%1 in (&quot;!args!&quot;) do (%\n%<br> set &quot;part2=!line%%2:~%%1!&quot;%\n%<br> set &quot;line%%2=!line%%2:~0,%%1!!%%3!!part2:~1!&quot;%\n%<br>)) else set args=<br><br><br>::--------------------------------------<br>:: start the game<br>setlocal enableDelayedExpansion<br>if not exist &quot;%saveLoc%\&quot; md &quot;%saveLoc%&quot;<br>set &quot;replay= Aborting... &quot;<br>set &quot;replayAvailable=&quot;<br>call :loadHighScores<br>call :mainMenu<br><br><br>::--------------------------------------<br>:: main loop (infinite loop)<br>for /l %%. in () do (<br><br> %=== check for and process abort signal if in replay mode ===%<br> if defined replay if exist &quot;%signal%&quot; (<br> del &quot;%signal%&quot;<br> set &quot;replayFinished=1&quot;<br> %draw%<br> echo(<br> %ClearLine%<br> &lt;nul set /p &quot;=Aborting... &quot;<br> call :purge<br> for %%A in (!configOptions!) do set &quot;%%A=!%%ASave!&quot;<br> call :mainMenu<br> )<br><br> %=== compute time since last move ===%<br> for /f &quot;tokens=1-4 delims=:.,&quot; %%a in (&quot;!time: =0!&quot;) do set /a &quot;t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1&quot;<br> if !tDiff! lss 0 set /a tDiff+=24*60*60*100<br><br> if !tDiff! geq !delay! (<br> %=== delay has expired, so time for movement ===%<br> set /a t1=t2<br><br> %=== compute game time ===%<br> if not defined gameStart set &quot;gameStart=!t2!&quot;<br> set /a &quot;gameTime=(t2-gameStart)&quot;<br> if !gameTime! lss 0 set /a &quot;gameTime+=24*60*60*100&quot;<br> set /a &quot;gameTime=(gameTime-pauseTime)/100, m=gameTime/60, s=gameTime%%60&quot;<br> if !m! lss 10 set &quot;m=0!m!&quot;<br> if !s! lss 10 set &quot;s=0!s!&quot;<br><br> %=== get keypress ===%<br> %getKey% !keys!<br> if /i !key! equ !pause! (<br><br> %=== pause game ===%<br> echo(<br> call :ask &quot;PAUSED - Press a key to continue...&quot;<br> %ClearPrev%<br> %sendCmd% go<br> for /f &quot;tokens=1-4 delims=:.,&quot; %%a in (&quot;!time: =0!&quot;) do set /a &quot;t2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, tDiff=t2-t1&quot;<br> if !tDiff! lss 0 set /a tDiff+=24*60*60*100<br> set /a pauseTime+=tDiff<br><br> ) else (<br><br> %=== establish direction ===%<br> if not defined replay (echo(!key!.) &gt;&gt;&quot;!gameLog!&quot;<br> for %%K in (!key!) do if !moveKeys! equ 2 (<br> set /a &quot;xDiff=xTurn%%K*!yDiff!, yDiff=yTurn%%K*!xDiff!&quot;<br> ) else if &quot;!%%KAxis!&quot; neq &quot;!axis!&quot; (<br> set /a &quot;xDiff=xDiff%%K, yDiff=yDiff%%K&quot;<br> set &quot;axis=!%%KAxis!&quot;<br> )<br><br> %=== erase the tail ===%<br> set &quot;TX=!snakeX:~-2!&quot;<br> set &quot;TY=!snakeY:~-2!&quot;<br> set &quot;snakeX=!snakeX:~0,-2!&quot;<br> set &quot;snakeY=!snakeY:~0,-2!&quot;<br> %plot% !TX! !TY! space<br><br> %=== compute new head location and attempt to move ===%<br> set /a &quot;X=PX+xDiff, Y=PY+yDiff&quot;<br> set &quot;X= !X!&quot;<br> set &quot;Y= !Y!&quot;<br> set &quot;X=!X:~-2!&quot;<br> set &quot;Y=!Y:~-2!&quot;<br> (%test% !X! !Y! playerSpace) &amp;&amp; (<br><br> %=== move successful ===%<br><br> %=== remove the new head location from the empty list ===%<br> for %%X in (&quot;!X!&quot;) do for %%Y in (&quot;!Y!&quot;) do set &quot;empty=!empty:#%%~X %%~Y=!&quot;<br><br> %=== eat any food that may be present ===%<br> (%test% !X! !Y! food) &amp;&amp; (<br> %=== initiate growth ===%<br> set /a grow+=growth<br><br> %=== locate and draw new food ===%<br> if defined replay (<br> &lt;&amp;9 set /p &quot;F=&quot;<br> ) else (<br> set /a &quot;F=(!random!%%(emptyCnt-1))*6+1&quot;<br> (echo !F!) &gt;&gt;&quot;!gameLog!&quot;<br> )<br> for %%F in (!F!) do (%plot% !empty:~%%F,5! food)<br> )<br><br> if !grow! gtr 0 (<br> %=== restore the tail ===%<br> %plot% !TX! !TY! body<br> set &quot;snakeX=!snakeX!!TX!&quot;<br> set &quot;snakeY=!snakeY!!TY!&quot;<br> set /a emptyCnt-=1<br><br> %=== manage score ===%<br> set /a &quot;score+=1, grow-=1&quot;<br> if not defined replay if !score! gtr !hi! set /a &quot;hi+=1, newHi=1&quot;<br><br> ) else (<br> %=== add the former tail position to the empty list ===%<br> set &quot;empty=!empty!#!TX! !TY!&quot;<br> )<br><br> %=== draw the new head ===%<br> if defined snakeX (%plot% !PX! !PY! body)<br> %plot% !X! !Y! head<br><br> %=== Add the new head position to the snake strings ===%<br> set &quot;snakeX=!X!!snakeX!&quot;<br> set &quot;snakeY=!Y!!snakeY!&quot;<br> set &quot;PX=!X!&quot;<br> set &quot;PY=!Y!&quot;<br><br> %draw%<br><br> ) || (<br><br> %=== failed move - game over ===%<br> set &quot;replayFinished=1&quot;<br> %plot% !TX! !TY! body<br> call :spinner !PX! !PY! death<br> %draw%<br> if defined newHi (<br> echo(<br> echo New High Score - Congratulations^^!<br> set &quot;hi!diffCode!=!score!&quot;<br> copy &quot;!gameLog!&quot; &quot;%hiFile%!diffCode!.txt&quot; &gt;nul<br> &gt;&gt;&quot;%hiFile%!diffCode!.txt&quot; echo ::!score!<br> )<br> echo(<br> %ClearLine%<br> call :ask &quot;Press a key to continue...&quot;<br> for %%A in (!configOptions!) do set &quot;%%A=!%%ASave!&quot;<br> call :mainMenu<br> )<br> )<br> )<br>)<br><br><br>::-------------------------------------<br>:getString Prompt Var MaxLen<br>:: Prompt for a string with max lengh of MaxLen.<br>:: Valid keys are alpha-numeric, space, underscore, and dash<br>:: String is terminated by Enter<br>:: Backspace works to delete previous character<br>:: Result is returned in Var<br>set /a &quot;maxLen=%3&quot;<br>set &quot;%2=&quot;<br>%sendCmd% prompt<br>&lt;nul set /p &quot;=%~1 &quot;<br>call :purge<br>:getStringLoop<br>(%getKey% !upper! 0 1 2 3 4 5 6 7 8 9 &quot; &quot; _ - {Enter} !BS!)<br>if defined key (<br> if !key! equ {Enter} (<br> echo(<br> exit /b<br> )<br> if !key! neq !BS! if !maxLen! gtr 0 (<br> set /a maxLen-=1<br> &lt;nul set /p &quot;=.!BS!!key!&quot;<br> set &quot;%2=!%2!!key!<br> )<br> if !key! equ !BS! if defined %2 (<br> set /a maxLen+=1<br> &lt;nul set /p &quot;=!BS! !BS!&quot;<br> set &quot;%2=!%2:~0,-1!&quot;<br> )<br>)<br>if defined inKey %sendCmd% one<br>goto :getStringLoop<br><br><br>::-------------------------------------<br>:ask Prompt ValidKey [Validkey]...<br>:: Prompt for a keypress.<br>:: Wait until a ValidKey is pressed and return result in Key variable.<br>:: Token delimiters, ), and poison characters must be quoted.<br>%sendCmd% prompt<br>&lt;nul set /p &quot;=%~1 &quot;<br>(set validKeys=%*)<br>(set validKeys=!validKeys:%1=!)<br>call :purge<br>:getResponse<br>(%getKey% !validKeys!)<br>if not defined key (<br> if defined inKey %sendCmd% one<br> goto :getResponse<br>)<br>exit /b<br><br><br>:purge<br>set &quot;inKey=&quot;<br>for /l %%N in (1 1 1000) do (<br> set /p &quot;inKey=&quot;<br> if &quot;!inKey!&quot; equ &quot;{purged}.&quot; exit /b<br>)&lt;&amp;9<br>goto :purge<br><br><br>::-------------------------------------<br>:spinner X Y ValueVar<br>set /a d1=-1000000<br>for /l %%N in (1 1 5) do for %%C in (%spinner%) do (<br> call :spinnerDelay<br> %plot% %1 %2 %%C<br> %draw%<br>)<br>call :spinnerDelay<br>(%plot% %1 %2 %3)<br>exit /b<br><br><br>::-------------------------------------<br>:delay centiSeconds<br>setlocal<br>for /f &quot;tokens=1-4 delims=:.,&quot; %%a in (&quot;!time: =0!&quot;) do set /a &quot;spinnerDelay=%1, d1=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100&quot;<br>:: fall through to :spinnerDelay<br><br>::-------------------------------------<br>:spinnerDelay<br>for /f &quot;tokens=1-4 delims=:.,&quot; %%a in (&quot;!time: =0!&quot;) do set /a &quot;d2=(((1%%a*60)+1%%b)*60+1%%c)*100+1%%d-36610100, dDiff=d2-d1&quot;<br>if %dDiff% lss 0 set /a dDiff+=24*60*60*100<br>if %dDiff% lss %spinnerDelay% goto :spinnerDelay<br>set /a d1=d2<br>exit /b<br><br><br>::-------------------------------------<br>:mainMenu<br>cls<br>set &quot;loadAvailable=&quot;<br>echo Growth rate = !growth!<br>echo(<br>echo Main Menu:<br>echo(<br>echo N - New game<br>if defined replayAvailable echo R - Replay previous game<br>if defined saveAvailable echo S - Save a game<br>if exist *.snake.txt echo L - Load and watch a saved game&amp;set &quot;loadAvailable=L&quot;<br><br>echo C - Control options<br>echo G - Graphic options<br>echo Q - Quit<br>echo(<br>set &quot;hiAvailable=&quot;<br>for /l %%N in (1 1 6) do if defined hi%%N (<br> if not defined hiAvailable (<br> echo Replay High Score:<br> echo(<br> )<br> set &quot;desc=!desc%%N!........&quot;<br> set &quot;hiAvailable=!hiAvailable! %%N&quot;<br> echo %%N - !desc:~0,8! !hi%%N!<br>)<br>if defined hiAvailable echo(<br>set &quot;keys=N C G Q !hiAvailable! !replayAvailable! !saveAvailable! !loadAvailable!&quot;<br>call :ask &quot;&gt;&quot; !keys!<br>if /i !key! equ Q (<br> %sendCmd% quit<br> cls<br> exit<br>)<br>if /i !key! equ N (<br> set &quot;replay=&quot;<br> set &quot;replayAvailable=R&quot;<br> set &quot;saveAvailable=S&quot;<br> goto :initialize<br>)<br>if /i !key! equ S (<br> if defined replayAvailable (<br> call :ask &quot;HighScore # or P for Previous:&quot; !hiAvailable! P<br> ) else (<br> call :ask &quot;HighScore #:&quot; !hiAvailable!<br> )<br> echo !key!<br> if /i !key! equ P (set &quot;src=!gameLog!&quot;) else set &quot;src=%hiFile%!key!.txt&quot;<br> call :getString &quot;Save file name:&quot; file 20<br> copy &quot;!src!&quot; &quot;!file!.snake.txt&quot;<br> call :ask &quot;Press a key to continue...&quot;<br>)<br>if /i !key! equ L (<br> call :getString &quot;Load file name:&quot; file 20<br> if exist &quot;!file!.snake.txt&quot; (<br> set &quot;replay=!file!.snake.txt&quot;<br> goto :initialize<br> )<br> echo Error: File &quot;!file!.snake.txt&quot; not found<br> call :ask &quot;Press a key to continue...&quot;<br>)<br>if /i !key! equ R (<br> set &quot;replay=!gameLog!&quot;<br> goto :initialize<br>)<br>if !key! geq 1 if !key! leq 6 (<br> set &quot;replay=%hiFile%!key!.txt&quot;<br> goto :initialize<br>)<br>if /i !key! equ C call :controlOptions<br>if /i !key! equ G call :graphicOptions<br>goto :mainMenu<br><br><br>::-------------------------------------<br>:controlOptions<br>cls<br>set &quot;keys={Enter} T L R P&quot;<br>if !moveKeys! equ 4 set &quot;keys=!keys! U D&quot;<br> echo Control Options:<br> echo(<br> echo T - Type... = !moveKeys! keys<br> echo(<br> echo L - Left... = !left!<br> echo R - Right.. = !right!<br>if !moveKeys! equ 4 echo U - Up..... = !up!<br>if !moveKeys! equ 4 echo D - Down... = !down!<br> echo(<br> echo P - Pause.. = !pause!<br> echo(<br> echo {Enter} - Return to Main Menu<br> echo(<br>call :ask &quot;&gt;&quot; !keys!<br>if !key! equ {Enter} goto :saveUserPrefs<br>if /i !key! equ T (<br> if !moveKeys! equ 2 (set &quot;moveKeys=4&quot;) else set &quot;moveKeys=2&quot;<br> goto :controlOptions<br>)<br>set &quot;option= LLeft RRight UUp DDown PPause&quot;<br>for /f %%O in (&quot;!option:* %key%=!&quot;) do (<br> call :ask &quot;Press a key for %%O:&quot;<br> for %%K in (0 1 2) do if &quot;!key!&quot; equ &quot;!invalid:~%%K,1!&quot; goto :controlOptions<br> for %%C in (!upper!) do set &quot;key=!key:%%C=%%C!&quot;<br> set &quot;%%O=!key!&quot;<br>)<br>goto :controlOptions<br><br><br>::-------------------------------------<br>:graphicOptions<br>cls<br>echo Graphic Options:<br>echo(<br>echo B - Border...... = !bound!<br>echo E - Empty space. = !space!<br>echo H - snake Head.. = !head!<br>echo S - Snake body.. = !body!<br>echo F - Food........ = !food!<br>echo D - Death....... = !death!<br>echo(<br>echo G - Growth rate. = !growth!<br>echo(<br>echo {Enter} - Rturn to Main Menu<br>echo(<br>call :ask &quot;&gt;&quot; B E H S F D G {Enter}<br>if !key! equ {Enter} goto :saveUserPrefs<br>if /i !key! equ G (<br> call :ask &quot;Press a digit for growth rate (0 = 10)&quot; 0 1 2 3 4 5 6 7 8 9<br> if !key! equ 0 set &quot;key=10&quot;<br> set &quot;growth=!key!&quot;<br> call :loadHighScores<br>) else (<br> set &quot;option=-BBorder:bound:-EEmpty Space:space:-HSnake Head:head:-SSnake Body:body:-FFood:food:-DDeath:death:&quot;<br> for /f &quot;tokens=1,2 delims=:&quot; %%A in (&quot;!option:*-%key%=!&quot;) do (<br> call :ask &quot;Press a key for %%A&quot;<br> for %%K in (0 1 2) do if &quot;!key!&quot; equ &quot;!invalid:~%%K,1!&quot; goto :graphicOptions<br> set &quot;%%B=!key!&quot;<br> )<br>)<br>goto :graphicOptions<br><br><br>::------------------------------------<br>:saveUserPrefs<br>(for %%V in (moveKeys up down left right space bound food head body death pause growth) do echo %%V=!%%V!) &gt;&quot;%userPref%&quot;<br>exit /b<br><br><br>::-------------------------------------<br>:initialize<br>cls<br>if defined replay (<br> echo Replay Speed Options:<br>) else (<br> echo Speed Options:<br>)<br>echo delay<br>echo # Description (seconds)<br>echo --- ----------- ---------<br>for /l %%N in (1 1 6) do (<br> set &quot;delay=0!delay%%N!&quot;<br> set &quot;desc=!desc%%N! &quot;<br> echo %%N !desc:~0,11! 0.!delay:~-2!<br>)<br>echo(<br>call :ask &quot;Pick a speed (1-6):&quot; 1 2 3 4 5 6<br>set &quot;difficulty=!desc%key%!&quot;<br>set &quot;delay=!delay%key%!&quot;<br>set &quot;diffCode=%key%&quot;<br>echo %key% - %difficulty%<br>echo(<br>&lt;nul set /p &quot;=Initializing.&quot;<br>set &quot;axis=X&quot;<br>set &quot;xDiff=+1&quot;<br>set &quot;yDiff=+0&quot;<br>set &quot;empty=&quot;<br>set /a &quot;PX=1, PY=height/2, FX=width/2+1, FY=PY, score=0, emptyCnt=0, t1=-1000000&quot;<br>set &quot;gameStart=&quot;<br>set &quot;m=00&quot;<br>set &quot;s=00&quot;<br>set &quot;snakeX= %PX%&quot;<br>set &quot;snakeY= %PY%&quot;<br>set &quot;snakeX=%snakeX:~-2%&quot;<br>set &quot;snakeY=%snakeY:~-2%&quot;<br>for /l %%Y in (0 1 %height%) do (<br> &lt;nul set /p &quot;=.&quot;<br> set &quot;line%%Y=&quot;<br> for /l %%X in (0,1,%width%) do (<br> set &quot;cell=&quot;<br> if %%Y equ 0 set &quot;cell=%bound%&quot;<br> if %%Y equ %height% set &quot;cell=%bound%&quot;<br> if %%X equ 0 set &quot;cell=%bound%&quot;<br> if %%X equ %width% set &quot;cell=%bound%&quot;<br> if %%X equ %PX% if %%Y equ %PY% set &quot;cell=%head%&quot;<br> if not defined cell (<br> set &quot;cell=%space%&quot;<br> set &quot;eX= %%X&quot;<br> set &quot;eY= %%Y&quot;<br> set &quot;empty=!empty!#!eX:~-2! !eY:~-2!&quot;<br> set /a emptyCnt+=1<br> )<br> if %%X equ %FX% if %%Y equ %FY% set &quot;cell=%food%&quot;<br> set &quot;line%%Y=!line%%Y!!cell!&quot;<br> )<br>)<br>for %%A in (!configOptions!) do set &quot;%%ASave=!%%A!&quot;<br>set &quot;replayFinished=&quot;<br>if defined replay (<br> %sendCmd% replay<br> %sendCmd% !replay!<br> call :waitForSignal<br> set &quot;replay=(REPLAY at !difficulty!)&quot;<br> set &quot;read=1&quot;<br> &lt;&amp;9 (<br> for /l %%N in (1 1 !configOptionCnt!) do if defined read (<br> set /p &quot;ln=&quot;<br> if &quot;!ln!&quot; equ &quot;END&quot; (set read=) else set &quot;!ln!&quot;<br> )<br> )<br> set &quot;keys=&quot;<br> set &quot;hi=0&quot;<br> for /f &quot;delims=:&quot; %%A in ('findstr &quot;^::&quot; &quot;%hiFile%!diffCode!.txt&quot; 2^&gt;nul') do set &quot;hi=%%A&quot;<br> (%draw%)<br> call :delay 100<br>) else (<br> if defined hi%diffCode% (set &quot;hi=!hi%diffCode%!&quot;) else set &quot;hi=0&quot;<br> (%draw%)<br> &gt;&quot;!gameLog!&quot; ( <br> for %%A in (!configOptions!) do (echo %%A=!%%A!)<br> (echo END)<br> )<br> echo(<br> if !moveKeys! equ 4 (<br> echo Controls: !up!=up !down!=down !left!=left !right!=right !pause!=pause<br> ) else (<br> echo Controls: !left!=left !right!=right !pause!=pause<br> )<br> echo Avoid running into yourself (!body!!body!!head!^) or wall (!bound!^)<br> echo Eat food (!food!^) to grow.<br> echo(<br> call :ask &quot;Press a key to start...&quot;<br> %sendCmd% go<br>)<br>set &quot;pauseTime=0&quot;<br>set &quot;xDiff!up!=+0&quot;<br>set &quot;xDiff!down!=+0&quot;<br>set &quot;xDiff!left!=-1&quot;<br>set &quot;xDiff!right!=+1&quot;<br>set &quot;yDiff!up!=-1&quot;<br>set &quot;yDiff!down!=+1&quot;<br>set &quot;yDiff!left!=+0&quot;<br>set &quot;yDiff!right!=+0&quot;<br>set &quot;!up!Axis=Y&quot;<br>set &quot;!down!Axis=Y&quot;<br>set &quot;!left!Axis=X&quot;<br>set &quot;!right!Axis=X&quot;<br>set &quot;xTurn!left!=1&quot;<br>set &quot;xTurn!right!=-1&quot;<br>set &quot;yTurn!left!=-1&quot;<br>set &quot;yTurn!right!=1&quot;<br>set &quot;playerSpace=!space!!food!&quot;<br>set ^&quot;keys=&quot;!left!&quot; &quot;!right!&quot; &quot;!pause!&quot;^&quot;<br>set &quot;newHi=&quot;<br>set &quot;grow=0&quot;<br>if !moveKeys! equ 4 set ^&quot;keys=!keys! &quot;!up!&quot; &quot;!down!&quot;^&quot;<br>cls<br>exit /b<br><br><br>::-------------------------------------<br>:waitForSignal<br>if not exist &quot;%signal%&quot; goto :waitForSignal<br>del &quot;%signal%&quot;<br>exit /b<br><br><br>::-------------------------------------<br>:loadHighScores<br>set &quot;saveAvailable=&quot;<br>for /l %%N in (1 1 6) do (<br> set &quot;hi%%N=&quot;<br> for /f &quot;delims=:&quot; %%A in ('findstr &quot;^::&quot; &quot;%hiFile%%%N.txt&quot; 2^&gt;nul') do (<br> set &quot;hi%%N=%%A&quot;<br> set &quot;saveAvailable=S&quot;<br> )<br>)<br>exit /b<br><br><br>::-------------------------------------<br>:fixLogs<br>setlocal enableDelayedExpansion<br>for %%F in (*.snake) do (<br> ren &quot;%%F&quot; &quot;%%F.txt&quot;<br> call :fixLog &quot;%%F.txt&quot;<br>)<br>pushd &quot;%SaveLoc%&quot;<br>for /f &quot;delims=&quot; %%F in ('dir /b SnakeHi*.txt 2^&gt;nul') do (<br> set &quot;file=%%~nF&quot;<br> set &quot;file=Snake1Hi!file:~-1!.txt&quot;<br> ren &quot;%%F&quot; &quot;!file!&quot;<br> call :fixLog &quot;!file!&quot;<br>)<br>popd<br>exit /b<br><br>:fixLog filePath<br>&gt;&quot;%~1.new&quot; (<br> &lt;&quot;%~1&quot; (<br> for %%A in (diffCode difficulty moveKeys up down left right) do (<br> set /p &quot;val=&quot;<br> (echo %%A=!val!)<br> )<br> )<br> (echo growth=1)<br> (echo END)<br> more +7 &quot;%~1&quot;<br>)<br>move /y &quot;%~1.new&quot; &quot;%~1&quot; &gt;nul<br>exit /b<br><br><br>::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::<br>:controller<br>:: Detects keypresses and sends the information to the game via a key file.<br>:: The controller has various modes of input that are activated by commands sent<br>:: from the game via a cmd file.<br>::<br>:: Modes:<br>::<br>:: hold - No input, wait for command<br>::<br>:: go - Continuously get/send key presses<br>::<br>:: prompt - Send {purged} marker to allow game to purge input buffer, then<br>:: get/send a single key press and hold<br>::<br>:: one - Get/send a single key press and hold<br>::<br>:: replay - Copy a game log to the key file. The next line in cmd file<br>:: specifies name of log file to copy. During replay, the controller<br>:: will send an abort signal to the game if a key is pressed.<br>::<br>:: quit - Immediately exit the controller process<br>::<br>:: As written, this routine incorrectly reports ! as ), but that doesn't matter<br>:: since we don't need that key. Both &lt;CR&gt; and Enter key are reported as {Enter}.<br>:: An extra character is appended to the output to preserve any control chars<br>:: when read by SET /P.<br><br>setlocal enableDelayedExpansion<br>for /f %%a in ('copy /Z &quot;%~dpf0&quot; nul') do set &quot;CR=%%a&quot;<br>set &quot;cmd=hold&quot;<br>set &quot;inCmd=&quot;<br>set &quot;key=&quot;<br>for /l %%. in () do (<br> if &quot;!cmd!&quot; neq &quot;hold&quot; (<br> for /f &quot;delims=&quot; %%A in ('xcopy /w &quot;%~f0&quot; &quot;%~f0&quot; 2^&gt;nul') do (<br> if not defined key set &quot;key=%%A&quot;<br> )<br> set &quot;key=!key:~-1!&quot;<br> if !key! equ !CR! set &quot;key={Enter}&quot;<br> )<br> &lt;&amp;8 set /p &quot;inCmd=&quot;<br> if defined inCmd (<br> if !inCmd! equ quit exit<br> set &quot;cmd=!inCmd!&quot;<br> if !inCmd! equ replay (<br> &lt;&amp;8 set /p &quot;file=&quot;<br> type &quot;!file!&quot; &gt;&amp;9<br> copy nul &quot;%signal%&quot;<br> )<br> set &quot;inCmd=&quot;<br> )<br> if defined key (<br> if &quot;!cmd!&quot; equ &quot;prompt&quot; (echo {purged}.)<br> if &quot;!cmd!&quot; equ &quot;replay&quot; (<br> copy nul &quot;%signal%&quot; &gt;nul<br> (echo {purged}.)<br> set &quot;cmd=go&quot;<br> ) else (echo(!key!.)<br> if &quot;!cmd!&quot; neq &quot;go&quot; set &quot;cmd=hold&quot;<br> set &quot;key=&quot;<br> )&gt;&amp;9<br>)</p>
<p>Hey... Just for help, click on my profile and try my snake game...</p>
<p>it does work write it in notepad and save it ?.bat</p>
<p>Uh... It didn't work. Both of them.</p>
that is a very impressively sized program! good job
Thanks it took me a long time to do it without spelling errors etc I hope you enjoy it ?
<p>cwuul</p>
<p>I cant type anything in</p>
<p>same here</p>
Try deleting it and writing the code again onto notepad make sure when you save it you put .bat at the end
<p>thanks man and check out my youtube it is infinityids5 </p>
<p>This dosnt even work at all</p>
<p>This dosnt even work at all</p>
<p>it doesnt work stupid people</p>
I tried it 7 times but nothing happend
<p>it doesnt work for me</p>
<p>Hello everyone! </p><p>If the code on this instructable does not work, try this one: <a href="https://www.instructables.com/id/CMD-Snake-Game/" rel="nofollow">https://www.instructables.com/id/CMD-Snake-Game/</a></p><p>With kind regards,</p><p>Niels, Media Manager of Zembyte</p>
Also Gyes if you liked this please remember to favourite this and comment and follow me I would really apreatiet it peace?<br>

About This Instructable

125,035views

36favorites

License:

Bio: Hi I'm Mohbuscus il be doing guides on pets and gaming and technology I hope you enjoy my guides and please follow peace
More by Mohbuscus:how to create funny computer prank How To See Infrared Light Create Snake Program 
Add instructable to: