2015-07-13 68 views
0

我正在創建一個.bat文件,它爲二十一點遊戲im編碼創建一個帳戶。在遊戲中,我遇到了代碼%random%的問題,其中im試圖讓它在數字21和4之間選擇一個隨機數。下面是完整的代碼。我有麻煩的線路顯示爲***** [代碼] *****%隨機百分比不能正常工作

@Echo off 
    Color 02 
    title Account Creation 
    mode con cols=44 lines=6 

    Echo Enter to continue 
    pause>nul 

    :newORexisting 
    cls 
    Echo  New account? [1] 
    Echo Existing account [2] 
    set /p answer= 
    if %answer%==1 goto new 
    if %answer%==2 goto load 

    :WI 
    cls 
    Echo Sorry. Wrong input. 
    Echo Enter to retry. 
    pause>nul 
    goto newORexisting 

    :new 
    cls 
    Echo Type your desired account name... 
    Echo then hit enter. 
    Echo. 
    Echo ~*~ NO SPACES ~*~ 
    set /p acctname= 
    goto Next 

    :next 
    cls 
    Echo Now type your 
    Echo desired password. 
    Echo. 
    Echo ~*~ NO SPACES ~*~ 
    set /p password= 
    cls 
    Echo Confirm your password is... 
    Echo %password% 
    Echo is this correct? [y] [n] 
    set /p confirmation= 
    if %confirmation%==y goto createACCT 
    if %confirmation%==n goto Retry 

    :retry 
    Echo Sorry. 
    Echo Press enter to re-enter your password. 
    pause>nul 
    goto next 

    :createACCT 
    color 02 
    cls 
    Echo Creating account, 
    Echo %acctname% 
    Echo Please Wait! 
    ping localhost -n 6 >nul 
    cls 
    Echo Account, 
    Echo %acctname% 
    Echo created. 
    Echo Press enter to finish! 
    pause>nul 
    cls 
    > %acctname%.bat (
    Echo @Echo off 
    Echo color 02 
    Echo title %acctname% 
    Echo Mode con cols=50 lines=30 
    Echo :pass 
    Echo cls 
    Echo Echo Enter your password. 
    Echo set ^/p password= 
    Echo if %%password%%==%password% goto start 
    Echo cls 
    Echo Echo Sorry incorrect password. 
    Echo Echo Enter to retry. 
    Echo Pause^>nul 
    Echo goto pass 
    Echo :start 
    Echo cls 
    Echo Echo welcome back, 
    Echo Echo %acctname% 
    Echo Echo Enter to begin playing. 
    Echo Pause^>nul 
    Echo set money=1000 
    Echo cls 
    Echo :tableselect 
    Echo Echo Welcome to Blackjack. 
    Echo Echo Money:$%%money%% 
    Echo Echo. 
    Echo Echo Please select a table. 
    Echo. 
    Echo Echo Table Number:1 
    Echo Echo Dealer:David 
    Echo Echo Betting Range:$10 - $50 
    Echo Echo. 
    Echo Echo Table Number:2 
    Echo Echo Dealer:Jessica 
    Echo Echo Betting Range:$50 - $100 
    Echo Echo. 
    Echo Echo Table Number:3 
    Echo Echo Dealer:Mark 
    Echo Echo Betting Range:$100 - $500 
    Echo Echo. 
    Echo Echo Table Number:4 
    Echo Echo Dealer:Robert 
    Echo Echo Betting Range:$500 - $1000 
    Echo Echo. 
    Echo set ^/p table=Table Number: 
    Echo if %%table%%==1 goto Table1 
    Echo if %%table%%==2 goto Table2 
    Echo if %%table%%==3 goto Table3 
    Echo if %%table%%==4 goto Table4 
    Echo :Table1 
    Echo if %%money%% LEQ 0 goto NoMoney 
    Echo cls 
    Echo Echo Table Number:1 
    Echo Echo Dealer:David 
    Echo Echo Money:$%%money%% 
    Echo Echo Players: 
    Echo Echo. 
    Echo Echo James:Bet:$0 
    Echo Echo. 
    Echo Echo Angie:Bet:$0 
    Echo Echo. 
    Echo Echo Jaryd:Bet:$0 
    Echo Echo. 
    Echo Echo %acctname%:Bet:$0 
    Echo Echo. 
    Echo set ^/p betamount=Bet Amount:$10 - $50:$ 
    Echo if %%betamount%% LEQ 9 goto invalidbet 
    Echo if %%betamount%% GEQ 51 goto invalidbet 
    Echo goto Table1active 
    Echo :invalidbet 
    Echo cls 
    Echo Echo Sorry. Your bet was invalid. 
    Echo Echo Enter to retry 
    Echo Pause^>nul 
    Echo goto Table1 
    Echo :Table1active 
    Echo set ^/a money=%%money%%-%%betamount%% 
    Echo cls 
    Echo Echo Table Number:1 
    Echo Echo Dealer:David 
    Echo Echo Money:$%%money%% 
    Echo Echo Players: 
    Echo Echo. 
    Echo Echo James:Bet:$%%betamount%% 
    Echo Echo. 
    Echo Echo Angie:Bet:$%%betamount%% 
    Echo Echo. 
    Echo Echo Jaryd:Bet:$%%betamount%% 
    Echo Echo. 
    Echo Echo %acctname%:Bet:$%%betamount%% 
    Echo Echo. 
    Echo Echo Press enter to start dealing. 
    Echo pause^>nul 
    Echo cls 
    *****Echo set handP1=%%random%% %%21+4***** 
    *****Echo set handP2=%%random%% %%21+4***** 
    *****Echo set handP3=%%random%% %%21+4***** 
    *****Echo set handP4=%%random%% %%21+4***** 
    Echo Echo Table Number:1 
    Echo Echo Dealer:David 
    Echo Echo Money:$%%money%% 
    Echo Echo Players: 
    Echo Echo. 
    Echo Echo James:Hand:%%handP1%% 
    Echo Echo. 
    Echo Echo Angie:Hand:%%handP2%% 
    Echo Echo. 
    Echo Echo Jaryd:Hand:%%handP3%% 
    Echo Echo. 
    Echo Echo %acctname%:Hand:%%handP4%% 
    Echo Echo. 
    Echo Echo Press 1 to hit. 
    Echo Echo Press 2 to stay. 
    Echo set ^/p hitStay=Choice: 
    Echo if %%handP1%% LEQ 16 set ^/a handP1=%%handP1%%+%%random%% %11+1 
    Echo if %%handP2%% LEQ 16 set ^/a handP1=%%handP1%%+%%random%% %11+1 
    Echo if %%handP3%% LEQ 16 set ^/a handP1=%%handP1%%+%%random%% %11+1 
    Echo if %%hitStay%%==1 goto hitT1 
    Echo if %%hitStay%%==2 goto stayT1 
    Echo :hitT1 
    Echo set ^/a handP4=%%handP4%%+%%random%% %11 +1 
    Echo cls 
    Echo Table Number:1 
    Echo Echo Dealer:David 
    Echo Echo Money:$%%money%% 
    Echo Echo Players: 
    Echo Echo. 
    Echo Echo James:Hand:$%%handP1%% 
    Echo Echo. 
    Echo Echo Angie:Hand:$%%handP2%% 
    Echo Echo. 
    Echo Echo Jaryd:Hand:$%%handP3%% 
    Echo Echo. 
    Echo Echo %acctname%:Hand:$%%handP4%% 
    Echo Echo. 
    Echo :stayT1 
    Echo cls 
    Echo Table Number:1 
    Echo Echo Dealer:David 
    Echo Echo Money:$%%money%% 
    Echo Echo Players: 
    Echo Echo. 
    Echo Echo James:Hand:$%%handP1%% 
    Echo Echo. 
    Echo Echo Angie:Hand:$%%handP2%% 
    Echo Echo. 
    Echo Echo Jaryd:Hand:$%%handP3%% 
    Echo Echo. 
    Echo Echo %acctname%:Hand:$%%handP4%% 
    Echo Echo. 
    Echo Echo Please Wait. 
    Echo ping localhost -n 5 >nul 
    Echo if %%handP1%% GTR %%handP2%% 

    Echo pause^>nul 
    ) 
    Echo Account Created. 
    Echo Please wait! 
    Ping localhost -n 4 >nul 
    start call %acctname%.bat 
    exit 


    :load 
    cls 
    Echo Type acct name 
    Echo then hit enter. 
    set /p acctname= 
    start call %acctname%.bat 
    exit 

