2
I wish it were always displayed Vida: 0
in the last block, even if the value is negative, without doing that "Gambiarra" that I did just below.
Is there any function around vidaInimigo
, without the need to create an additional condition: Se(vidaInimigo <= 0) entao EscrevaL("Vida: 0")
?
Because the enemy had 4
of Life, received 39
and was left with -35
of life.
I wanted life to be shown equal to 0
, and not -35
.
I imagine there’s some function that goes up.
Follow the code of the algorithm:
algoritmo "RPG"
var
danoCausado, vidaInimigo, baseDanoPlayer: Inteiro
inicio
baseDanoPlayer <- 50
vidaInimigo <- 100
EscrevaL("Vida: ", vidaInimigo)
Repita
danoCausado <- randi(baseDanoPlayer)
vidaInimigo <- vidaInimigo - danoCausado
EscrevaL(" >>> Dano causado: ", danoCausado)
Se(vidaInimigo <= 0) entao
EscrevaL("Vida: 0")
senao
EscrevaL("Vida: ", vidaInimigo)
FimSe
Ate(vidaInimigo <= 0)
Se (vidaInimigo <= 0) entao
EscrevaL("Inimigo abatido!")
FimSe
fimalgoritmo
This is not the question, but I did not have time to comment on what you deleted: https://en.wikipedia.org/wiki/Printf_format_string - it is not specific to Java, but it may help
– Bacco
This is more specific http://www.javawithus.com/tutorial/displaying-text-using-printf-method
– Bacco
And the link has been updated to double without decimal, applying the links above: https://ideone.com/irUPu3
– Bacco