batch-file - 自动检查批处理文件中的输入
问题描述
我目前正在研究批量文本冒险/RPG,以了解更多关于编码的信息,并且我正在尝试实现输入的自动检查(例如玩家类型 1,无需按 Enter 即可通过)。我目前有这个:
echo Type 1 for New Game
echo.
set /p=gamepick
if gamepicker equ 1 goto newgame
if gamepicker neq 1 goto gamepicker
关于如何做到这一点的任何建议?
解决方案
在 Windows 命令批处理文件中,功能代码如下:
REM Turn off command echoing to the screen
@ECHO OFF
ECHO.
ECHO.
SET /p GamePick=Type 1 for New Game
IF "%GamePick%"=="1" goto NewGame
REM If the script gets here, the input value was not a 1
:GamePicker
REM Some code to do something
REM and at the end of the code, exit the script
GOTO Exit
:NewGame
REM The input value was a 1
ECHO We're starting a new game for you!
REM Some game code goes here
REM and at the end of the code, exit the script
GOTO Exit
:Exit
REM This is the end of the script.
推荐阅读
- java - 将 bean 逻辑创建放到一个简单的 Spring Boot 应用程序中的哪里?
- jaxb - 如何在 JAXB Unmarshal 中持久化 Element 的 UserData?
- c# - 如何在实体框架中将 db datetime 转换为 datetime
- javascript - 使用 input[range] 选择器在图像之间切换/淡入淡出
- c# - 如何构建客户端以使用 HMAC-SHA256 签名方法进行 oauth 1.0 身份验证?
- java - 如何在视图类中调用画布并从活动类更改它的颜色
- powershell - 如何遍历目录中的所有子文件夹,并删除具有特定文件名的文件
- android - 没有方法签名:build_*.android()
- node.js - 如何按时间戳对订单进行排序?
- django - Django从媒体下载文件夹