首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >批量游戏中的健康条

批量游戏中的健康条
EN

Stack Overflow用户
提问于 2014-03-08 03:12:40
回答 2查看 871关注 0票数 1

我有一个批量游戏,我需要为一个角色做一个健康栏。我有以下变量:Max_HealthCurrent_HealthHealth_Percent

我想要一种使用Health_Percent变量来创建像这样的健康栏的方法。

如果该字符具有:Max_Health = 500 Current_Health = 500,那么Health_Percent= 100,因此该条如下所示:

健康: 100% =====.=====.=====.=====.=====

如果字符有:Max_Health = 500 Current_Health = 250,那么Health_Percent= 50,那么条形图如下所示:

健康: 50% =====.=====.===

其中,每个'='表示健康的4%,而健康栏每20%用'.'分隔一次。

但是,如果'.'使事情变得太困难,您可以省略它。

提前谢谢你。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-03-08 04:26:04

让我的孩子意识到,亚西尼已经打败了我。但是,这段代码可能要好得多,因为它检查错误,而且更可定制(以及他的代码包括.作为条形图的一部分)。此外,对于我的,您需要计算百分比,然后调用它。这是很久以前使用的,当时我认为批处理适合游戏开发(很久以前)。

这是我的密码:

Health.bat

代码语言:javascript
复制
@echo off
setlocal enabledelayedexpansion
set test=%~1
set /a health=%~1
set print=%~2

:: Remember to check if errorlevel is 1 after calling script
:: If not check which error occured based of its value.

if "%health%" EQU "" (
Echo Error: No Health Inputed!
Exit /b 2
)
if "%health%" NEQ "%test%" (
Echo Error: Please Input an integer!
Exit /b 3
)
if %health% GTR 100 (
Echo Error: Please Input a number within 0-100!
Exit /b 4 
)
if %health% LSS 0 (
Echo Error: Please Input a number within 0-100!
Exit /b 5
)
if "%print%" EQu "" (
set print=#
)
if exist tmp.e del tmp.e
<nul set /p=%print% 1>nul 2>tmp.e
set /p wrong=<tmp.e
del tmp.e
if "%worng%" NEQ "" set print=#


<nul set /p"=Health: %health%%%  "
set /a repeat=health/20
set /a remain=health%%20
for /l %%a in (1, 1, %repeat%) do (
<nul set /p=%print%%print%%print%%print%%print%
if %%a LSS !repeat! (
<nul set /p=-
)
)
if %remain% EQU 0 Goto :END

<nul set /p=-
set /a repeat=remain/4
set /a round=remain%%4
for /l %%a in (1, 1, %repeat%) do (
<nul set /p=%print%
)

if %round% GTR 0 (
<nul set /p=%print%
)

:END
Echo.
endlocal
exit /b 1

简单地使用:

代码语言:javascript
复制
C:\> Health.bat 43
Health: 43% #####-#####-#

C:\> Health.bat 50 $
Health: 50% $$$$$-$$$$$-$$$

C:\> REM ^B is avhieved by Keystroke of "Ctrl+B"
C:\> Health.bat 67 ^B
Health: 67% ☻☻☻☻☻-☻☻☻☻☻-☻☻☻☻☻-☻☻

C:\> REM Normally if you tried to use an "&" it would cause lots of errors
C:\> Rem However I have speacial code to check for that.
C:\> Health.bat 6 &
Health: 6% ##

C:\> Rem and the best thing is now you can have multichar hp blocks
C:\>Health.bat 26 ^V^U^V
Health: 26%  ▬§▬▬§▬▬§▬▬§▬▬§▬-▬§▬▬§▬

它会做你想做的。

基本参数如下:

代码语言:javascript
复制
 Health [Health Percent]
 Health [Health Percent] [HP Block]

注意,我将默认的健康栏更改为#####-#####-##,因为它看起来比-----.--好多了。

Mona

票数 1
EN

Stack Overflow用户

发布于 2014-03-08 04:23:06

代码语言:javascript
复制
@echo off
setlocal EnableDelayedExpansion

rem For this example, take Max_Health and Current_Health from parameters
set /A Max_Health=%1, Current_Health=%2

set "bar======.=====.=====.=====.====="
set /A Health_Percent=Current_Health*100/Max_Health, barLen=Health_Percent*29/100

echo Max_Health=%Max_Health%, Current_Health=%Current_Health%, Health_Percent=%Health_Percent%
echo/
echo Health: %Health_Percent%%% !bar:~0,%barLen%!

输出示例:

代码语言:javascript
复制
C:\> test 500 500
Max_Health=500, Current_Health=500, Health_Percent=100

Health: 100% =====.=====.=====.=====.=====

C:\> test 500 250
Max_Health=500, Current_Health=250, Health_Percent=50

Health: 50% =====.=====.==
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22264523

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档