我最近关注了一些教程并学习了如何创建和编写批处理文件。我开始制作一款旨在模拟战斗怪物的游戏。这个游戏的一个机制是成为一个库存,一旦编程,你就可以从商店购买某些商品并将它们放入你已经可以在战斗中访问的库存中。到目前为止,唯一的编程级别是教程,只是它的开始。你应该做的是在被问到时选择一个库存槽,然后计算机应该运行它似乎没有做的库存功能。出现一些错误,然后自动关闭窗口。如果有人能用简单的术语解释为什么这不起作用以及我如何解决它,它真的会帮助我。谢谢:D这是我的代码......
::SETUP
@echo off
title Platformer
color 0a
::Variables
set my_level=0
set money=0
set inventory_slot_1=
set inventory_slot_2=
set inventory_slot_3=
set inventory_slot_4=
set inventory_slot_5=
set current_level=-1
set pin=0
::MONSTER VARIABLES
set monster_level = 0
::MAIN MENU
:main_menu
cls
echo.
echo PPPPP l aaaaa ttttt fffff ooooo rrrr mmmmm eeeee rrrr
echo P P l a a t f o o r r m m m e r r
echo PPPPP l aaaaa t ffff o o rrrr m m m eeee rrrr
echo P l a a t f o o r r m m m e r r
echo P l a a t f ooooo r r m m eeeee r r
echo.
echo 1990 inc.
echo.
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
echo 1 - Play
echo 2 - Save
echo 3 - Load
echo.
set /p input=">>> "
if %input%==1 goto level_select
if %input%==2 goto save
if %input%==3 goto load
pause >nul
::LEVEL SELECT
:level_select
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
echo 1 - Tutorial
echo 2 - Level 1
echo 3 - level 2
echo 4 - level 3
echo 5 - Boss
echo 6 - BACK
echo.
set /p input=">>> "
if %input%==1 goto tutorial
if %input%==2 goto level_select
if %input%==3 goto level_select
if %input%==4 goto level_select
if %input%==5 goto level_select
if %input%==6 goto main_menu
goto main_menu
pause >nul
::INVENTORY
:inventory
if %~1==rock set %damage%=2
if %~1==mercy set mercy_chance=%RANDOM%*%monster_leve%/32768+1
EXIT /b
::TUTORIAL
:tutorial
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
set /a current_level = 0
call:summon_dragon
pause >nul
::Monster -- Dragon
:summon_dragon
set /a monster_level=%current_level%+1
set /a rand=%RANDOM%%%3+1
set /a monster_hp=%monster_level%*3+%rand%
echo A Lvl.%monster_level% Dragon Has Been Summoned
echo What Will You Do?
echo.
echo HP: %monster_hp%
echo.
echo 1 - [ %inventory_slot_1% ]
echo 2 - [ %inventory_slot_2% ]
echo 3 - [ %inventory_slot_3% ]
echo 4 - [ %inventory_slot_4% ]
echo 5 - [ %inventory_slot_5% ]
echo 6 - [ Mercy ]
echo.
set /p input=">>> "
if input==1 callinventory %inventory_slot_1%
if input==2 call:inventory %inventory_slot_2%
if input==3 call:inventory %inventory_slot_3%
if input==4 call:inventory %inventory_slot_4%
if input==5 call:inventory %inventory_slot_5%
if input==6 (
call:inventory mercy
if %mercy_chance%==1 (
set my_level=%my_level%+1
goto win
)
)
set monster_hp=%monster_hp%-%damage%
if monster_hp<=0(
set my_level=%my_level%+1
set current_level=%current_level%+1
goto win
)
EXIT /b
::WIN
:win
cls
echo YOU WIN!
pause >nul
::SAVE
:save
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
set /p pin="Pin: "
echo.
if pin==nul(set /p pin = Change Pin: goto save)
(
echo @echo off
echo set my_level=%my_level%
echo set money=%money%
) >> game_saves\%pin%.cmd
echo SAVED
pause >nul
goto main_menu
::LOAD
:load
cls
echo LVL.%my_level% $%money%
echo ________________________________________________________________________________
echo.
set /p pin="Pin: "
echo.
if pin==nul( pause >Invalid Pin goto load)
call game_saves\%pin%.cmd
echo Loaded
pause >nul
goto main_menu
答案 0 :(得分:1)
if %~1==rock set %damage%=2
可能不正确。如果%~1
为空,则会出现语法错误。
您正在尝试set
damage
的内容变量为2.可能这是不正确的。如果此时未设置damage
,则会cmd
尝试解析set =2
转到开始&gt;程序&gt;附件,并为自己设置Command Prompt
的快捷方式。
单击该按钮将转到cmd
,然后您可以通过使用cd c:\wherever\your\batch\is
更改为相应目录并只运行 nameofyourbatchfile 来导航并运行批处理。< / p>
要退出cmd
,请键入exit
并获取有关命令的帮助,请键入 commandname /?
所有的行动都以 Enter
终止