如何让 Batch 识别变量等于 '#' 而不是 'a'

Posted

技术标签:

【中文标题】如何让 Batch 识别变量等于 \'#\' 而不是 \'a\'【英文标题】:How do I get Batch to recognise variable is equal to '#' instead of 'a'如何让 Batch 识别变量等于 '#' 而不是 'a' 【发布时间】:2021-05-21 08:11:10 【问题描述】:

我想创建一个像流氓一样的批处理文件,但是我需要解决一个小问题。当角色走进墙壁时(#),我希望角色后退一步,这是可行的,但是我无法让批处理脚本识别角色是否已经走进墙壁!

@echo off
set drive=%~dp0%
:start
echo %~dp0%
echo Set name
set /p file=">"
if not exist "%drive%Locations\%file%.bat" goto mdfile
set x=12
set y=15
goto level
:level
set loc=x%x%y%y%
set x%x%y%y%=a
call %drive%Locations\%file%.bat
if '%loc%'=='a' goto start
if '%loc%'=='0' echo Entered shop && pause && goto %dire%
if '%loc%'=='~' echo You are drowning && pause && goto boucle
goto boucle

:mdfile
call %~dp0%Locations\make.bat
set x=12
set y=15
goto level


:boucle
cls  
echo.
call :map
echo.
echo %loc%
if '%%!x%x%y%y%!%%' == !#! (echo Equal) else (echo Not Equal)

echo q w e a s d ///// %let%
echo.
set loc=x%x%x%y%
choice /c qweasd /n >nul
if %errorlevel%==1 goto :savenum
if %errorlevel%==2 goto :up
if %errorlevel%==3 goto :savenuma
if %errorlevel%==4 goto :left
if %errorlevel%==5 goto :down
if %errorlevel%==6 goto :right
goto boucle

:map

%xay30%%xay30%%xay30%%xay30%%xay30%%xay30%%xay30%

echo %c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%

echo %c0c0%%x24y1%%x24y2%%x24y3%%x24y4%%x24y5%%x24y6%%x24y7%%x24y8%%x24y9%%x24y10%%x24y11%%x24y12%%x24y13%%x24y14%%x24y15%%x24y16%%x24y17%%x24y18%%x24y19%%x24y20%%x24y21%%x24y22%%x24y23%%x24y24%%x24y25%%x24y26%%x24y27%%x24y28%%x24y29%%x24y30%%c0c0%
echo %c0c0%%x23y1%%x23y2%%x23y3%%x23y4%%x23y5%%x23y6%%x23y7%%x23y8%%x23y9%%x23y10%%x23y11%%x23y12%%x23y13%%x23y14%%x23y15%%x23y16%%x23y17%%x23y18%%x23y19%%x23y20%%x23y21%%x23y22%%x23y23%%x23y24%%x23y25%%x23y26%%x23y27%%x23y28%%x23y29%%x23y30%%c0c0%
echo %c0c0%%x22y1%%x22y2%%x22y3%%x22y4%%x22y5%%x22y6%%x22y7%%x22y8%%x22y9%%x22y10%%x22y11%%x22y12%%x22y13%%x22y14%%x22y15%%x22y16%%x22y17%%x22y18%%x22y19%%x22y20%%x22y21%%x22y22%%x22y23%%x22y24%%x22y25%%x22y26%%x22y27%%x22y28%%x22y29%%x22y30%%c0c0%
echo %c0c0%%x21y1%%x21y2%%x21y3%%x21y4%%x21y5%%x21y6%%x21y7%%x21y8%%x21y9%%x21y10%%x21y11%%x21y12%%x21y13%%x21y14%%x21y15%%x21y16%%x21y17%%x21y18%%x21y19%%x21y20%%x21y21%%x21y22%%x21y23%%x21y24%%x21y25%%x21y26%%x21y27%%x21y28%%x21y29%%x21y30%%c0c0%
echo %c0c0%%x20y1%%x20y2%%x20y3%%x20y4%%x20y5%%x20y6%%x20y7%%x20y8%%x20y9%%x20y10%%x20y11%%x20y12%%x20y13%%x20y14%%x20y15%%x20y16%%x20y17%%x20y18%%x20y19%%x20y20%%x20y21%%x20y22%%x20y23%%x20y24%%x20y25%%x20y26%%x20y27%%x20y28%%x20y29%%x20y30%%c0c0%
echo %c0c0%%x19y1%%x19y2%%x19y3%%x19y4%%x19y5%%x19y6%%x19y7%%x19y8%%x19y9%%x19y10%%x19y11%%x19y12%%x19y13%%x19y14%%x19y15%%x19y16%%x19y17%%x19y18%%x19y19%%x19y20%%x19y21%%x19y22%%x19y23%%x19y24%%x19y25%%x19y26%%x19y27%%x19y28%%x19y29%%x19y30%%c0c0%
echo %c0c0%%x18y1%%x18y2%%x18y3%%x18y4%%x18y5%%x18y6%%x18y7%%x18y8%%x18y9%%x18y10%%x18y11%%x18y12%%x18y13%%x18y14%%x18y15%%x18y16%%x18y17%%x18y18%%x18y19%%x18y20%%x18y21%%x18y22%%x18y23%%x18y24%%x18y25%%x18y26%%x18y27%%x18y28%%x18y29%%x18y30%%c0c0%
echo %c0c0%%x17y1%%x17y2%%x17y3%%x17y4%%x17y5%%x17y6%%x17y7%%x17y8%%x17y9%%x17y10%%x17y11%%x17y12%%x17y13%%x17y14%%x17y15%%x17y16%%x17y17%%x17y18%%x17y19%%x17y20%%x17y21%%x17y22%%x17y23%%x17y24%%x17y25%%x17y26%%x17y27%%x17y28%%x17y29%%x17y30%%c0c0%
echo %c0c0%%x16y1%%x16y2%%x16y3%%x16y4%%x16y5%%x16y6%%x16y7%%x16y8%%x16y9%%x16y10%%x16y11%%x16y12%%x16y13%%x16y14%%x16y15%%x16y16%%x16y17%%x16y18%%x16y19%%x16y20%%x16y21%%x16y22%%x16y23%%x16y24%%x16y25%%x16y26%%x16y27%%x16y28%%x16y29%%x16y30%%c0c0%
echo %c0c0%%x15y1%%x15y2%%x15y3%%x15y4%%x15y5%%x15y6%%x15y7%%x15y8%%x15y9%%x15y10%%x15y11%%x15y12%%x15y13%%x15y14%%x15y15%%x15y16%%x15y17%%x15y18%%x15y19%%x15y20%%x15y21%%x15y22%%x15y23%%x15y24%%x15y25%%x15y26%%x15y27%%x15y28%%x15y29%%x15y30%%c0c0%
echo %c0c0%%x14y1%%x14y2%%x14y3%%x14y4%%x14y5%%x14y6%%x14y7%%x14y8%%x14y9%%x14y10%%x14y11%%x14y12%%x14y13%%x14y14%%x14y15%%x14y16%%x14y17%%x14y18%%x14y19%%x14y20%%x14y21%%x14y22%%x14y23%%x14y24%%x14y25%%x14y26%%x14y27%%x14y28%%x14y29%%x14y30%%c0c0%
echo %c0c0%%x13y1%%x13y2%%x13y3%%x13y4%%x13y5%%x13y6%%x13y7%%x13y8%%x13y9%%x13y10%%x13y11%%x13y12%%x13y13%%x13y14%%x13y15%%x13y16%%x13y17%%x13y18%%x13y19%%x13y20%%x13y21%%x13y22%%x13y23%%x13y24%%x13y25%%x13y26%%x13y27%%x13y28%%x13y29%%x13y30%%c0c0%
echo %c0c0%%x12y1%%x12y2%%x12y3%%x12y4%%x12y5%%x12y6%%x12y7%%x12y8%%x12y9%%x12y10%%x12y11%%x12y12%%x12y13%%x12y14%%x12y15%%x12y16%%x12y17%%x12y18%%x12y19%%x12y20%%x12y21%%x12y22%%x12y23%%x12y24%%x12y25%%x12y26%%x12y27%%x12y28%%x12y29%%x12y30%%c0c0%
echo %c0c0%%x11y1%%x11y2%%x11y3%%x11y4%%x11y5%%x11y6%%x11y7%%x11y8%%x11y9%%x11y10%%x11y11%%x11y12%%x11y13%%x11y14%%x11y15%%x11y16%%x11y17%%x11y18%%x11y19%%x11y20%%x11y21%%x11y22%%x11y23%%x11y24%%x11y25%%x11y26%%x11y27%%x11y28%%x11y29%%x11y30%%c0c0%
echo %c0c0%%x10y1%%x10y2%%x10y3%%x10y4%%x10y5%%x10y6%%x10y7%%x10y8%%x10y9%%x10y10%%x10y11%%x10y12%%x10y13%%x10y14%%x10y15%%x10y16%%x10y17%%x10y18%%x10y19%%x10y20%%x10y21%%x10y22%%x10y23%%x10y24%%x10y25%%x10y26%%x10y27%%x10y28%%x10y29%%x10y30%%c0c0%
echo %c0c0%%x9y1%%x9y2%%x9y3%%x9y4%%x9y5%%x9y6%%x9y7%%x9y8%%x9y9%%x9y10%%x9y11%%x9y12%%x9y13%%x9y14%%x9y15%%x9y16%%x9y17%%x9y18%%x9y19%%x9y20%%x9y21%%x9y22%%x9y23%%x9y24%%x9y25%%x9y26%%x9y27%%x9y28%%x9y29%%x9y30%%c0c0%
echo %c0c0%%x8y1%%x8y2%%x8y3%%x8y4%%x8y5%%x8y6%%x8y7%%x8y8%%x8y9%%x8y10%%x8y11%%x8y12%%x8y13%%x8y14%%x8y15%%x8y16%%x8y17%%x8y18%%x8y19%%x8y20%%x8y21%%x8y22%%x8y23%%x8y24%%x8y25%%x8y26%%x8y27%%x8y28%%x8y29%%x8y30%%c0c0%
echo %c0c0%%x7y1%%x7y2%%x7y3%%x7y4%%x7y5%%x7y6%%x7y7%%x7y8%%x7y9%%x7y10%%x7y11%%x7y12%%x7y13%%x7y14%%x7y15%%x7y16%%x7y17%%x7y18%%x7y19%%x7y20%%x7y21%%x7y22%%x7y23%%x7y24%%x7y25%%x7y26%%x7y27%%x7y28%%x7y29%%x7y30%%c0c0%
echo %c0c0%%x6y1%%x6y2%%x6y3%%x6y4%%x6y5%%x6y6%%x6y7%%x6y8%%x6y9%%x6y10%%x6y11%%x6y12%%x6y13%%x6y14%%x6y15%%x6y16%%x6y17%%x6y18%%x6y19%%x6y20%%x6y21%%x6y22%%x6y23%%x6y24%%x6y25%%x6y26%%x6y27%%x6y28%%x6y29%%x6y30%%c0c0%
echo %c0c0%%x5y1%%x5y2%%x5y3%%x5y4%%x5y5%%x5y6%%x5y7%%x5y8%%x5y9%%x5y10%%x5y11%%x5y12%%x5y13%%x5y14%%x5y15%%x5y16%%x5y17%%x5y18%%x5y19%%x5y20%%x5y21%%x5y22%%x5y23%%x5y24%%x5y25%%x5y26%%x5y27%%x5y28%%x5y29%%x5y30%%c0c0%
echo %c0c0%%x4y1%%x4y2%%x4y3%%x4y4%%x4y5%%x4y6%%x4y7%%x4y8%%x4y9%%x4y10%%x4y11%%x4y12%%x4y13%%x4y14%%x4y15%%x4y16%%x4y17%%x4y18%%x4y19%%x4y20%%x4y21%%x4y22%%x4y23%%x4y24%%x4y25%%x4y26%%x4y27%%x4y28%%x4y29%%x4y30%%c0c0%
echo %c0c0%%x3y1%%x3y2%%x3y3%%x3y4%%x3y5%%x3y6%%x3y7%%x3y8%%x3y9%%x3y10%%x3y11%%x3y12%%x3y13%%x3y14%%x3y15%%x3y16%%x3y17%%x3y18%%x3y19%%x3y20%%x3y21%%x3y22%%x3y23%%x3y24%%x3y25%%x3y26%%x3y27%%x3y28%%x3y29%%x3y30%%c0c0%
echo %c0c0%%x2y1%%x2y2%%x2y3%%x2y4%%x2y5%%x2y6%%x2y7%%x2y8%%x2y9%%x2y10%%x2y11%%x2y12%%x2y13%%x2y14%%x2y15%%x2y16%%x2y17%%x2y18%%x2y19%%x2y20%%x2y21%%x2y22%%x2y23%%x2y24%%x2y25%%x2y26%%x2y27%%x2y28%%x2y29%%x2y30%%c0c0%
echo %c0c0%%x1y1%%x1y2%%x1y3%%x1y4%%x1y5%%x1y6%%x1y7%%x1y8%%x1y9%%x1y10%%x1y11%%x1y12%%x1y13%%x1y14%%x1y15%%x1y16%%x1y17%%x1y18%%x1y19%%x1y20%%x1y21%%x1y22%%x1y23%%x1y24%%x1y25%%x1y26%%x1y27%%x1y28%%x1y29%%x1y30%%c0c0%
echo %c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%
goto :eof

:LEFT
if '%y%'=='1' goto selecmap
set dire=right
set /a y=%y% -  1
set x%x%y%y%=a
goto level

:RIGHT
if '%y%'=='30' goto selecmap
set dire=left
set /a y=%y% + 1
set x%x%y%y%=a
goto level

:UP
if '%x%'=='24' goto selecmap
set dire=down
set /a x=%x% + 1
set x%x%y%y%=a
goto level

:DOWN
if '%x%'=='1' goto selecmap
set dire=up
set /a x=%x% - 1
set x%x%y%y%=a
goto level

:selecmap
goto boucle
set /p =
goto level

基本上,call :level 命令一直调用set x1y1=.set x24y30=.。这是刷新地图的方式。之后,有set x%x%y%y%=a 显示头像。墙壁是在那条线之后设置的。我希望批处理脚本能够识别它已经走到了墙上,因为头像没有设置为 a,而是头像是 #。然后它会转到 :dire 并重置头像所在的位置。 有什么帮助吗?

这里是提到的“make.bat”文件。要进行测试,请确保它与此批处理文件位于同一目录中,位于名为“Locations”的子目录文件夹中

(
 echo set c0c0=#
 echo set cncn=%nd%
 echo set cece=%ed%
 echo set cscs=%sd%
 echo set cwcw=%wd%
 echo set x1y1=.
 echo set x2y1=.
 echo set x3y1=.
 echo set x4y1=.
 echo set x5y1=.
 echo set x6y1=.
 echo set x7y1=.
 echo set x8y1=.
 echo set x9y1=.
 echo set x10y1=.
 echo set x11y1=.
 echo set x12y1=.
 echo set x13y1=.
 echo set x14y1=.
 echo set x15y1=.
 echo set x16y1=.
 echo set x17y1=.
 echo set x18y1=.
 echo set x19y1=.
 echo set x20y1=.
 echo set x21y1=.
 echo set x22y1=.
 echo set x23y1=.
 echo set x24y1=.

 echo set x1y2=.
 echo set x2y2=.
 echo set x3y2=.
 echo set x4y2=.
 echo set x5y2=.
 echo set x6y2=.
 echo set x7y2=.
 echo set x8y2=.
 echo set x9y2=.
 echo set x10y2=.
 echo set x11y2=.
 echo set x12y2=.
 echo set x13y2=.
 echo set x14y2=.
 echo set x15y2=.
 echo set x16y2=.
 echo set x17y2=.
 echo set x18y2=.
 echo set x19y2=.
 echo set x20y2=.
 echo set x21y2=.
 echo set x22y2=.
 echo set x23y2=.
 echo set x24y2=.

 echo set x1y3=.
 echo set x2y3=.
 echo set x3y3=.
 echo set x4y3=.
 echo set x5y3=.
 echo set x6y3=.
 echo set x7y3=.
 echo set x8y3=.
 echo set x9y3=.
 echo set x10y3=.
 echo set x11y3=.
 echo set x12y3=.
 echo set x13y3=.
 echo set x14y3=.
 echo set x15y3=.
 echo set x16y3=.
 echo set x17y3=.
 echo set x18y3=.
 echo set x19y3=.
 echo set x20y3=.
 echo set x21y3=.
 echo set x22y3=.
 echo set x23y3=.
 echo set x24y3=.

 echo set x1y4=.
 echo set x2y4=.
 echo set x3y4=.
 echo set x4y4=.
 echo set x5y4=.
 echo set x6y4=.
 echo set x7y4=.
 echo set x8y4=.
 echo set x9y4=.
 echo set x10y4=.
 echo set x11y4=.
 echo set x12y4=.
 echo set x13y4=.
 echo set x14y4=.
 echo set x15y4=.
 echo set x16y4=.
 echo set x17y4=.
 echo set x18y4=.
 echo set x19y4=.
 echo set x20y4=.
 echo set x21y4=.
 echo set x22y4=.
 echo set x23y4=.
 echo set x24y4=.

 echo set x1y5=.
 echo set x2y5=.
 echo set x3y5=.
 echo set x4y5=.
 echo set x5y5=.
 echo set x6y5=.
 echo set x7y5=.
 echo set x8y5=.
 echo set x9y5=.
 echo set x10y5=.
 echo set x11y5=.
 echo set x12y5=.
 echo set x13y5=.
 echo set x14y5=.
 echo set x15y5=.
 echo set x16y5=.
 echo set x17y5=.
 echo set x18y5=.
 echo set x19y5=.
 echo set x20y5=.
 echo set x21y5=.
 echo set x22y5=.
 echo set x23y5=.
 echo set x24y5=.

 echo set x1y6=.
 echo set x2y6=.
 echo set x3y6=.
 echo set x4y6=.
 echo set x5y6=.
 echo set x6y6=.
 echo set x7y6=.
 echo set x8y6=.
 echo set x9y6=.
 echo set x10y6=.
 echo set x11y6=.
 echo set x12y6=.
 echo set x13y6=.
 echo set x14y6=.
 echo set x15y6=.
 echo set x16y6=.
 echo set x17y6=.
 echo set x18y6=.
 echo set x19y6=.
 echo set x20y6=.
 echo set x21y6=.
 echo set x22y6=.
 echo set x23y6=.
 echo set x24y6=.

 echo set x1y7=.
 echo set x2y7=.
 echo set x3y7=.
 echo set x4y7=.
 echo set x5y7=.
 echo set x6y7=.
 echo set x7y7=.
 echo set x8y7=.
 echo set x9y7=.
 echo set x10y7=.
 echo set x11y7=.
 echo set x12y7=.
 echo set x13y7=.
 echo set x14y7=.
 echo set x15y7=.
 echo set x16y7=.
 echo set x17y7=.
 echo set x18y7=.
 echo set x19y7=.
 echo set x20y7=.
 echo set x21y7=.
 echo set x22y7=.
 echo set x23y7=.
 echo set x24y7=.

 echo set x1y8=.
 echo set x2y8=.
 echo set x3y8=.
 echo set x4y8=.
 echo set x5y8=.
 echo set x6y8=.
 echo set x7y8=.
 echo set x8y8=.
 echo set x9y8=.
 echo set x10y8=.
 echo set x11y8=.
 echo set x12y8=.
 echo set x13y8=.
 echo set x14y8=.
 echo set x15y8=.
 echo set x16y8=.
 echo set x17y8=.
 echo set x18y8=.
 echo set x19y8=.
 echo set x20y8=.
 echo set x21y8=.
 echo set x22y8=.
 echo set x23y8=.
 echo set x24y8=.

 echo set x1y9=.
 echo set x2y9=.
 echo set x3y9=.
 echo set x4y9=.
 echo set x5y9=.
 echo set x6y9=.
 echo set x7y9=.
 echo set x8y9=.
 echo set x9y9=.
 echo set x10y9=.
 echo set x11y9=.
 echo set x12y9=.
 echo set x13y9=.
 echo set x14y9=.
 echo set x15y9=.
 echo set x16y9=.
 echo set x17y9=.
 echo set x18y9=.
 echo set x19y9=.
 echo set x20y9=.
 echo set x21y9=.
 echo set x22y9=.
 echo set x23y9=.
 echo set x24y9=.

 echo set x1y10=.
 echo set x2y10=.
 echo set x3y10=.
 echo set x4y10=.
 echo set x5y10=.
 echo set x6y10=.
 echo set x7y10=.
 echo set x8y10=.
 echo set x9y10=.
 echo set x10y10=.
 echo set x11y10=.
 echo set x12y10=.
 echo set x13y10=.
 echo set x14y10=.
 echo set x15y10=.
 echo set x16y10=.
 echo set x17y10=.
 echo set x18y10=.
 echo set x19y10=.
 echo set x20y10=.
 echo set x21y10=.
 echo set x22y10=.
 echo set x23y10=.
 echo set x24y10=.

 echo set x1y11=.
 echo set x2y11=.
 echo set x3y11=.
 echo set x4y11=.
 echo set x5y11=.
 echo set x6y11=.
 echo set x7y11=.
 echo set x8y11=.
 echo set x9y11=.
 echo set x10y11=.
 echo set x11y11=.
 echo set x12y11=.
 echo set x13y11=.
 echo set x14y11=.
 echo set x15y11=.
 echo set x16y11=.
 echo set x17y11=.
 echo set x18y11=.
 echo set x19y11=.
 echo set x20y11=.
 echo set x21y11=.
 echo set x22y11=.
 echo set x23y11=.
 echo set x24y11=.

 echo set x1y12=.
 echo set x2y12=.
 echo set x3y12=.
 echo set x4y12=.
 echo set x5y12=.
 echo set x6y12=.
 echo set x7y12=.
 echo set x8y12=.
 echo set x9y12=.
 echo set x10y12=.
 echo set x11y12=.
 echo set x12y12=.
 echo set x13y12=.
 echo set x14y12=.
 echo set x15y12=.
 echo set x16y12=.
 echo set x17y12=.
 echo set x18y12=.
 echo set x19y12=.
 echo set x20y12=.
 echo set x21y12=.
 echo set x22y12=.
 echo set x23y12=.
 echo set x24y12=.

 echo set x1y13=.
 echo set x2y13=.
 echo set x3y13=.
 echo set x4y13=.
 echo set x5y13=.
 echo set x6y13=.
 echo set x7y13=.
 echo set x8y13=.
 echo set x9y13=.
 echo set x10y13=.
 echo set x11y13=.
 echo set x12y13=.
 echo set x13y13=.
 echo set x14y13=.
 echo set x15y13=.
 echo set x16y13=.
 echo set x17y13=.
 echo set x18y13=.
 echo set x19y13=.
 echo set x20y13=.
 echo set x21y13=.
 echo set x22y13=.
 echo set x23y13=.
 echo set x24y13=.

 echo set x1y14=.
 echo set x2y14=.
 echo set x3y14=.
 echo set x4y14=.
 echo set x5y14=.
 echo set x6y14=.
 echo set x7y14=.
 echo set x8y14=.
 echo set x9y14=.
 echo set x10y14=.
 echo set x11y14=.
 echo set x12y14=.
 echo set x13y14=.
 echo set x14y14=.
 echo set x15y14=.
 echo set x16y14=.
 echo set x17y14=.
 echo set x18y14=.
 echo set x19y14=.
 echo set x20y14=.
 echo set x21y14=.
 echo set x22y14=.
 echo set x23y14=.
 echo set x24y14=.

 echo set x1y15=.
 echo set x2y15=.
 echo set x3y15=.
 echo set x4y15=.
 echo set x5y15=.
 echo set x6y15=.
 echo set x7y15=.
 echo set x8y15=.
 echo set x9y15=.
 echo set x10y15=.
 echo set x11y15=.
 echo set x12y15=.
 echo set x13y15=.
 echo set x14y15=.
 echo set x15y15=.
 echo set x16y15=.
 echo set x17y15=.
 echo set x18y15=.
 echo set x19y15=.
 echo set x20y15=.
 echo set x21y15=.
 echo set x22y15=.
 echo set x23y15=.
 echo set x24y15=.

 echo set x1y16=.
 echo set x2y16=.
 echo set x3y16=.
 echo set x4y16=.
 echo set x5y16=.
 echo set x6y16=.
 echo set x7y16=.
 echo set x8y16=.
 echo set x9y16=.
 echo set x10y16=.
 echo set x11y16=.
 echo set x12y16=.
 echo set x13y16=.
 echo set x14y16=.
 echo set x15y16=.
 echo set x16y16=.
 echo set x17y16=.
 echo set x18y16=.
 echo set x19y16=.
 echo set x20y16=.
 echo set x21y16=.
 echo set x22y16=.
 echo set x23y16=.
 echo set x24y16=.

 echo set x1y17=.
 echo set x2y17=.
 echo set x3y17=.
 echo set x4y17=.
 echo set x5y17=.
 echo set x6y17=.
 echo set x7y17=.
 echo set x8y17=.
 echo set x9y17=.
 echo set x10y17=.
 echo set x11y17=.
 echo set x12y17=.
 echo set x13y17=.
 echo set x14y17=.
 echo set x15y17=.
 echo set x16y17=.
 echo set x17y17=.
 echo set x18y17=.
 echo set x19y17=.
 echo set x20y17=.
 echo set x21y17=.
 echo set x22y17=.
 echo set x23y17=.
 echo set x24y17=.

 echo set x1y18=.
 echo set x2y18=.
 echo set x3y18=.
 echo set x4y18=.
 echo set x5y18=.
 echo set x6y18=.
 echo set x7y18=.
 echo set x8y18=.
 echo set x9y18=.
 echo set x10y18=.
 echo set x11y18=.
 echo set x12y18=.
 echo set x13y18=.
 echo set x14y18=.
 echo set x15y18=.
 echo set x16y18=.
 echo set x17y18=.
 echo set x18y18=.
 echo set x19y18=.
 echo set x20y18=.
 echo set x21y18=.
 echo set x22y18=.
 echo set x23y18=.
 echo set x24y18=.

 echo set x1y19=.
 echo set x2y19=.
 echo set x3y19=.
 echo set x4y19=.
 echo set x5y19=.
 echo set x6y19=.
 echo set x7y19=.
 echo set x8y19=.
 echo set x9y19=.
 echo set x10y19=.
 echo set x11y19=.
 echo set x12y19=.
 echo set x13y19=.
 echo set x14y19=.
 echo set x15y19=.
 echo set x16y19=.
 echo set x17y19=.
 echo set x18y19=.
 echo set x19y19=.
 echo set x20y19=.
 echo set x21y19=.
 echo set x22y19=.
 echo set x23y19=.
 echo set x24y19=.

 echo set x1y20=.
 echo set x2y20=.
 echo set x3y20=.
 echo set x4y20=.
 echo set x5y20=.
 echo set x6y20=.
 echo set x7y20=.
 echo set x8y20=.
 echo set x9y20=.
 echo set x10y20=.
 echo set x11y20=.
 echo set x12y20=.
 echo set x13y20=.
 echo set x14y20=.
 echo set x15y20=.
 echo set x16y20=.
 echo set x17y20=.
 echo set x18y20=.
 echo set x19y20=.
 echo set x20y20=.
 echo set x21y20=.
 echo set x22y20=.
 echo set x23y20=.
 echo set x24y20=.

 echo set x1y21=.
 echo set x2y21=.
 echo set x3y21=.
 echo set x4y21=.
 echo set x5y21=.
 echo set x6y21=.
 echo set x7y21=.
 echo set x8y21=.
 echo set x9y21=.
 echo set x10y21=.
 echo set x11y21=.
 echo set x12y21=.
 echo set x13y21=.
 echo set x14y21=.
 echo set x15y21=.
 echo set x16y21=.
 echo set x17y21=.
 echo set x18y21=.
 echo set x19y21=.
 echo set x20y21=.
 echo set x21y21=.
 echo set x22y21=.
 echo set x23y21=.
 echo set x24y21=.

 echo set x1y22=.
 echo set x2y22=.
 echo set x3y22=.
 echo set x4y22=.
 echo set x5y22=.
 echo set x6y22=.
 echo set x7y22=.
 echo set x8y22=.
 echo set x9y22=.
 echo set x10y22=.
 echo set x11y22=.
 echo set x12y22=.
 echo set x13y22=.
 echo set x14y22=.
 echo set x15y22=.
 echo set x16y22=.
 echo set x17y22=.
 echo set x18y22=.
 echo set x19y22=.
 echo set x20y22=.
 echo set x21y22=.
 echo set x22y22=.
 echo set x23y22=.
 echo set x24y22=.

 echo set x1y23=.
 echo set x2y23=.
 echo set x3y23=.
 echo set x4y23=.
 echo set x5y23=.
 echo set x6y23=.
 echo set x7y23=.
 echo set x8y23=.
 echo set x9y23=.
 echo set x10y23=.
 echo set x11y23=.
 echo set x12y23=.
 echo set x13y23=.
 echo set x14y23=.
 echo set x15y23=.
 echo set x16y23=.
 echo set x17y23=.
 echo set x18y23=.
 echo set x19y23=.
 echo set x20y23=.
 echo set x21y23=.
 echo set x22y23=.
 echo set x23y23=.
 echo set x24y23=.

 echo set x1y24=.
 echo set x2y24=.
 echo set x3y24=.
 echo set x4y24=.
 echo set x5y24=.
 echo set x6y24=.
 echo set x7y24=.
 echo set x8y24=.
 echo set x9y24=.
 echo set x10y24=.
 echo set x11y24=.
 echo set x12y24=.
 echo set x13y24=.
 echo set x14y24=.
 echo set x15y24=.
 echo set x16y24=.
 echo set x17y24=.
 echo set x18y24=.
 echo set x19y24=.
 echo set x20y24=.
 echo set x21y24=.
 echo set x22y24=.
 echo set x23y24=.
 echo set x24y24=.

 echo set x1y25=.
 echo set x2y25=.
 echo set x3y25=.
 echo set x4y25=.
 echo set x5y25=.
 echo set x6y25=.
 echo set x7y25=.
 echo set x8y25=.
 echo set x9y25=.
 echo set x10y25=.
 echo set x11y25=.
 echo set x12y25=.
 echo set x13y25=.
 echo set x14y25=.
 echo set x15y25=.
 echo set x16y25=.
 echo set x17y25=.
 echo set x18y25=.
 echo set x19y25=.
 echo set x20y25=.
 echo set x21y25=.
 echo set x22y25=.
 echo set x23y25=.
 echo set x24y25=.

 echo set x1y26=.
 echo set x2y26=.
 echo set x3y26=.
 echo set x4y26=.
 echo set x5y26=.
 echo set x6y26=.
 echo set x7y26=.
 echo set x8y26=.
 echo set x9y26=.
 echo set x10y26=.
 echo set x11y26=.
 echo set x12y26=.
 echo set x13y26=.
 echo set x14y26=.
 echo set x15y26=.
 echo set x16y26=.
 echo set x17y26=.
 echo set x18y26=.
 echo set x19y26=.
 echo set x20y26=.
 echo set x21y26=.
 echo set x22y26=.
 echo set x23y26=.
 echo set x24y26=.

 echo set x1y27=.
 echo set x2y27=.
 echo set x3y27=.
 echo set x4y27=.
 echo set x5y27=.
 echo set x6y27=.
 echo set x7y27=.
 echo set x8y27=.
 echo set x9y27=.
 echo set x10y27=.
 echo set x11y27=.
 echo set x12y27=.
 echo set x13y27=.
 echo set x14y27=.
 echo set x15y27=.
 echo set x16y27=.
 echo set x17y27=.
 echo set x18y27=.
 echo set x19y27=.
 echo set x20y27=.
 echo set x21y27=.
 echo set x22y27=.
 echo set x23y27=.
 echo set x24y27=.

 echo set x1y28=.
 echo set x2y28=.
 echo set x3y28=.
 echo set x4y28=.
 echo set x5y28=.
 echo set x6y28=.
 echo set x7y28=.
 echo set x8y28=.
 echo set x9y28=.
 echo set x10y28=.
 echo set x11y28=.
 echo set x12y28=.
 echo set x13y28=.
 echo set x14y28=.
 echo set x15y28=.
 echo set x16y28=.
 echo set x17y28=.
 echo set x18y28=.
 echo set x19y28=.
 echo set x20y28=.
 echo set x21y28=.
 echo set x22y28=.
 echo set x23y28=.
 echo set x24y28=.

 echo set x1y29=.
 echo set x2y29=.
 echo set x3y29=.
 echo set x4y29=.
 echo set x5y29=.
 echo set x6y29=.
 echo set x7y29=.
 echo set x8y29=.
 echo set x9y29=.
 echo set x10y29=.
 echo set x11y29=.
 echo set x12y29=.
 echo set x13y29=.
 echo set x14y29=.
 echo set x15y29=.
 echo set x16y29=.
 echo set x17y29=.
 echo set x18y29=.
 echo set x19y29=.
 echo set x20y29=.
 echo set x21y29=.
 echo set x22y29=.
 echo set x23y29=.
 echo set x24y29=.

 echo set x1y30=.
 echo set x2y30=.
 echo set x3y30=.
 echo set x4y30=.
 echo set x5y30=.
 echo set x6y30=.
 echo set x7y30=.
 echo set x8y30=.
 echo set x9y30=.
 echo set x10y30=.
 echo set x11y30=.
 echo set x12y30=.
 echo set x13y30=.
 echo set x14y30=.
 echo set x15y30=.
 echo set x16y30=.
 echo set x17y30=.
 echo set x18y30=.
 echo set x19y30=.
 echo set x20y30=.
 echo set x21y30=.
 echo set x22y30=.
 echo set x23y30=.
 echo set x24y30=.


 echo set x%%x%%y%%y%%=a)>%drive%Locations\%file%.bat

A.S.C

(Edit Stephan):这是我上周为测试创建的make.bat(创建随机地图)-也许你觉得它有用:

@echo off 
<nul set /p "=building random map "
for /l %%x in (24,-1,1) do (
  <nul set /p "=."
  for /l %%y in (1,1,30) do (
    set "x%%xy%%y=."
    call :setvar %%x %%y 20 "#"
    call :setvar %%x %%y 10 "~"
  )
)
set "x5y5=@"
set "c0c0=#"
goto :eof
:setvar x y threshhold char
if %random:~-2% lss %3 set "x%1y%2=%~4"

【问题讨论】:

不可重现 - 我假设 make.bat 构建网格?无论如何 - if '%!x12y15!%' == !#! ... 似乎很奇怪 - 你的意思是 if '%!x12y15!%' == '#' ... 吗? (顺便说一句:你真的应该使用双引号 if: if "%!x12y15!%" == "#" ... 一切正常,make.bat 文件为我创建了一个空白画布来制作该地图,然后做什么`! ` 符号呢? 我想,你知道,what the exclamation marks mean,因为你在代码中使用了它们。 我用过它们,但我不知道它们到底是什么,我只是根据我在其他地方发现的东西进行实验。 【参考方案1】:

我建议这个我无法测试的代码,因为发布的代码不是一个最小的、可重现的例子。

@echo off
setlocal EnableExtensions DisableDelayedExpansion
set "BatchPath=%~dp0"

:Begin
setlocal EnableDelayedExpansion
echo !BatchPath!
endlocal
:PromptName
set "file="
set /P "file=Set name> "
rem Prompt the user again on no file name entered at all.
if not defined file goto PromptName
rem Remove all double quotes from user input string.
set "file=%file:"=%"
rem Prompt the user again on just double quotes entered by the user.
if not defined file goto PromptName
rem Contains the entered string a character not valid in a file name.
set "ValidName=?"
for /F "eol=| delims=*/:<>?\|   " %%I in ("%file%") do set "ValidName=%%I"
if not "%ValidName%" == "%file%" goto PromptName
set "ValidName="
rem If the file name was entered with file extension .bat, remove
rem the file extension, except the entered string is just .bat.
for %%I in ("%file%") do if /I "%%~xI" == ".bat" if not "%%~nI" == "" set "file=%%~nI"
if not exist "%BatchPath%Locations\%file%.bat" call "%BatchPath%Locations\make.bat"
set "x=12"
set "y=15"

:level
set "loc=x%x%y%y%"
set "x%x%y%y%=a"
call "%BatchPath%Locations\%file%.bat"
if "%loc%" == "a" goto Begin
if "%loc%" == "0" echo Entered shop& pause & goto %dire%
if "%loc%" == "~" echo You are drowning& pause

cls
echo/
call :map
echo/
echo %loc%
setlocal EnableDelayedExpansion
set "Char=!x%x%y%y%!"
endlocal & if "%Char%" == "#" (echo Equal) else (echo Not Equal)

echo q w e a s d ///// %let%
echo/
set "loc=x%x%x%y%"
%SystemRoot%\System32\choice.exe /C QWEASD /N >nul
if errorlevel 6 goto RIGHT
if errorlevel 5 goto DOWN
if errorlevel 4 goto LEFT
if errorlevel 3 goto savenuma
if errorlevel 2 goto UP
if errorlevel 1 goto savenum
goto boucle

:map

%xay30%%xay30%%xay30%%xay30%%xay30%%xay30%%xay30%

echo %c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%

echo %c0c0%%x24y1%%x24y2%%x24y3%%x24y4%%x24y5%%x24y6%%x24y7%%x24y8%%x24y9%%x24y10%%x24y11%%x24y12%%x24y13%%x24y14%%x24y15%%x24y16%%x24y17%%x24y18%%x24y19%%x24y20%%x24y21%%x24y22%%x24y23%%x24y24%%x24y25%%x24y26%%x24y27%%x24y28%%x24y29%%x24y30%%c0c0%
echo %c0c0%%x23y1%%x23y2%%x23y3%%x23y4%%x23y5%%x23y6%%x23y7%%x23y8%%x23y9%%x23y10%%x23y11%%x23y12%%x23y13%%x23y14%%x23y15%%x23y16%%x23y17%%x23y18%%x23y19%%x23y20%%x23y21%%x23y22%%x23y23%%x23y24%%x23y25%%x23y26%%x23y27%%x23y28%%x23y29%%x23y30%%c0c0%
echo %c0c0%%x22y1%%x22y2%%x22y3%%x22y4%%x22y5%%x22y6%%x22y7%%x22y8%%x22y9%%x22y10%%x22y11%%x22y12%%x22y13%%x22y14%%x22y15%%x22y16%%x22y17%%x22y18%%x22y19%%x22y20%%x22y21%%x22y22%%x22y23%%x22y24%%x22y25%%x22y26%%x22y27%%x22y28%%x22y29%%x22y30%%c0c0%
echo %c0c0%%x21y1%%x21y2%%x21y3%%x21y4%%x21y5%%x21y6%%x21y7%%x21y8%%x21y9%%x21y10%%x21y11%%x21y12%%x21y13%%x21y14%%x21y15%%x21y16%%x21y17%%x21y18%%x21y19%%x21y20%%x21y21%%x21y22%%x21y23%%x21y24%%x21y25%%x21y26%%x21y27%%x21y28%%x21y29%%x21y30%%c0c0%
echo %c0c0%%x20y1%%x20y2%%x20y3%%x20y4%%x20y5%%x20y6%%x20y7%%x20y8%%x20y9%%x20y10%%x20y11%%x20y12%%x20y13%%x20y14%%x20y15%%x20y16%%x20y17%%x20y18%%x20y19%%x20y20%%x20y21%%x20y22%%x20y23%%x20y24%%x20y25%%x20y26%%x20y27%%x20y28%%x20y29%%x20y30%%c0c0%
echo %c0c0%%x19y1%%x19y2%%x19y3%%x19y4%%x19y5%%x19y6%%x19y7%%x19y8%%x19y9%%x19y10%%x19y11%%x19y12%%x19y13%%x19y14%%x19y15%%x19y16%%x19y17%%x19y18%%x19y19%%x19y20%%x19y21%%x19y22%%x19y23%%x19y24%%x19y25%%x19y26%%x19y27%%x19y28%%x19y29%%x19y30%%c0c0%
echo %c0c0%%x18y1%%x18y2%%x18y3%%x18y4%%x18y5%%x18y6%%x18y7%%x18y8%%x18y9%%x18y10%%x18y11%%x18y12%%x18y13%%x18y14%%x18y15%%x18y16%%x18y17%%x18y18%%x18y19%%x18y20%%x18y21%%x18y22%%x18y23%%x18y24%%x18y25%%x18y26%%x18y27%%x18y28%%x18y29%%x18y30%%c0c0%
echo %c0c0%%x17y1%%x17y2%%x17y3%%x17y4%%x17y5%%x17y6%%x17y7%%x17y8%%x17y9%%x17y10%%x17y11%%x17y12%%x17y13%%x17y14%%x17y15%%x17y16%%x17y17%%x17y18%%x17y19%%x17y20%%x17y21%%x17y22%%x17y23%%x17y24%%x17y25%%x17y26%%x17y27%%x17y28%%x17y29%%x17y30%%c0c0%
echo %c0c0%%x16y1%%x16y2%%x16y3%%x16y4%%x16y5%%x16y6%%x16y7%%x16y8%%x16y9%%x16y10%%x16y11%%x16y12%%x16y13%%x16y14%%x16y15%%x16y16%%x16y17%%x16y18%%x16y19%%x16y20%%x16y21%%x16y22%%x16y23%%x16y24%%x16y25%%x16y26%%x16y27%%x16y28%%x16y29%%x16y30%%c0c0%
echo %c0c0%%x15y1%%x15y2%%x15y3%%x15y4%%x15y5%%x15y6%%x15y7%%x15y8%%x15y9%%x15y10%%x15y11%%x15y12%%x15y13%%x15y14%%x15y15%%x15y16%%x15y17%%x15y18%%x15y19%%x15y20%%x15y21%%x15y22%%x15y23%%x15y24%%x15y25%%x15y26%%x15y27%%x15y28%%x15y29%%x15y30%%c0c0%
echo %c0c0%%x14y1%%x14y2%%x14y3%%x14y4%%x14y5%%x14y6%%x14y7%%x14y8%%x14y9%%x14y10%%x14y11%%x14y12%%x14y13%%x14y14%%x14y15%%x14y16%%x14y17%%x14y18%%x14y19%%x14y20%%x14y21%%x14y22%%x14y23%%x14y24%%x14y25%%x14y26%%x14y27%%x14y28%%x14y29%%x14y30%%c0c0%
echo %c0c0%%x13y1%%x13y2%%x13y3%%x13y4%%x13y5%%x13y6%%x13y7%%x13y8%%x13y9%%x13y10%%x13y11%%x13y12%%x13y13%%x13y14%%x13y15%%x13y16%%x13y17%%x13y18%%x13y19%%x13y20%%x13y21%%x13y22%%x13y23%%x13y24%%x13y25%%x13y26%%x13y27%%x13y28%%x13y29%%x13y30%%c0c0%
echo %c0c0%%x12y1%%x12y2%%x12y3%%x12y4%%x12y5%%x12y6%%x12y7%%x12y8%%x12y9%%x12y10%%x12y11%%x12y12%%x12y13%%x12y14%%x12y15%%x12y16%%x12y17%%x12y18%%x12y19%%x12y20%%x12y21%%x12y22%%x12y23%%x12y24%%x12y25%%x12y26%%x12y27%%x12y28%%x12y29%%x12y30%%c0c0%
echo %c0c0%%x11y1%%x11y2%%x11y3%%x11y4%%x11y5%%x11y6%%x11y7%%x11y8%%x11y9%%x11y10%%x11y11%%x11y12%%x11y13%%x11y14%%x11y15%%x11y16%%x11y17%%x11y18%%x11y19%%x11y20%%x11y21%%x11y22%%x11y23%%x11y24%%x11y25%%x11y26%%x11y27%%x11y28%%x11y29%%x11y30%%c0c0%
echo %c0c0%%x10y1%%x10y2%%x10y3%%x10y4%%x10y5%%x10y6%%x10y7%%x10y8%%x10y9%%x10y10%%x10y11%%x10y12%%x10y13%%x10y14%%x10y15%%x10y16%%x10y17%%x10y18%%x10y19%%x10y20%%x10y21%%x10y22%%x10y23%%x10y24%%x10y25%%x10y26%%x10y27%%x10y28%%x10y29%%x10y30%%c0c0%
echo %c0c0%%x9y1%%x9y2%%x9y3%%x9y4%%x9y5%%x9y6%%x9y7%%x9y8%%x9y9%%x9y10%%x9y11%%x9y12%%x9y13%%x9y14%%x9y15%%x9y16%%x9y17%%x9y18%%x9y19%%x9y20%%x9y21%%x9y22%%x9y23%%x9y24%%x9y25%%x9y26%%x9y27%%x9y28%%x9y29%%x9y30%%c0c0%
echo %c0c0%%x8y1%%x8y2%%x8y3%%x8y4%%x8y5%%x8y6%%x8y7%%x8y8%%x8y9%%x8y10%%x8y11%%x8y12%%x8y13%%x8y14%%x8y15%%x8y16%%x8y17%%x8y18%%x8y19%%x8y20%%x8y21%%x8y22%%x8y23%%x8y24%%x8y25%%x8y26%%x8y27%%x8y28%%x8y29%%x8y30%%c0c0%
echo %c0c0%%x7y1%%x7y2%%x7y3%%x7y4%%x7y5%%x7y6%%x7y7%%x7y8%%x7y9%%x7y10%%x7y11%%x7y12%%x7y13%%x7y14%%x7y15%%x7y16%%x7y17%%x7y18%%x7y19%%x7y20%%x7y21%%x7y22%%x7y23%%x7y24%%x7y25%%x7y26%%x7y27%%x7y28%%x7y29%%x7y30%%c0c0%
echo %c0c0%%x6y1%%x6y2%%x6y3%%x6y4%%x6y5%%x6y6%%x6y7%%x6y8%%x6y9%%x6y10%%x6y11%%x6y12%%x6y13%%x6y14%%x6y15%%x6y16%%x6y17%%x6y18%%x6y19%%x6y20%%x6y21%%x6y22%%x6y23%%x6y24%%x6y25%%x6y26%%x6y27%%x6y28%%x6y29%%x6y30%%c0c0%
echo %c0c0%%x5y1%%x5y2%%x5y3%%x5y4%%x5y5%%x5y6%%x5y7%%x5y8%%x5y9%%x5y10%%x5y11%%x5y12%%x5y13%%x5y14%%x5y15%%x5y16%%x5y17%%x5y18%%x5y19%%x5y20%%x5y21%%x5y22%%x5y23%%x5y24%%x5y25%%x5y26%%x5y27%%x5y28%%x5y29%%x5y30%%c0c0%
echo %c0c0%%x4y1%%x4y2%%x4y3%%x4y4%%x4y5%%x4y6%%x4y7%%x4y8%%x4y9%%x4y10%%x4y11%%x4y12%%x4y13%%x4y14%%x4y15%%x4y16%%x4y17%%x4y18%%x4y19%%x4y20%%x4y21%%x4y22%%x4y23%%x4y24%%x4y25%%x4y26%%x4y27%%x4y28%%x4y29%%x4y30%%c0c0%
echo %c0c0%%x3y1%%x3y2%%x3y3%%x3y4%%x3y5%%x3y6%%x3y7%%x3y8%%x3y9%%x3y10%%x3y11%%x3y12%%x3y13%%x3y14%%x3y15%%x3y16%%x3y17%%x3y18%%x3y19%%x3y20%%x3y21%%x3y22%%x3y23%%x3y24%%x3y25%%x3y26%%x3y27%%x3y28%%x3y29%%x3y30%%c0c0%
echo %c0c0%%x2y1%%x2y2%%x2y3%%x2y4%%x2y5%%x2y6%%x2y7%%x2y8%%x2y9%%x2y10%%x2y11%%x2y12%%x2y13%%x2y14%%x2y15%%x2y16%%x2y17%%x2y18%%x2y19%%x2y20%%x2y21%%x2y22%%x2y23%%x2y24%%x2y25%%x2y26%%x2y27%%x2y28%%x2y29%%x2y30%%c0c0%
echo %c0c0%%x1y1%%x1y2%%x1y3%%x1y4%%x1y5%%x1y6%%x1y7%%x1y8%%x1y9%%x1y10%%x1y11%%x1y12%%x1y13%%x1y14%%x1y15%%x1y16%%x1y17%%x1y18%%x1y19%%x1y20%%x1y21%%x1y22%%x1y23%%x1y24%%x1y25%%x1y26%%x1y27%%x1y28%%x1y29%%x1y30%%c0c0%
echo %c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%%c0c0%
goto :EOF

:LEFT
if "%y%" == "1" goto selecmap
set "dire=right"
set /A y-=1
set "x%x%y%y%=a"
goto level

:RIGHT
if "%y%" == "30" goto selecmap
set "dire=left"
set /A y+=1
set "x%x%y%y%=a"
goto level

:UP
if "%x%" == "24" goto selecmap
set "dire=down"
set /A x+=1
set "x%x%y%y%=a"
goto level

:DOWN
if "%x%" == "1" goto selecmap
set "dire=up"
set /A x-=1
set "x%x%y%y%=a"
goto level

:selecmap
goto boucle

注意:分隔符是*/:&lt;&gt;?\| 和一个TAB不是三个空格,由浏览器显示和复制。

可以删除以rem 开头的命令行,因为它们仅说明对批处理文件用户输入的字符串应用的检查。

最重要的修复是更换

if '%%!x%x%y%y%!%%' == !#! (echo Equal) else (echo Not Equal)

通过

setlocal EnableDelayedExpansion
set "Char=!x%x%y%y%!"
endlocal & if "%Char%" == "#" (echo Equal) else (echo Not Equal)

改进后的代码首先定义了一个新环境,其中复制了在接下来的两个命令行中使用的当前环境变量列表,并显式启用了delayed expansion,同时命令扩展的状态保持不变。命令 SETLOCAL 将命令扩展(启用)、延迟扩展(禁用)和当前工作目录的当前状态推送到堆栈上。

第二个命令行在执行期间动态构建环境变量的名称。该环境变量的值被延迟扩展引用并赋值给环境变量Char

Windows 命令处理器在第三个命令行上将%Char% 替换为当前环境变量列表中分配给此环境变量的值。然后执行ENDLOCAL命令,删除SETLOCAL之前创建的环境变量列表,环境变量Char,恢复之前的环境变量列表,从堆栈中弹出状态命令扩展并设置状态(仍然启用),从堆栈中弹出延迟扩展的状态并设置状态(再次禁用)并从堆栈中弹出当前目录并将该目录再次设置为当前目录,此处不会更改任何内容。

接下来执行命令 IF 进行字符串比较,其中左侧字符串不再包含%Char%,而是之前在启用延迟扩展的先前环境中确定的字符。

其他改进是:

    此批处理文件所需的执行环境完全定义在顶部,前两个命令行关闭命令回显模式,启用命令扩展并禁用延迟扩展。所以批处理文件的处理不再依赖于在批处理文件之外定义的环境设置。

    使用正确的%~dp0 将批处理文件的完整路径分配给环境变量BatchPath% 仅位于参数引用的开头,而没有任何结尾。 %~dp0 引用当前处理批处理文件的参数 0 的驱动器和路径。在命令提示符窗口中运行 call /? 时的帮助输出解释了不带或带修饰符引用参数字符串的语法。批处理文件路径始终以反斜杠结尾。因此,%~dp0 与文件/文件夹名称或通配符模式的连接应始终不使用额外的反斜杠。

    在所有(重新)定义环境变量的命令行上,命令 SET 的整个参数字符串都用双引号引起来。我在Why is no string output with 'echo %var%' after using 'set var = text' on command line?的回答中详细解释了原因

    算术表达式 的推荐语法用于所有带有命令 SET 和选项 /A 的命令行,如在运行 set /? 的帮助输出中所解释的那样命令提示符窗口。在这种情况下,(通常)不需要双引号,因为在计算算术表达式时会忽略尾随空格/制表符。

    批处理文件的目录输出时不带双引号,使用延迟扩展即使在包含一个或多个&amp;的批处理文件路径上也能正常工作。

    最好将参数字符串用双引号括起来,以确保空格和字符 &amp;()[]^=;!'+,`~&lt;&gt;| 在解析命令行时被 Windows 命令处理器按字面意思解释。这对于将两个字符串与 IF 和运算符 == 进行比较尤其重要,特别是如果两个字符串之一是环境变量引用,可以用未定义的环境变量上的任何内容替换全部。像if %variable% == string 这样的字符串比较可能在处理if == string 之后进行,这是一个严重的语法错误,因为string 不是一个有效的运算符,导致cmd.exe 立即退出批处理文件处理,这对于使用的用户来说永远不会有趣一个批处理文件。

    IF 命令总是将字符串与周围的" 进行比较。因此,在将不包含双引号的变量字符串与固定字符串进行比较时,两个字符串都必须用双引号引起来。另请参阅我在 Symbol equivalent to NEQ, LSS, GTR, etc. in Windows batch files 上的回答,了解 IF 如何准确地进行字符串比较。与 Linux shell 解释器相比,字符 ' 对于 Windows 命令处理器 cmd.exe 没有特殊含义,除了在 ' 中包含一组 for /F 循环。出于这个原因,只有 " 应该用于两个字符串进行比较,而不是其他字符。

其余的改进由以下人员详细解释:

DosTips 论坛主题:ECHO. FAILS to give text or blank line - Instead use ECHO/ Single line with multiple commands using Windows batch file 解释运算符&amp;&amp;&amp;。 How to stop Windows command interpreter from quitting batch file execution on an incorrect user input? Problems checking if string is quoted and adding quotes to string

Stephan 提出了一种更有效的地图展示方式:

:map
setlocal EnableDelayedExpansion
%xay30%%xay30%%xay30%%xay30%%xay30%%xay30%%xay30%
for /L %%y in (1,1,32) do <nul set /P "=%c0c0%"
echo/
for /L %%x in (24,-1,1) do (
    <nul set /P "=%c0c0%"
    for /L %%y in (1,1,30) do (
        <nul set /p "=!x%%xy%%y!"
    )
    echo %c0c0%
)
for /L %%y in (1,1,32) do <nul set /P "=%c0c0%"
endlocal
goto :EOF

谢谢你,斯蒂芬。

【讨论】:

以上是关于如何让 Batch 识别变量等于 '#' 而不是 'a'的主要内容,如果未能解决你的问题,请参考以下文章

如何让我的变量作为变量而不是对象的属性工作?

(转)如何在一台电脑上开启多个tomcat 和配置让系统识别哪个具体的tomcat

C#中,如何让一个变量值不等于指定的两个值

laravel如何验证是不是等于变量

如何让语句识别未定义的变量? [复制]

如何测试变量是不是不等于两个值中的任何一个?