i need help making my ruby while loop more accurate and easier to read [closed]

Posted on

Problem

  while enemy.health > 0 && player.health > 0
    enemy.health = enemy.health - player.damage
    player.health = player.health - enemy.damage
    puts "#{enemy.name}'s health = #{enemy.health} your health = #{player.health}"
    sleep(0.5)
  end

This is my ruby while loop for my game i am making and i need help making it easier to read and more accurateany suggestions?

Solution

You can use the shorthand operator -= so you don’t have to type the same thing twice.

enemy.health -= player.damage

player.health -= enemy.damage

Leave a Reply

Your email address will not be published. Required fields are marked *