@echo off
color 0a
title Horror Game
echo.
echo.
echo.
echo.
echo Welcome to the game
echo If you get scared
echo Feel free to leave
echo.
echo.
echo You are in a dark room.
echo It is cold.
echo All you hear is a scratching sound
echo near your feet.
echo What do you do?
echo.
echo.
echo 1.) Feel around you
echo 2.) Listen for anything else
set/p input = Command?
if %input% == "1" goto Feel
if %input% == "2" goto Listen
echo.
echo.
:Feel
echo You feel around and hear a growl.
echo As you realize the scratching was
echo on your leg.
echo.
echo You remember nothing else.
pause
end
我正在尝试为 cmd 制作一个基于文本的游戏,每当我尝试输入响应时都会立即关闭,我几乎无法读出“此时转到意外”
最佳答案
你没有正确地形成你的测试。您需要用双引号将变量括起来:
if "%input%" == "1" goto Feel
if "%input%" == "2" goto Listen
请注意,在这些之后您需要一个额外的条件来处理他们没有输入 1 或 2 的可能性。
您应该考虑使用
choice
命令而不是 set /p
.类型 choice /?
从命令提示符。将来,如果您遇到提前终止的问题,请从命令提示符运行您的脚本。这样窗口就不会对您关闭,您将有足够的时间来阅读错误。
您可以通过按 快速运行命令提示符。 -R,输入
cmd
并按 Enter
关于batch-file - goto在这个时候出乎意料,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19898451/