請幫我找出爲什麼這不會工作。這些數字是不是在21和4號顯示爲之間+4 34324,或者一些其他的大量+4

+0

爲什麼bash標記?也只粘貼相關的代碼,而不是整個腳本。 – SMA

+0

這不是bash。你正在使用哪種操作系統和外殼?請將您的示例減少到僅引起問題的部分。 –

+0

http://stackoverflow.com/help/mcve – anishsane

回答

1

更換

Echo set handP1=%%random%% %%21+4 

Echo set /A handP1=%%random%% %%%% 21 + 4 

證明

==>type D:\bat\SO\31377293.bat 
@ECHO OFF >NUL 
> files\31377293.bat (
    Echo set /A handP1=%%random%% %%%% 21 + 4 
    Echo @set handP 
) 
@ECHO ON >NUL 
type files\31377293.bat 
call files\31377293.bat 

輸出

==>D:\bat\SO\31377293.bat 

==>type files\31377293.bat 
set /A handP1=%random% %% 21 + 4 
@set handP 

==>call files\31377293.bat 

==>set /A handP1=8932 % 21 + 4 
handP1=11 

==> 
+0

的第二批生產線參數,它給了我'set/A handP1 =%19661%%%%% 21 + 4 ' – Stephan

+1

@Stephan只有在你從cmd行運行它時纔會得到你的輸出。否則,從批處理文件執行該解決方案時是正確的 – jeb

+0

謝謝。這工作。 – JeLlYBeD