이 코드를 배치 파일에 넣으면 :
내 코드는 다음과 같습니다.
@echo off
title template
color 0F
pause
:menu
cls
echo 1.start
echo 2.instructions
echo 3.exit
set /p answer=Type the number of your option and press enter
if %answer%==1 goto start_1
if %answer%==2 goto instructions
if %answer%==3 goto exit
:exit
echo thanks for playing
pause
exit /b
:instructions
cls
echo instructions
echo.
echo This game is case-sensitive!
echo Just have fun with it!
pause
goto menu
:start_1
set /a s1=%random% * 3 / 32768 + 1
if %s1%==1 goto prefight_1
if %s1%==2 goto prefight_2
if %s1%==3 goto prefight_3
:prefight_1
cls
echo You have discovered 3 Turtles!
echo They dont see you!
set /p answer=would you like to (1)FIGHT or (2)RUN?
if %answer%==1 goto fight_1
if %answer%==2 goto run_1
:fight_1
set /a f1=%random% * 4 / 32768 + 1
if %f1%==1 goto lose_fight_1
if %f1%==2 goto win_fight_1
if %f1%==3 goto win_fight_1
if %f1%==4 goto win_fight_1
:prefight_2
cls
echo You have discovered 3 Turtles!
echo They see you!
set /p answer=would you like to (1)FIGHT or (2)RUN?
if %answer%==1 goto fight_2
if %answer%==2 goto run_1
:fight_2
set /a f2=%random% * 4 / 32768 + 1
if %f2% gtr 4 goto fight_2
if %f2% lss 1 goto fight_2
if %f2%==1 goto lose_fight_1
if %f2%==2 goto lose_fight_1
if %f2%==3 goto win_fight_1
if %f2%==4 goto win_fight_1
:prefight_3
cls
echo You have discovered 3 Turtles!
echo They see you!
echo They seem angry!
set /p answer=would you like to (1)FIGHT or (2)RUN?
if %answer%==1 goto fight_3
if %answer%==2 goto run_1
:fight_3
set /a f3=%random% * 4 / 32768 + 1
if %f3%==1 goto lose_fight_1
if %f3%==2 goto lose_fight_1
if %f3%==3 goto lose_fight_1
if %f3%==4 goto win_fight_1
:lose_fight_1
cls
echo Sorry,You LOST!
echo Thank you for playing!
echo made by: JEREMY
set /p answer==(1)continue or (2)quit?
if %answer%==1 goto start_1
if %answer%==2 goto menu
pause
:run_1
cls
echo You ran away
pause
goto start_1
나는 당신이 변수를 설정했다고 강력하게 의심한다 random
. 그렇게했다면 환경에서 설정 한 값이 매직 변수를 재정의합니다.
당신은 그것을 지울 수 있습니다 set "random="
setlocal
뒤에 a를 사용하는 것이 일반적 @echo off
입니다. 이렇게하면 배치가 종료 될 때 환경에 대한 모든 변경 사항이 취소됩니다. 이것이 없으면 변경 사항은 명시 적으로 다시 변경 될 때까지 유지됩니다.
개인적으로 선호합니다
/ a value = % random % %% limit + 1 설정
1..limit 값을 생성합니다. 다른 이유가 없다면 입력하기가 더 쉽습니다.
@echo off
setlocal
rem environment changes made after here will be backed-out when the batch finishes...
....whatever....
이 setlocal
명령은 배치가 종료되거나 endlocal
명령이 발생할 때까지만 존재하는 '로컬'환경을 설정합니다 .
자세한 내용 setlocal /?
은 프롬프트에서 참조하십시오.
win_fight_1
루틴을 추가하면 배치가 잘 작동하는 것 같습니다 .
그러나 일괄 처리가 시작 set /p answer
==(1)continue or (2)quit?
되지만 그중 하나를 제거 =하면 문제가 해결됩니다.
그 이상으로 가고 싶은지 menu
또는 start_1
.
그리고
if %f2% gtr 4 goto fight_2
if %f2% lss 1 goto fight_2
효과가 없을 것입니다. set /a f2=%random% %% 4 + 1
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다