我的批处理程序退出,我不知道为什么

时间:2015-06-23 14:54:51

标签: windows batch-file

所以,我做了一个战争策略游戏。这个想法是你应该用3种武器攻击另一个国家:空袭,核弹和导弹。当我选择武器时,有时批处理文件退出而不显示错误。我想解决这个问题,但我不知道怎么做。批处理程序使用外部命令batbox.exe。从http://www.mediafire.com/download/rwxl04379rtchaq/batbox.exe

下载
@echo off
mode con: cols=80 lines=26
cls
title WW3
set nukeprice=80
set airstrikeprice=40
set missileprice=20
set healthprice=95
:menu
cls
echo                             World War 3
echo.
echo [Start Game]
echo [About]
echo [Exit]
for /f "delims=: tokens=1,2" %%A in ('batbox /m') do (
set x=%%A
set y=%%B
)
if %y%==2 (
if %x% geq 1 if %x% leq 12  (
goto setcountry
)
)
if %y%==3 (
if %x% geq 1 if %x% leq 7  (
goto about
)
)
if %y%==4 (
if %x% geq 1 if %x% leq 7  (
exit
)
)
goto menu
:setcountry
cls
echo Select your country.
echo.
echo [USA]
echo [Russia]
echo [Canada]
echo [UK]
for /f "delims=: tokens=1,2" %%A in ('batbox /m') do (
set x=%%A
set y=%%B
)
if %y%==2 (
if %x% geq 1 if %x% leq 5  (
set country=USA
goto setcpucountry
)
)
if %y%==3 (
if %x% geq 1 if %x% leq 8  (
set country=Russia
goto setcpucountry
)
)
if %y%==4 (
if %x% geq 1 if %x% leq 9  (
set country=Canada
goto setcpucountry
)
)
if %y%==5 (
if %x% geq 1 if %x% leq 4  (
set country=UK
goto setcpucountry
)
)
goto setcountry
:setcpucountry
set /a cpucountryran=%random% %%4 + 1
if %cpucountryran%==1 set enemy=USA
if %cpucountryran%==2 set enemy=Russia
if %cpucountryran%==3 set enemy=Canada
if %cpucountryran%==4 set enemy=UK
if %enemy%==%country% goto setcpucountry
goto setammo
:setammo
set missiles=3
set airstrike=2
set nuke=1
set health=1000
set money=100
set cpumissiles=3
set cpuairstrike=2
set cpunuke=1
set cpumoney=100
set cpuhealth=1000
:play
cls
echo %country%
echo HP: %health%
echo %money%$
echo.
echo [Nuke x %nuke%]
echo [Airstrike x %airstrike%]
echo [Missiles x %missiles%]
echo.
echo [Shop]
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo                                                                        %enemy%
echo                                                                        HP: %cpuhealth%
echo                                                                            %cpumoney%$
echo                                                                      [Nuke x %cpunuke%]
echo                                                                 [Airstrike x %cpuairstrike%]
echo                                                                  [Missiles x %cpumissiles%]
for /f "delims=: tokens=1,2" %%A in ('batbox /m') do (
set x=%%A
set y=%%B
)
if %y%==4 (
if %x% geq 1 if %x% leq 9  (
goto nuke
)
)
if %y%==5 (
if %x% geq 1 if %x% leq 14  (
goto airstrike
)
)
if %y%==6 (
if %x% geq 1 if %x% leq 13  (
goto missiles
)
)
if %y%==8 (
if %x% geq 1 if %x% leq 6  (
goto shop
)
)
goto play
:nuke
if "%nuke%" leq "0" (
echo You are out of Nukes!
ping localhost -n 2 >nul
set nuke=0
goto play
)
cls
echo %country% shot a Nuke on %enemy%!
echo.
set /a nukehit=%random% %%2 + 1
if %nukehit%==1 (
echo Miss!
)
if %nukehit%==2 (
echo Hit!
echo.
echo %enemy% lost 40 HP!
echo.
echo You got 25$!
set /a cpuhealth=%cpuhealth%-40
set /a money=%money%+25
set /a nuke=%nuke%-1
)
if "%cpuhealth%" leq "0" goto win
ping localhost -n 3 >nul
goto cpuplay
:airstrike
if %airstrike% leq 0 (
echo You are out of Airstrikes!
set airstrike=0
ping localhost -n 2 >nul
goto play
)
cls
echo %country% shot a Airstrike on %enemy%!
echo.
set /a airstrikehit=%random% %%2 + 1
if %airstrikehit%==1 (
echo Miss!
)
if %airstrikehit%==2 (
echo Hit!
echo.
echo %enemy% lost 20 HP!
echo.
echo You got 15$!
set /a cpuhealth=%cpuhealth%-20
set /a money=%money%+15
set /a airstrike=%airstrike%-1
)
if %cpuhealth% leq 0 goto win
ping localhost -n 3 >nul
goto cpuplay
:missiles
if %missiles% leq 0 (
echo You are out of Missiles!
set missiles=0
ping localhost -n 2 >nul
goto play
)
cls
echo %country% shot a Missile on %enemy%!
echo.
set /a missilehit=%random% %%2 + 1
if %missilehit%==1 echo Miss!
if %missilehit%==2 (
echo Hit!
echo.
echo %enemy% lost 10 HP!
echo.
echo %country% got 5$!
set /a cpuhealth=%cpuhealth%-10
set /a missiles=%missiles%-1
set /a money=%money%+5
ping localhost -n 3 >nul
)
if %cpuhealth% leq 0 goto win
ping localhost -n 3 >nul
:cpuplay
set /a cpuweapon=%random% %%4 + 1
if %cpuweapon% equ 1 goto cpunuke
if %cpuweapon% equ 2 goto cpuairstrike
if %cpuweapon% equ 3 goto cpumissile
if %cpuweapon% equ 4 goto cpushop
goto cpuplay
:cpunuke
if "%cpunuke%" leq "0" goto cpuplay
cls
echo %enemy% shot a Nuke on %country%!
echo.
set /a cpunukehit=%random% %%2 + 1
if %cpunukehit%==1 (
echo Miss!
ping localhost -n 3 >nul
)
if %cpunukehit%==2 (
echo Hit!
echo.
echo %country% lost 40 HP!
echo.
echo %enemy% got 25$!
set /a health=%health%-40
set /a cpumoney=%cpumoney%+25
set /a cpunuke=%cpunuke%-1
ping localhost -n 3 >nul
)
if "%health%" leq "0" goto lose
goto play
:cpuairstrike
if "%cpuairstrike%" leq "0" goto cpuplay
cls
echo %enemy% shot a Airstrike on %country%!
echo.
set /a cpuairstrikehit=%random% %%2 + 1
if %cpuairstrikehit%==1 (
echo Miss!
ping localhost -n 3 >nul
)
if %cpuairstrikehit%==2 (
echo Hit!
echo.
echo %country% lost 20 HP!
echo.
echo %enemy% got 15$!
set /a health=%health%-20
set /a cpumoney=%cpumoney%+15
set /a cpuairstrike=%cpuairstrike%-1
ping localhost -n 3 >nul
)
if "%health%" leq "0" goto lose
goto play
:cpumissile
if "%cpumissile%" leq "0" goto cpuplay
cls
echo %enemy% shot a Missile on %country%!
echo.
set /a cpumissilehit=%random% %%2 + 1
if %cpumissilehit%==1 (
echo Miss!
ping localhost -n 3 >nul
)
if %cpumissilehit%==2 (
echo Hit!
echo.
echo %country% lost 10 HP!
echo.
echo %enemy% got 5$
set /a health=%health%-10
set /a cpumoney=%cpumoney%+5
set /a cpumissile=%cpumissile%-1
ping localhost -n 3 >nul
)
if "%health%" leq "0" goto lose
goto play
:cpushop
set /a cpubuyran=%random% %%4 + 1
if %cpubuyran% equ 1 (
if %cpumoney% lss %missileprice% goto cpushop
if %cpumoney% geq %missileprice% goto cpubuymissile
)
if %cpubuyran% equ 2 (
if %cpumoney% lss %airstrikeprice% goto cpushop
if %cpumoney% geq %airstrikeprice% goto cpubuyairstrike
)
if %cpubuyran% equ 3 (
if %cpumoney% lss %nukeprice% goto cpushop
if %cpumoney% geq %airstrikeprice% goto cpubuynuke
)
if %cpubuyran% equ 4 (
if %cpumoney% lss %healthprice% goto cpushop
if %cpumoney% geq %healthprice% goto cpubuyhp
goto cpushop

:cpubuymissile
set /a cpumissiles=%cpumissiles%+1
set /a cpumoney=%cpumoney%-20
cls
echo %enemy% bought a Missile!
ping localhost -n 2 >nul
goto play

:cpubuyairstrike
set /a cpuairstrike=%cpuairstrike%+1
set /a cpumoney=%cpumoney%-40
cls
echo %enemy% bought a Airstrike!
ping localhost -n 2 >nul
goto play

:cpubuynuke
set /a cpunuke=%cpunuke%+1
set /a cpumoney=%cpumoney%-80
cls
echo %enemy% bought a Nuke!
ping localhost -n 2 >nul
goto play

:cpubuyhp
set /a cpuhealth=%cpuhealth%+20
set /a cpumoney=%cpumoney%-95
cls
echo %enemy% bought 20 HP!
ping localhost -n 2 >nul
goto play

:win
cls
echo You won World War 3!
ping localhost -n 3 >nul
goto menu
:lose
cls
echo You lost the war!
ping localhost -n 3 >nul
goto menu
:about
cls
echo                       World War 3
echo.
echo Version: 1.0
echo Made by: HackerGamerLV
pause >nul
goto menu
:shop
cls
echo                                   Shop
echo.
echo [Missile] - %missileprice%$
echo [Airstrike] - %airstrikeprice%$
echo [Nuke] - %nukeprice%$
echo [20 HP] - %healthprice%$
echo.
echo [Exit Shop]
for /f "delims=: tokens=1,2" %%A in ('batbox /m') do (
set x=%%A
set y=%%B
)
if %y%==2 (
if %x% geq 1 if %x% leq 9  (
if %money% lss %missileprice% goto shopend
if %money% geq %missileprice% goto shopmissile
)
)
if %y%==3 (
if %x% geq 1 if %x% leq 11  (
if %money% lss %airstrikeprice% goto shopend
if %money% geq %airstrikeprice% goto shopairstrike
)
)
if %y%==4 (
if %x% geq 1 if %x% leq 6  (
if %money% lss %nukeprice% goto shopend
if %money% geq %nukeprice% goto shopnuke
)
)
if %y%==5 (
if %x% geq 1 if %x% leq 9  (
if %money% lss %healthprice% goto shopend
if %money% geq %healthprice% goto shophp
)
)
if %y%==7 (
if %x% geq 1 if %x% leq 11  (
goto play
)
)
goto shop
:shopend
echo You don't have enough money!
ping localhost -n 2 >nul
goto shop

:shopmissile
set /a money=%money%-%missileprice%
set /a missiles=%missiles%+1
echo You bought a Missile!
ping localhost -n 2 >nul
goto cpuplay

:shopairstrike
set /a money=%money%-%airstrikeprice%
set /a airstrike=%airstrike%+1
echo You bought a Airstrike
ping localhost -n 2 >nul
goto cpuplay

:shopnuke
set /a money=%money%-%nukeprice%
set /a nuke=%nuke%+1
echo You bought a Nuke!
ping localhost -n 2 >nul
goto cpuplay

:shophp
set /a money=%money%-%healthprice%
set /a health=%health%+20
echo You bought 20 HP!
ping localhost -n 2 >nul
goto cpuplay

1 个答案:

答案 0 :(得分:0)

似乎没有右括号:

if %cpubuyran% equ 4 (

请妥善缩进代码。