-2
我正在製作一個批處理遊戲,我正在嘗試將一個名爲finalrealm的批處理遊戲保存到我的系統中。他的比賽比我的比賽更開放,所以我不得不改變內容。我的保存系統的工作原理是,當你到達遊戲的某個部分時,它會將遊戲中的「位置」設置爲一個變量,將遊戲中的所有變量保存爲一個.bat文件,然後使用該位置變量,回到遊戲中的位置。但是,出現了問題,然後它會將您帶入登錄代碼。然後,如果我嘗試登錄,則會失敗。如何在批處理中保存?
下面是代碼:
@echo off
cls
Title RPG BUILD 0.4 (MAJOR UPDATE:Saving Progress +)
color 07
cls
:FirstMENU
cls
echo What would you like to do?
echo.
echo 1) Open Save File
echo 2) New Game
echo.
echo.
echo Current Version: RPG BUILD 0.4
echo (Saving Function Based on "FinalRealm" by Brian)
set /p login=
if %login% GEQ 3 goto FirstMENU
if %login% EQU 1 goto login
if %login% EQU 2 goto createuser
goto Login
:createuser
echo.
echo What would you like your Username to be?
set /p username1=
set v1f=0
goto checkforspaces
:checkforspaces
set x=!v1f!
set Letter%v1f%=!username1:~%x%,1!
if "!Letter%v1f%!" EQU " " (
echo.
echo.
echo Sorry you cant use spaces in your Username.
pause>nul
goto FirstMenu
)
echo.
echo What would you like your Password to be?
set /p password1=
goto Begin
:SAVE_GAME_FILES
(
echo set username1=%username1%
echo set password1=%password1%
:DATA_VALUES
set Hair=%Hair%
set Face=%Face%
set E=%E%
set /a Power=%Power%
set /a Hp=%Hp%
set rival=%rival%
set /a rivalhp=%rivalhp%
set L=%L%
)>%username1%.bat
if L EQU 1 goto Menu
if L EQU 2 goto folo
if L EQU 3 goto rolo
if L EQU 4 goto levelup1
if L EQU 5 goto 23
:login
cls
set /p name1=Username:
if not exist "%name1%.bat" (
echo That is not a valid Username.
pause>nul
goto FirstMenu
)
set /p pass1=Password:
call %name1%.bat
if not %password1% EQU %pass1% (
echo That is not a valid Password.
pause>nul
goto FirstMenu
)
goto SAVE_GAME_FILES
:Begin
echo Hello %username1%!
pause >nul
cls
echo Begin your journey by making a character!
pause >nul
:CM
cls
echo Loading Character Maker
pause >nul
cls
:Hair
echo 1. Bald
echo 2. Wavy Hair ~~~
echo 3. Curled Up Hair ,,,
set /p answer=Type the number of your option and press enter.
if %answer%==1 goto lel
if %answer%==2 goto 2
if %answer%==3 goto 3
:lel
cls
set Hair=___
goto A
:2
cls
set Hair=~~~
goto A
:3
cls
set Hair=,,,
goto A
:A
echo 1. ('-') Face
echo 2. (.3.) Face
echo 3. (._.) Face
set /p answer=Type the number of your option and press enter.
if %answer%==1 goto 5
if %answer%==2 goto 6
if %answer%==3 goto 7
:5
cls
set Face=('-')
goto B
:6
cls
set Face=(.3.)
goto B
:7
cls
set Face=(._.)
goto B
:B
echo 1. (-) Energy
echo 2. (*) Energy
echo 3. (+) Energy
set /p answer=Type the number of your option and press enter.
if %answer%==1 goto 8
if %answer%==2 goto 9
if %answer%==3 goto 0
:0
cls
set E=+
goto C
:9
cls
set E=*
goto C
:8
cls
set E=-
goto C
:C
echo %Hair%
echo %Face%
echo /!\ %E%
echo /"\
echo This is your character
set /p answer=Would you like to redo you character? (Yes/No)
if %answer%==Yes goto CM
if %answer%==No goto MenuPre
:MenuPre
set L=1
goto SAVE_GAME_FILES
:Menu
cls
echo MENU
echo 1. Start
echo 2. Exit
set /p answer=Type the number of your option and press enter.
if %answer%==1 goto Start
if %answer%==2 goto Exit
:Exit
exit
:Start
cls
echo Let us begin by getting you an item!
pause >nul
cls
set L=2
goto SAVE_GAME_FILES
:folo
cls
color 0A
echo \---------------------------------------------------\
echo \ Item Shop (Route 1) \
echo \---------------------------------------------------\
pause >nul
cls
echo Oh hey! A promotion! "All new customers get a free sword!"
pause >nul
cls
echo *Randomizing Sword's Power*
pause >nul
:Random
cls
set /a Power=%random%
if %random% GTR 1000 goto Random
set /a Power=%Power%/2400 + 1
echo Wow! This sword's power stat is %Power% (10 and below is common,
echo 11 and above is uncommon)
pause >nul
cls
echo %username1% recieved "Sword"
pause >nul
set L=3
goto SAVE_GAME_FILES
:rolo
cls
color 03
echo ???????: Hey, %username1%! I am going to wreck you!!!!
pause >nul
cls
echo ??????: I am your rival!!!
pause >nul
cls
set /p rival=What is your rival's name?
cls
set /a rivalhp=50
set /a hp=50
cls
color 0F
echo %rival%'s HP:%rivalhp% %username1%'s Hp:%hp%
pause >nul
:BattleMain
cls
echo %rival%'s HP:%rivalhp% %username1%'s Hp:%hp%
echo What move will you use?
echo 1.Slash
set /p answer=
if %answer%==1 goto SwegslashRandom
:SwegslashRandom
cls
set /a num=%random%
if %num% gtr 100 goto SwegslashRandom
if %num% lss 1 goto SwegslahsRandom
if %num% gtr 75 (goto Critical)
if %num%==75 (goto OK)
if %num% lss 75 (goto OK)
:Critical
set /a rivalhp= %rivalhp%-(%Power% + 5)
cls
echo %rival% used Punch!
pause >nul
cls
echo Your HP went down by 8!
pause >nul
cls
echo You used Slash
pause >nul
cls
echo Critical hit! %rival%'s HP went down by %power% + 5 for critical hit bonus!
pause
set /a hp=%hp%-8
if %rivalhp%==0 goto Win
if %rivalhp% lss 0 goto Win
if %rivalhp% gtr 0 goto BattleMain
:OK
set /a rivalhp= %rivalhp%-%power%
cls
echo %rival% used Punch!
pause >nul
cls
echo Your HP went down by 10!
pause >nul
if %hp%==0 goto LOZER
if %hp% lss 0 goto LOZER
cls
echo You used Slash
pause >nul
cls
echo %rival%'s HP went down by %power%!
pause >nul
set /a hp =%hp%-10
if %rivalhp%==0 goto Win
if %rivalhp% lss 0 goto Win
if %rivalhp% gtr 0 goto BattleMain
:Win
cls
color 0E
echo %rival%: Ugh, you're too powerful...
pause >nul
cls
echo %rival% ran away
pause >nul
goto levelup1
:LOZER
cls
color 47
echo %rival%:HA, what a weak foe!
pause >nul
echo *Redoing Battle*
pause >nul
goto rolo
set L=4
goto SAVE_GAME_FILES
:levelup1
cls
echo %username1% Leveled up to, Level 2!
set /a level=2
pause >nul
cls
set /a hp=(%hp%*8)+50
set /a power=%power%+((%random%/1000)+1)
echo Wow! Your sword's power is now %power%, and your HP is now %hp%
pause >nul
:PRE23
set L=5
goto SAVE_GAME_FILES
:23
cls
echo Oh hey, %rival% dropped a map!
pause >nul
cls
echo [] Destiny Cave
echo Route 3 !
echo ________ !
echo / \ !
echo [] City A \ Route 4 ! Route X
echo / \ !
echo /Route 2 ! Route 5 !
echo Route 1 / []_____!____________[]
echo _________/ Gang Hideout City B
pause >nul
cls
echo %username1% obtained "Map"
pause >nul
cls
echo Let's continue onto Route 2!
pause >nul
cls
echo \---------------------------------------------------\
echo \ Route 2 \
echo \---------------------------------------------------\
pause >nul
cls
echo While we go down Route 2, let me explain "energy"
pause >nul
cls
echo It seems you have, %E% type energy.
pause >nul
cls
echo During a battle, you can use energy attacks.
pause >nul
cls
echo Energy Attacks are sort of a gamble, they can be really good or really bad
echo but they get stronger the lower the hp you have, so use them to finish the battle
pause >nul
cls
echo [] Destiny Cave
echo Route 3 !
echo ________ !
echo / \ !
echo You ---> [] City A \ Route 4 ! Route X
echo / \ !
echo /Route 2 ! Route 5 !
echo Route 1 / []_____!____________[]
echo _________/ Gang Hideout City B
pause >nul
echo Hey! We are now in City A!
pause >nul
cls
echo that is the end of Build
pause >nul
exit
幫助,將不勝感激!謝謝!
乍一看,您在字符變量中使用括號。由於圓括號是塊打開和關閉字符,因此任何變量的關閉字符都可能會影響塊邏輯。因此,如果要使用它,則必須將右括號**轉義或用引號括起來。逃跑** ^)** – elzooilogico