Nostalgic code game, Ruby Warrior is good

image.png

Site is here

Ruby Warrior

--A game where you control the hero with the ruby code and clear the level. -Original is a text game that looks like Rogue and is written by ryanb. Published about 10 years ago --It seems that Bloc made the original Web game. ** Good Job! **

rule

--The def play_turn (warrior) ... end part of the code is one turn, and you write the code here. ――Repeat the turn, defeat the enemy and escape --You can only warrior.action! once in one turn (you can't process loops in the turn) [^ 1] --The skill warrior.action! Will increase as the level progresses. --There are beginner mode and intermediate mode (I tried it in beginner mode this time)

[^ 1]: ʻOnly one action can be performed per turn.` Error

Level 1

You see before yourself a long hallway with stairs at the end. There is nothing in the way.

class Player
  def play_turn(warrior)
    # cool code goes here
    warrior.walk!
  end
end

Highlights of this level: Walking happily: walking:

Level 2

It is too dark to see anything, but you smell sludge nearby.

class Player
  def play_turn(warrior)
    if warrior.feel.empty?
      warrior.walk!
    else
      warrior.attack!
    end
  end
end

Highlights of this level: First enemy: dragon_face:

--Get warrior.attack!

Level 3

The air feels thicker than before. There must be a horde of sludge.

class Player
  def play_turn(warrior)
    if warrior.feel.empty?
      if warrior.health < 15
        warrior.rest!
      else
        warrior.walk!
      end
    else
      warrior.attack!
    end
  end
end

Highlights of this level: Rest when you rest: sleeping_accommodation:

--Get warrior.rest!

Level 4

You can hear bow strings being stretched.

class Player
  def play_turn(warrior)
    @health = warrior.health unless @health
    if warrior.feel.empty?
      if @health <= warrior.health && warrior.health < 12
        warrior.rest!
      else
        warrior.walk!
      end
    else
      warrior.attack!
    end
    @health = warrior.health
  end
end

Highlights of this level: Physical condition management: bed:

--Obtained warrior.health

Level 5

You hear cries for help. Captives must need rescuing.

class Player
  def play_turn(warrior)
    @health = warrior.health unless @health
    if warrior.feel.captive?
      warrior.rescue!
    elsif warrior.feel.empty?
      if @health <= warrior.health && warrior.health < 13
        warrior.rest!
      else
        warrior.walk!
      end
    else
      warrior.attack!
    end
    @health = warrior.health
  end
end

Highlights of this level: Enemy or ally? : lock:

--Get warrior.rescue!

Level 6

The wall behind you feels a bit further away in this room. And you hear more cries for help.

class Player
  
  def initialize()
    @captive = true
  end
  
  def play_turn(warrior)
    @health = warrior.health unless @health
    if @captive
      if warrior.feel(:backward).captive?
        warrior.rescue!(:backward)
        @captive = false
      else
        warrior.walk!(:backward)
      end
    else
      if warrior.feel.empty?
        if @health > warrior.health && warrior.health < 10
          warrior.walk!(:backward)
        elsif @health <= warrior.health && warrior.health < 20
          warrior.rest!
        else
          warrior.walk!
        end
      else
        warrior.attack!
      end
      @health = warrior.health
    end
  end
  
end

Highlights of this level: Hits & Away: back:

I tried to flag the presence of captive and change the process, but it didn't work, but I finally wrote it in ʻinitialize ()` and it worked.

Level 7

You feel a wall right in front of you and an opening behind you.

class Player
  def play_turn(warrior)  
    @health = warrior.health unless @health
    if warrior.feel.wall?
      warrior.pivot!
    else
      if warrior.feel.empty?
        if @health > warrior.health && warrior.health < 10
          warrior.walk!(:backward)
        elsif @health <= warrior.health && warrior.health < 20
          warrior.rest!
        else
          warrior.walk!
        end
      else
        warrior.attack!
      end
    end
    @health = warrior.health
  end  
end

Highlights of this level: Turn around and see the scenery someday

--Get warrior.pivot!

Level 8

You hear the mumbling of wizards. Beware of their deadly wands! Good thing you found a bow.

class Player
  
  def initialize()
    @captive = true
  end
  
  def play_turn(warrior)
    @health = warrior.health unless @health
    if @captive
      if warrior.feel.captive?
        warrior.rescue!
        @captive = false
      else
        warrior.walk!
      end
    else
      if warrior.look.any?{|s| s.enemy?}
        warrior.shoot!
      else
        warrior.walk!
      end
    end
  end  
  
end

Highlights of this level: Far Mongachi: bow_and_arrow:

--Get warrior.look andwarrior.shoot! ――The wizard-like thing cuts the life of about 11 with a single blow from a distance, so you will die if you hit two shots ... But the range is unexpectedly short ――I think it was refreshing thanks to ʻany? `

Level 9

Time to hone your skills and apply all of the abilities that you have learned.

class Player

  def initialize()
    @left_captive = true
  end

  def play_turn(warrior)
    if @left_captive
      if warrior.look(:backward).any?{|s| s.enemy?}
        warrior.shoot!(:backward)
      elsif warrior.feel(:backward).captive?
        warrior.rescue!(:backward)
        @left_captive = false
      else
        warrior.walk!(:backward)
      end
    else
      if warrior.look.any?{|s| s.enemy?}
        warrior.shoot!
      elsif warrior.feel.captive?
        warrior.rescue!
      elsif warrior.feel.wall?
        warrior.pivot!
      else
        warrior.walk!
      end
    end
  end
  
end


Highlights of this level: Moonwalk: walking_tone2 :: bow_and_arrow:

――How to win by relying only on the bow! An unarmed guy who shoots an arrow backwards and never warrior.rest!. I'm not using what I've learned. Is it okay to do this?

Become a Ruby Warrior

image.png

Please let me know if you have a better code!

Recommended Posts

Nostalgic code game, Ruby Warrior is good
Writing code Ruby
[Ruby] What is true?