" Goto此时出人意料"

时间:2015-06-23 11:04:13

标签: batch-file

我正在批量制作战争策略游戏。这个想法是你选择你的国家,并攻击其他随机选择的国家。有3种武器:核弹,空袭和导弹。当我选择武器时,有时会显示" goto此时出乎意料"并退出。我不知道该怎么做。它使用外部命令" batbox.exe"

@echo off
mode con: cols=80 lines=26
color a
title WW3
: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 cpumissiles=3
set cpuairstrike=2
set cpunuke=1
set cpuhealth=1000
:play
cls
echo %country%                                                                   %enemy%
echo HP: %health%                                                              HP: %cpuhealth%
echo.
echo [Nuke x %nuke%]                                                          [Nuke x %cpunuke%]
echo [Airstrike x %airstrike%]                                                [Airstrike x %cpuairstrike%]
echo [Missiles x %missiles%]                                                  [Missiles x %cpumissiles%]
for /f "delims=: tokens=1,2" %%A in ('batbox /m') do (
set x=%%A
set y=%%B
)
if %y%==3 (
if %x% geq 1 if %x% leq 9  (
goto nuke
)
)
if %y%==4 (
if %x% geq 1 if %x% leq 14  (
goto airstrike
)
)
if %y%==5 (
if %x% geq 1 if %x% leq 13  (
goto missiles
)
)
goto play
:nuke
if %nuke%==0 (
echo You are out of Nukes!
ping localhost -n 2 >nul
goto play
)
cls
echo %country% shot a Nuke on %enemy%!
echo.
set /a hit=%random% %%2 + 1
if %hit%==1 (
echo Miss!
)
if %hit%==2 (
echo Hit!
echo.
echo %enemy% lost 400 HP!
set /a cpuhealth=%cpuhealth%-400
set /a nuke=%nuke%-1
)
ping localhost -n 3 >nul
goto cpuplay
:airstrike
if %airstrike%==0 (
echo You are out of Airstrikes!
ping localhost -n 2 >nul
goto play
)
cls
echo %country% shot a Airstrike on %enemy%!
echo.
set /a hit=%random% %%2 + 1
if %hit%==1 (
echo Miss!
)
if %hit%==2 (
echo Hit!
echo.
echo %enemy% lost 400 HP!
set /a cpuhealth=%cpuhealth%-200
set /a airstrike=%airstrike%-1
)
ping localhost -n 3 >nul
goto cpuplay
:missiles
if %missiles%==0 (
echo You are out of Missiles!
ping localhost -n 2 >nul
goto play
)
cls
echo %country% shot a Missile on %enemy%!
echo.
set /a hit=%random% %%2 + 1
if %hit%==1 echo Miss!
if %hit%==2 (
echo Hit!
echo.
echo %enemy% lost 100 HP!
set /a cpuhealth=%cpuhealth%-100
set /a airstrike=%airstrike%-1
ping localhost -n 3 >nul
)
ping localhost -n 3 >nul
goto cpuplay
:cpuplay
set /a cpuweapon=%random% %%3 + 1
if %cpuweapon% equ 1 goto cpunuke
if %cpuweapon% equ 2 goto cpuairstrike
if %cpuweapon% equ 3 goto cpumissile
goto cpuplay
:cpunuke
if %cpunuke% equ 0 goto cpuplay
cls
echo %enemy% shot a Nuke on %country%!
echo.
set /a cpuhit=%random% %%2 + 1
if %cpuhit%==1 (
echo Miss!
ping localhost -n 3 >nul
)
if %cpuhit%==2 (
echo Hit!
echo.
echo %country% lost 400 HP!
set /a health=%health%-400
set /a cpunuke=%cpunuke%-1
ping localhost -n 3 >nul
)
goto play
:cpuairstrike
if %cpuairstrike% equ 0 goto cpuplay
cls
echo %enemy% shot a Airstrike on %country%!
echo.
set /a cpuhit=%random% %%2 + 1
if %cpuhit%==1 (
echo Miss!
ping localhost -n 3 >nul
)
if %cpuhit%==2 (
echo Hit!
echo.
echo %country% lost 200 HP!
set /a health=%health%-200
set /a cpunuke=%cpunuke%-1
ping localhost -n 3 >nul
)
goto play
:cpumissile
if %cpumissile% equ 0 goto cpuplay
cls
echo %enemy% shot a Missile on %country%!
echo.
set /a cpuhit=%random% %%2 + 1
if %cpuhit%==1 (
echo Miss!
ping localhost -n 3 >nul
)
if %cpuhit%==2 (
echo Hit!
echo.
echo %country% lost 100 HP!
set /a health=%health%-100
set /a cpunuke=%cpunuke%-1
ping localhost -n 3 >nul
)
goto play

0 个答案:

没有答案