How do I go back to a specic part of the program?

How do I go back to a specic part of the program?

I would like to keep going back to certain parts of the programs. Do I
need to do something special or is there a command I can use that would
allow me to go anywhere I want?

So far the only command I have in my game is walk.
The enemies so far are rat frog rabbit and snake

Please help me I am stuck and I cant figure out how to move forward
without that.

Here’s a little rewrite, note two things:

  1. The use of the initialize method
  2. The complete lack of variables that simply hold copies of the
    values held in an object

It’s a start

class Creature
attr_reader :name, :attack, :hp

def initialize(name, attack, hp)
@name = name
@attack = attack
@hp = hp

def damage(attack)
@hp -= attack

def alive?
@hp > 0

hero =“Levi”, 10, 100)
frog =“Frog”, 1, 10)
rat =“Rat”, 3, 20)
rabbit =“Rabbit”, 4, 25)
snake =“Snake”, 8, 25)

while hero.alive?
puts “What would you like to do?”
action = gets.chomp

case action
when ‘attack’
puts “Which enemy would you like to get?”
enemy = gets.chomp
my_enemy = nil

case enemy
when "frog"
  my_enemy = frog
when "rat"
  my_enemy = rat
when "rabbit"
  my_enemy = rabbit
when "snake"
  my_enemy = snake

if my_enemy
  if my_enemy.alive?
    if my_enemy.alive?
      puts "You deal the #{} #{hero.attack} points of

damage, it retaliates"
puts “The #{} deals you #{my_enemy.attack}
points of damage”
puts “Splat, the #{} is dead”
puts “He’s dead Jim”
puts “You viciously attack a #{enemy}, which ignores you because
you can’t spell”
when “walk”
puts “You are walking man”
puts “please enter a valid action”

puts “You died”

Oh my gosh thank you! I really appreciate this. I ran it and it seems
like a game now. I will read through this and understand it.

Thank you so much for the help. I am excited to practice now =D.

I love the way battles are played out haha this is great thanks a lot!

EDIT: “Hes dead Jim” thats funny haha