Batch movement

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Batch movement

#1 Post by batnoob » 21 Apr 2017 13:44

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

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Batch movement

#2 Post by Sounak@9434 » 21 Apr 2017 23:48

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

batnoob
Posts: 56
Joined: 19 Apr 2017 12:23

Re: Batch movement

#3 Post by batnoob » 24 Apr 2017 07:33

no, i am just trying to move the 'X' without moving the entire wall

Sounak@9434
Posts: 100
Joined: 16 Dec 2016 22:31

Re: Batch movement

#4 Post by Sounak@9434 » 24 Apr 2017 23:44

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.

penpen
Expert
Posts: 2009
Joined: 23 Jun 2013 06:15
Location: Germany

Re: Batch movement

#5 Post by penpen » 25 Apr 2017 03:44

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

Post Reply