【发布时间】:2014-10-28 23:59:50
【问题描述】:
在 Snake 游戏中,用户在其中键入选项,游戏将带您进入该选项,而无需按 Enter。你是怎么做到的?
但请记住,我是初学者,所以请向我解释任何您认为困难的事情。游戏可以在这里找到http://www.dostips.com/forum/viewtopic.php?f=3&t=4741
【问题讨论】:
标签: file batch-file choice
在 Snake 游戏中,用户在其中键入选项,游戏将带您进入该选项,而无需按 Enter。你是怎么做到的?
但请记住,我是初学者,所以请向我解释任何您认为困难的事情。游戏可以在这里找到http://www.dostips.com/forum/viewtopic.php?f=3&t=4741
【问题讨论】:
标签: file batch-file choice
dbenham 制作的蛇代码非常复杂,但是由于您的问题仅限于输入机制,所以这不是问题。
这个贪吃蛇游戏使用choice 命令,它只需要按下一个指定的键,不需要再按下一个键。根据用户按下的键,变量errorlevel 将更改为该字符在选项列表中的数字位置。
为帮助屏幕键入 choice /?。摘录如下:
CHOICE [/C choices] [/N] [/CS] [/T timeout /D choice] [/M text]
Description:
This tool allows users to select one item from a list
of choices and returns the index of the selected choice.
Parameter List:
/C choices Specifies the list of choices to be created.
Default list is "YN".
/N Hides the list of choices in the prompt.
The message before the prompt is displayed
and the choices are still enabled.
/CS Enables case-sensitive choices to be selected.
By default, the utility is case-insensitive.
/T timeout The number of seconds to pause before a default
choice is made. Acceptable values are from 0 to
9999. If 0 is specified, there will be no pause
and the default choice is selected.
/D choice Specifies the default choice after nnnn seconds.
Character must be in the set of choices specified
by /C option and must also specify nnnn with /T.
/M text Specifies the message to be displayed before
the prompt. If not specified, the utility
displays only a prompt.
/? Displays this help message.
这是一个例子:
C:\> set errorlevel=-1
C:\> choice /c "YN" /m "Yes or No"
Yes or No: [Y,N]? Y
C:\> Echo %errorlevel%
1
C:\>
【讨论】:
xcopy /w 作为 2.0 版的输入
choice 命令,因为它更简单。无论如何,谢谢你把它捡起来。
Errorlevel 是一个变量,一些批量命令通常会更改它以传达它们刚刚返回的错误类型。 Choice 使用它来传达用户所做的选择。 Xcopy 是一个批处理命令,用于复制文件时的附加功能,但是由于它的许多参数,它通常对其他东西有用。