Page 1 of 1

Batch movement

Posted: 21 Apr 2017 13:44
by batnoob
I can't seem to figure out how to create movement like Snake.bat :mrgreen: i think i got it a little bit but i cant figure out the rest. Here's what i got:

Code: Select all

:setup
@echo off
set lsp=   
set char=X
set rsp=   
set wall=#

:1
cls
for /l %%a In (1 1 11) do (<nul set /p "=%wall%")
echo.
for /l %%a In (1 1 4) do (echo %wall%%lsp% %rsp%%wall%)
echo %wall%%lsp%%char%%rsp%%wall%
for /l %%a In (1 1 4) do (echo %wall%%lsp% %rsp%%wall%)
for /l %%a In (1 1 11) do (<nul set /p "=%wall%")
echo.
choice /c ADS /m "S resets"
if %ERRORLEVEL% == 1 (CALL:Left) ELSE if %ERRORLEVEL% == 2 (CALL:Right) Else (goto :setup)
goto :1
pause
exit /b

:Left
set lsp=%lsp:~0,-1%
set rsp=%rsp:~0,+1%
GOTO:EOF

:Right
set rsp=%rsp:~0,-1%
set lsp=%lsp:~0,+1%
GOTO:EOF


Thank you, BatNoob

Re: Batch movement

Posted: 21 Apr 2017 23:48
by Sounak@9434
Are you trying to remove the tail like in snake.bat? If not then you can have a look at my lilgui.bat

Code: Select all

lilgui /a # /h 11 /w 11 /s 6-6 /pc X

LILGUI.zip
(2.29 KiB) Downloaded 847 times

Re: Batch movement

Posted: 24 Apr 2017 07:33
by batnoob
no, i am just trying to move the 'X' without moving the entire wall

Re: Batch movement

Posted: 24 Apr 2017 23:44
by Sounak@9434
batnoob wrote:no, i am just trying to move the 'X' without moving the entire wall

In that case my tool is perfect for you.

Re: Batch movement

Posted: 25 Apr 2017 03:44
by penpen
The variable string manipulation doesn't work, as it seems you have expected:
The expression "%lsp:~0,+1%" does not append a character at the end of lsp, instead it only prints one character starting with index 0.

So this might help you:

Code: Select all

:setup
@echo off
set lsp=   
set char=X
set rsp=   
set wall=#

:1
cls
echo "    " "    "
echo "%lsp%" "%rsp%"

for /l %%a In (1 1 11) do (<nul set /p "=%wall%")
echo.
for /l %%a In (1 1 4) do (echo %wall%%lsp% %rsp%%wall%)
echo %wall%%lsp%%char%%rsp%%wall%
for /l %%a In (1 1 4) do (echo %wall%%lsp% %rsp%%wall%)
for /l %%a In (1 1 11) do (<nul set /p "=%wall%")
echo.
choice /c ADS /m "S resets"
if %ERRORLEVEL% == 1 (CALL:Left) ELSE if %ERRORLEVEL% == 2 (CALL:Right) Else (goto :setup)
goto :1
pause
exit /b

:Left
if defined lsp (
   set "rsp=%lsp:~-1%%rsp%"
   set "lsp=%lsp:~0,-1%"
)
GOTO:EOF

:Right
if defined rsp (
   set "lsp=%rsp:~0,1%%lsp%"
   set "rsp=%rsp:~1%"
)
GOTO:EOF


penpen