未更新到正确的编号或损坏

问题描述 投票:0回答:1

玩家的首次伤害仅更新一次,然后当我再次攻击强盗时,它会卡在 60 并且不会更新到正确的数字。另外,如果您发现任何其他错误/错误,请随时告诉我,因为我一直坚持这一点。我还想添加更多选择,例如买东西和去其他地方,但我仍然陷入当前的问题

@echo off
    title Choices and Consequences - RPG Game

set "player_hp=100"
set "player_attack=20"
set "player_defense=10"
set "bandits_hp=80"
set "currency=0"

:main_menu
cls
echo Choices and Consequences - RPG Game
echo 1. Start Game
echo 2. Quit
set /p choice=Enter your choice: 

if "%choice%"=="1" (
    call :start_game
) else if "%choice%"=="2" (
    exit
) else (
    echo Invalid choice. Please try again.
    timeout 2 >nul
    goto main_menu
)

:start_game
cls
echo Welcome to the Choices and Consequences RPG Game!
echo You are a brave adventurer on a quest to save the kingdom from evil creatures.
echo.
set /p player_name=Enter your adventurer's name: 

echo.
echo Hello, %player_name%! Your journey begins now.
timeout 3 >nul
call :encounter_1
goto :main_menu

:encounter_1
cls
echo You encounter a group of bandits on the road.
echo What will you do?
echo 1. Fight the bandits
echo 2. Try to negotiate with them
set /p action=Enter your action: 

if "%action%"=="1" (
    call :fight_bandits
) else if "%action%"=="2" (
    call :negotiate_bandits
) else (
    echo Invalid action. Please try again.
    timeout 2 >nul
    goto encounter_1
)

:fight_bandits
cls
echo ------------------------------
echo Your HP: %player_hp%
echo Bandits' HP: %bandits_hp%
echo ------------------------------
echo 1. Attack
echo 2. Defend
set /p action=Enter your action: 

if "%action%"=="1" (
    call :player_attack_bandits
) else if "%action%"=="2" (
    call :player_defend_bandits
) else (
    echo Invalid action. Please try again.
    timeout 2 >nul
    goto fight_bandits
)


:player_attack_bandits
set /a %bandits_hp=80% - %player_attack%
if %bandits_hp% leq 0 (
    echo You have defeated the bandits!
    echo.
    set /a currency+=50
    timeout 2 >nul
    call :encounter_2
)
echo You attacked the bandits! The bandits' HP is now %bandits_hp%.
timeout 2 >nul
call :bandits_attack_player
goto fight_bandits

:bandits_attack_player
set /a player_hp-=(25 + %random% %% 10) - %player_defense%
if %player_hp% leq 0 (
    echo The bandits defeated you! %player_name%, your journey ends here.
    echo.
    pause
    goto :main_menu
)
echo The bandits attacked you! Your HP is now %player_hp%.
timeout 2 >nul
goto fight_bandits

:negotiate_bandits
cls
echo You try to negotiate with the bandits.
echo They demand 50 gold coins as a toll to pass safely.
echo What will you do?
echo 1. Pay the toll
echo 2. Refuse and fight them
set /p action=Enter your action: 

if "%action%"=="1" (
    set /a currency-=50
    call :encounter_2
) else if "%action%"=="2" (
    call :fight_bandits
) else (
    echo Invalid action. Please try again.
    timeout 2 >nul
    goto negotiate_bandits
)

:encounter_2
cls
echo You continue on your journey and reach a crossroads.
echo Which path will you take?
echo 1. Take the dark forest path
echo 2. Follow the river path
set /p action=Enter your action: 

if "%action%"=="1" (
    call :explore_forest
) else if "%action%"=="2" (
    call :follow_river
) else (
    echo Invalid action. Please try again.
    timeout 2 >nul
    goto encounter_2
)

:: Implement more encounters and choices as the game progresses.
:: Each choice should lead to different consequences and affect the story and player's abilities.

:explore_forest
cls
echo You venture into the dark forest.
echo There might be hidden treasures or dangerous creatures lurking in the shadows.
timeout 3 >nul
call :end_game
goto :main_menu

:follow_river
cls
echo You decide to follow the peaceful river path.
echo The journey is calm and uneventful.
timeout 3 >nul
call :end_game
goto :main_menu

:end_game
cls
echo Congratulations, %player_name%! You have completed your journey.
echo Your final stats:
echo HP: %player_hp%
echo Currency: %currency%
echo.
echo Thank you for playing Choices and Consequences - RPG Game.
pause
goto :main_menu
batch-file
1个回答
0
投票

子程序有错误:player_attack_bandits

该子的第一行是:

set /a %bandits_hp=80% - %player_attack%

=80 部分导致语法错误,并且可能只是复制错误。 删除 =80,此设置命令将按您的预期运行。

© www.soinside.com 2019 - 2024. All rights reserved.