![Very Happy :D](./images/smilies/icon_biggrin.gif)
I've updated the code in the initial post.
Dave Benham
Moderator: DosItHelp
Code: Select all
%=== remove the new head location from the empty list ===%
for %%X in ("!X!") do for %%Y in ("!Y!") do set "empty=!empty:#%%~X %%~Y=!"
:: ...
set /a "score+=1, F=(!random!%%emptyCnt)*6+1, emptyCnt-=1"
:: ...
%=== add the former tail position to the empty list ===%
set "empty=!empty!#!TX! !TY!"
Code: Select all
ERROR: This game requires the CHOICE command, but it is missing.
Game aborted. :(
usw.
Code: Select all
Z:\>choice /c:yn /t 0 /d y
CHOICE:Incorrect timeout syntax. Expected form Tc,nn or T:c,nn
Z:\>choice /c:yn /t:y,-1
CHOICE:Incorrect timeout syntax. Expected form Tc,nn or T:c,nn
Code: Select all
: ...
set "choice="
2>nul >nul choice /c:yn /t 0 /d y
if errorlevel 1 if not errorlevel 2 (
set "choice=choice /cs"
)
2>nul >nul choice /c:yn /t:y,1
if errorlevel 1 if not errorlevel 2 set "choice=choice /s"
if not defined choice (
: ...
Code: Select all
set /a "score+=1, F=(!random!%%(emptyCnt-=1))*6+1"
Squashman wrote:I can't get it to work at all. Windows 7 32bit.
It gets stuck at Press any alpha-numeric key to start...
Aacini wrote:I remember that SNAKE game uses just two control keys: turn right and turn left, and that the turn direction was relative to snake movement. As a matter of fact, this behaviour was one of the most funny details of SNAKE game. I used such control in my SNAKE.BAT program (posted more than a year ago, look for it below program #6), that I wrote mainly as an example program on how to use my Window.exe, GetKey.exe, CursorPos.exe and Show.exe auxiliary .exe programs.
Antonio
Code: Select all
:GetKey
set "key="
for /F "usebackq delims=" %%L in (`xcopy /L /w "%~f0" "%~f0" 2^>NUL`) do (
if not defined key set "key=%%L"
)
set "key=%key:~-1%"
exit /b
Code: Select all
SETLOCAL
(SET EXISTCHOICE=)
SET "FOLDER_TO_SEARCH=.\;%PATH%"
FOR %%A IN (CHOICE.EXE) DO (
SET "EXISTCHOICE=%%~$FOLDER_TO_SEARCH:A"
)
IF NOT DEFINED EXISTCHOICE (
SET "FOLDER_TO_SEARCH=%PATH%"
FOR %%A IN (CHOICE.COM) DO (
SET "EXISTCHOICE=%%~$FOLDER_TO_SEARCH:A"
)
)
IF NOT DEFINED EXISTCHOICE (
ECHO CHOICE NOT EXIST
)
Code: Select all
(SET KEYS=WASD)
(SET /A SECONDS=2)
CHOICE /C 0 /N /D 0 /T 1 <NUL >NUL 2>&1
IF NOT ERRORLEVEL 255 (
REM CHOICE VERSION 2003 .EXE
SET "ACTION1=CHOICE.EXE /C %KEYS% /N /D "
SET "ACTION2= /T %SECONDS%"
SET "AGAIN=CHOICE.EXE /C %KEYS%YN /N /M "PLAY AGAIN[Y,N]?""
) ELSE (
REM CHOICE VERSION 98 .COM AND .EXE
SET "ACTION1=CHOICE /C:%KEYS% /N /T:"
SET "ACTION2=,%SECONDS%"
SET "AGAIN=CHOICE /C:%KEYS%YN /N "PLAY AGAIN[Y,N]?""
)
:ACTION
%ACTION1%!MOVEMENT!%ACTION2% >NUL 2>&1
I realize my program does not run on XP without downloading a non-standard CHOICE command, so I haven't met my goal for XP.
Code: Select all
@echo off &setlocal
<nul set /p "=Yes or No [yn]: "
call :choice yn
echo Option #%errorlevel% was chosen.
pause
goto :eof
:choice
setlocal DisableDelayedExpansion
set "n=0" &set "c=" &set "e=" &set "map=%~1"
if not defined map endlocal &exit /b 0
for /f "delims=" %%i in ('2^>nul xcopy /lw "%~f0" "%~f0"') do if not defined c set "c=%%i"
set "c=%c:~-1%"
if defined c (
for /f delims^=^ eol^= %%i in ('cmd /von /u /c "echo(!map!"^|find /v ""^|findstr .') do (
set /a "n += 1" &set "e=%%i"
setlocal EnableDelayedExpansion
if /i "!e!"=="!c!" (
echo(!c!
for /f %%j in ("!n!") do endlocal &endlocal &exit /b %%j
)
endlocal
)
)
endlocal &goto choice