我正在尝试为文本的特定部分着色,并设法成功部分。我正在使用call :colorEcho
行为文本着色。不起作用的行是第72行。它第一次在第54行工作,但不在第54行。我只是想知道这里是否有人知道如何解决这个问题。
顺便说一下,我从here
@echo off
SETLOCAL EnableDelayedExpansion
for /F "tokens=1,2 delims=#" %%a in ('"prompt #$H#$E# & echo on & for %%b in (1) do rem"') do (
set "DEL=%%a"
)
:start
echo You have been studying for years for this moment, to create a human master race, all you have to do is complete the circuit connecting the lightning rods to the speciman. Do you do it?
ping -n 2 1.1.1.1 > nul
echo.
echo 1) Connect the circuit.
echo 2) No, you take your work and burn it.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto awaken
if "%Choice%"=="2" goto end1
:awaken
cls
echo 3
timeout /t 2 /nobreak >nul
cls
echo 2
timeout /t 2 /nobreak >nul
cls
echo 1
timeout /t 2 /nobreak >nul
cls
echo CRACK!!
timeout /t 2 /nobreak >nul
cls
echo Lightning strikes the rod and you see movement coming from the speciman under the sheet on the table.
pause
cls
echo The creature sits up. It is more disgusting then you ever could have imagined, you are terrified. It stares at you with mindless eyes, what do you do?
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm
:run4life [
cls
]
:staycalm [
cls
echo The monster stares at you.
timeout /t 4 /nobreak >nul
echo It screams
timeout /t 1 /nobreak >nul
call :colorEcho 0a "RAAAAUUUGGGHHH"
timeout /t 2 /nobreak >nul
echo.
echo 1) Run for your life.
echo 2) Stay in the Room.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm2
]
:staycalm2
[
cls
timeout /t 3 /nobreak >nul
echo You hear a knock at the door.
call :colorEcho 0a " Hello, anyone there? Someone reported hearing a scream from your residence."
echo.
echo How should you react?
echo.
echo 1) Jump out the window.
echo 2) Answer the door.
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto run4life
if "%Choice%"=="2" goto staycalm3
]
:staycalm3
[
cls
call :colorEcho 0c "Oh yes, I was just scared by a spider."
echo.
timeout /t 2 /nobreak >nul
echo.
call :colorEcho ob "uhhmmm..."
timeout /t 2 /nobreak >nul
echo.
echo.
call :colorEcho 0b "Well, do you mind if I come in just to check around?
]
:end 1
cls
echo Congratulations, you have completed the game without causing anyone to die!
echo.
echo 1) Exit
echo 2) Play Again!
echo.
set /p Choice=Choose Now:
if "%Choice%"=="1" goto
if "%Choice%"=="2" goto first
:colorEcho
echo off
<nul set /p ".=%DEL%" > "%~2"
findstr /v /a:%1 /R "^$" "%~2" nul
del "%~2" > nul 2>&1i
答案 0 :(得分:2)
您正在使用彩色打印例程的原始版本,该例程无法处理文件名中无效的字符:\
,/
,:
,"
,{ {1}},?
,*
,&
,|
,<
。您正在使用的版本尝试创建名称等于您显示的字符串的文件,因此它不适用于您的问题字符串。
How to have multiple colors in a Windows batch file?的前三个答案有更复杂的版本(更复杂),几乎可以处理任何角色。
答案 1 :(得分:0)
文中的问号是搞砸了。顺便说一句,我认为你的意思是第70行是失败的。