我正在开发批量游戏,我在测试过程中遇到了错误。我最好向您展示代码:
:move
set /a chance=%RANDOM% % 4 + 1
if %chance% == 1 goto randomitem
if %chance% == 2 goto randommonster
if %chance% == 3 goto safe
if %chance% == 4 goto trap
:randomitem
cls
echo You found an item!
echo Sorry! The items mechanism hasn't been added yet!
goto main
:randommonster
cls
echo A random monster attacks you!
echo Sorry! The monsters mechanism hasn't been added yet!
goto main
:safe
cls
echo You enter another dark room with 4 corridors.
goto main
:trap
cls
echo You fall into a trap!
echo Sorry! The traps mechanism hasn't been added yet!
goto main
出于某种原因,它不是有机会完成所有4条路径,而是只做随机项目。我不知道如何解决这个问题,请帮助我!
谢谢!
答案 0 :(得分:2)
您需要将用作mod运算符的%
加倍。
set /a chance=%RANDOM% %% 4 + 1