我正在批量制作代码以猜测女王游戏(1张右卡,2张错误),它将成为更大游戏的一部分(因此是旅馆循环)。但是每当我选择一张不是卡片的卡片时,它就会给我"(此时出乎意料的是#34;。代码中导致这种情况的原因是什么?
就在这里
:cards
if %unum%==%realcard% (goto rand1)
if NOT %unum%==%realcard% (goto rand2)
:rand1
if %randchoice%==1 (goto fake1)
if NOT %randchoice%==1 (goto fake2)
:fake1
echo %fakecard1% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:fake2
echo %fakecard2% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:rand2
if NOT %unum%==%fakecard1% (goto fake3)
if %unum%==%fakecard1% (goto fake4)
:fake3
echo %fakecard1% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:fake4
echo %fakecard2% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
对于那些想要完整代码的人:
@echo off
set /a gold=1000
goto q1
:inn
cls
echo THIS IS A TEST INN
pause
:q1
cls
echo ############### Guess the Queen ###############
echo In this game you can bet up to 1,000 Gold
echo If you lose you will lose your bet and an additional
echo 50 percent of your bet.
echo If you win you will get all of the wager back and
echo you will get an additional 50 percent of your wager
echo .
echo 3 cards will be delt and they will contain
echo 2 Aces and 1 Queen
echo You will then pick a card, then one of the aces will
echo be revealed. You then have the choice to keep your
echo card or switch to the other card.
pause
cls
:choiceq
choice /m "Do you want to play?"
if %errorlevel%==2 (goto inn)
if %errorlevel%==1 (goto playqueen)
:playqueen
set wagerq=0
set /p wagerq="Your Wager:"
echo Your Wager is %wagerq%
if %wagerq% GTR %gold% (goto nomoney)
if %wagerq% LEQ 0 (goto zeromoney)
goto dabet
:nomoney
echo You ain't got that much money!
echo You can still bet this, but if you lose the
echo gamblers won't like it, so be WARNED.
choice /m "Do you want still want to bet this?"
if %errorlevel%==2 (goto choiceq)
if %errorlevel%==1 (goto dabet)
:zeromoney
echo Gamblers do not appreciate this.
echo You cannot do that to them.
echo the Gamblers beat you up and you lose one health.
echo And they take all your money
pause
set /a gold=%gold%-%gold%
set /a health=%health%-1
goto inn
:dabet
set /a ranchoice=%RANDOM% * 3 / 32767 +1
set /a realcard= %RANDOM% * 3 / 32767
if %realcard%==0 (set /a realcard=0)
if %realcard%==1 (set /a realcard=1)
if %realcard%==2 (set /a realcard=2)
set /a fakecard1=%realcard%-1
set /a fakecard2=%realcard%-2
if %fakecard1% LSS 0 (set /a fakecard1=%fakecard1% * -1)
if %fakecard2% LSS 0 (set /a fakecard2=%fakecard2% * -1)
echo Which card?
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
set /p unum="Your choice:"
goto checkq
:checkq
if %unum% GTR 2 (goto zeromoney)
if %unum% LSS 0 (goto zeromoney)
goto cards
:cards
if %unum%==%realcard% (goto rand1)
if NOT %unum%==%realcard% (goto rand2)
:rand1
if %randchoice%==1 (goto fake1)
if NOT %randchoice%==1 (goto fake2)
:fake1
echo %fakecard1% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:fake2
echo %fakecard2% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:rand2
if NOT %unum%==%fakecard1% (goto fake3)
if %unum%==%fakecard1% (goto fake4)
:fake3
echo %fakecard1% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:fake4
echo %fakecard2% is an Ace
echo 0 1 2
echo _ _ _
echo ! ! ! ! ! !
echo !_! !_! !_!
goto cq
:cq
choice /m "Do you wish to change your card?"
if %errorlevel%==2 (goto nodeal)
if %errorlevel%==1 (goto deal)
:nodeal
echo Computing
echo .
if %realcard%==%unum% (goto winq)
if NOT %realcard%==%unum% (goto loseq)
:deal
echo Your card is %unum%!
set /p unum: "Which card would you like to change to?"
echo Computing
echo .
if %realcard%==%unum% (goto winq)
if NOT %realcard%==%unum% (goto loseq)
:winq
set /a winamount=%wagerq% + (%wagerq% / 2 )
echo YAY! You WON!
echo Your wager was %wagerq%!
echo You won %winamount%!
if %winamount%==1500 (goto zeromoney)
set /a gold=%gold% + %winamount%
choice /m "Play Again?"
if %errorlevel%==2 (goto inn)
if %errorlevel%==1 (goto q1)
:loseq
set /a loseamount=%wagerq% + (%wagerq% / 2 )
set /a gold=%gold% - %loseamount%
if %gold% LSS 0 (goto yodead)
echo You lost!
echo Better Luck next time!
echo The real card was %realcard%
echo You lost %loseamount% gold
choice /m "Play Again?"
if %errorlevel%==2 (goto inn)
if %errorlevel%==1 (goto q1)
:yodead
echo The gamblers do not appreciate being bet money you don't have.
echo Not Cool
echo .
goto zeromoney
答案 0 :(得分:2)
错字:
set /a ranchoice=%RANDOM% * 3 / 32767 +1
这不会设置ranDchoice
行
if %randchoice%==1 (goto fake1)
的解释类似于if ==1 (goto fake1)
这显然是语法错误。
IF语法是否为string1 operator string2 action。
string1 = = 1;运算符是(goto。(如果理解的话,goto不是运算符,因此它会反对。
如果“%possibleemptyvariable%”==“1”转到...
,则需要或...确保您的变量已设置...