1
在遊戲Snake中,用戶可以在其中輸入選項,遊戲可以讓您在沒有按下回車鍵的情況下進行選擇。你是怎樣做的?此代碼如何在不按回車鍵的情況下捕獲用戶輸入?
但請記住我是初學者,所以請向我解釋任何你可能認爲很難的事情。遊戲可以在這裏找到http://www.dostips.com/forum/viewtopic.php?f=3&t=4741
在遊戲Snake中,用戶可以在其中輸入選項,遊戲可以讓您在沒有按下回車鍵的情況下進行選擇。你是怎樣做的?此代碼如何在不按回車鍵的情況下捕獲用戶輸入?
但請記住我是初學者,所以請向我解釋任何你可能認爲很難的事情。遊戲可以在這裏找到http://www.dostips.com/forum/viewtopic.php?f=3&t=4741
由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:\>
Snake.bat使用'輸入XCOPY/w'爲2.0 – SomethingDark 2014-10-29 01:00:59
是版本,但由於運明確表示,他是一個初學者我以爲我會給他「選擇」命令,因爲它更簡單。無論如何,感謝您撿起它。 – Monacraft 2014-10-29 01:33:44
謝謝你的記住我有點小事,但你能解釋一下錯誤級別是什麼嗎?我試圖查找它,但顯然它有點複雜,請告訴我xcopy是什麼,謝謝! – Cool841 2014-10-29 08:56:06