嗨,最近我受到了一个朋友的挑战,我做了一个空间RPG唯一有问题的是我的战斗系统就像棋盘游戏战舰基本上他是一个1-25之间的随机数,有效,我有一个雷达系统,以避免人们真正击中敌人,这是有效的,但玩家开火不是它只是按下任何键时关闭
:combatalpha
cls
@echo off
echo Fire where
echo 1)1-1
echo 2)1-2
echo 3)1-3
set /a number=%random% %% 25+1
if '%number%' == '20' (
echo its between 15-25 )
if '%number%' == '21' (
echo its between 20-25 )
if '%number%' == '22' (
echo its between 20-25 )
if '%number%' == '23' (
echo its between 20-25 )
if '%number%' == '24' (
echo its between 20-25 )
if '%number%' == '25' (
echo its between 20-25 )
if '%number%' == '15' (
echo its between 10-20 )
if '%number%' == '16' (
echo its between 15-20 )
if '%number%' == '17' (
echo its between 15-20 )
if '%number%' == '18' (
echo its between 15-20 )
if '%number%' == '19' (
echo its between 15-20 )
if '%number%' == '10' (
echo its between 5-15 )
if '%number%' == '11' (
echo its between 10-15 )
if '%number%' == '12' (
echo its between 10-15 )
if '%number%' == '13' (
echo its between 10-15 )
if '%number%' == '14' (
echo its between 10-15 )
if '%number%' == '5' (
echo its between 0-10 )
if '%number%' == '6' (
echo its between 5-10 )
if '%number%' == '7' (
echo its between 5-10 )
if '%number%' == '8' (
echo its between 5-10 )
if '%number%' == '9' (
echo its between 5-10 )
if '%number%' == '1' (
echo its between 1-5 )
if '%number%' == '2' (
echo its between 1-5 )
if '%number%' == '3' (
echo its between 1-5 )
if '%number%' == '4' (
echo its between 1-5 )
echo %number%
set /p pshot=
if '%pshot%' == '1' %AND% (
if '%number%' == '1' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '2' %AND% (
if '%number%' == '2' (
echo HIT!)
pause
goto combatalpha )
if '%pshot%' == '3' %AND% (
if '%number%' == '3' (
echo HIT!
pause
goto combatalpha)
if '%pshot%' == '4' %AND% (
if '%number%' == '4' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '5' %AND% (
if '%number%' == '5' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '6' %AND% (
if '%number%' == '6' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '7' %AND% (
if '%number%' == '7' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '8' %AND% (
if '%number%' == '8' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '9' %AND% (
if '%number%' == '9' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '10' %AND% (
if '%number%' == '10' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '11' %AND% (
if '%number%' == '11' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '12' %AND% (
if '%number%' == '12' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '13' %AND% (
if '%number%' == '13' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '14' %AND% (
if '%number%' == '14' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '15' %AND% (
if '%number%' == '15' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '16' %AND% (
if '%number%' == '16' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '17' %AND% (
if '%number%' == '17' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '18' %AND% (
if '%number%' == '18' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '19' %AND% (
if '%number%' == '19' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '20' %AND% (
if '%number%' == '20' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '21' %AND% (
if '%number%' == '21' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '23' %AND% (
if '%number%' == '23' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '24' %AND% (
if '%number%' == '24' (
echo HIT!
pause
goto combatalpha) )
if '%pshot%' == '25' %AND% (
if '%number%' == '25' (
echo HIT!
pause
goto combatalpha) )
pause
echo MISS!
pause
goto start
答案 0 :(得分:1)
如果玩家未命中goto start
,则进程结束的主要原因。标签:start
未定义。
只是简化你的代码(对不起,它真的是多余的,幸运的是,范围是1-25)。不确定这正是您编码的内容,但可以作为起点
@echo off
setlocal enableextensions disabledelayedexpansion
set "rounds=1"
set "hits=0"
:combatalpha
set /a "number=%random% %% 25+1"
set /a "lowLimit=number / 5 * 5"
if %lowLimit% equ 25 set "lowLimit=20"
set /a "highLimit=lowLimit + 5"
if %lowLimit% equ 0 set "lowLimit=1"
:ask
cls
echo round %rounds% hits %hits%
echo(
echo it is between %lowLimit%-%highLimit% (it is %number%)
echo(
set "pshot="
set /p "pshot=Your shot? " || goto :ask
if "%pshot%"=="%number%" (
echo HIT!
set /a "hits+=1"
) else (
echo MISS!
)
set /a "rounds+=1"
pause
goto :combatalpha
计算出射击范围限制。上限只是低+ 5,下限是使用以下事实计算的:在批处理文件中算术运算只处理整数,因此,n/5*5
会将数字四舍五入到五的较低倍数(以模拟范围) )。其余的只是绘制界面,询问玩家以及镜头是否与位置匹配,增加点击计数器。在任何情况下,增加轮数并再次进行战斗。