Jeu de code nostalgique, Ruby Warrior est bon

image.png

Le site est ici

Ruby Warrior

règle

[^ 1]: ʻUne seule action peut être effectuée par tour .`

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

Points forts de ce niveau: Marcher avec bonheur: marcher:

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

Points forts de ce niveau: Premier ennemi: dragon_face:

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

Points forts de ce niveau: Reposez-vous quand vous vous reposez: sleep_accommodation:

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

Points forts de ce niveau: Gestion de la condition physique: lit:

--Obtenir 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

Points forts de ce niveau: Ennemi ou allié? : fermer à clé:

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

Points forts de ce niveau: Hits & Away: retour:

J'ai essayé de changer le processus en signalant s'il y avait captive et cela ne fonctionnait pas, mais finalement je l'ai écrit dans ʻinitialize ()` et cela a fonctionné.

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

Points forts de ce niveau: Faites demi-tour et admirez le paysage un jour

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

Points forts de ce niveau: Far Mongachi: bow_and_arrow:

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


Points forts de ce niveau: Moonwalk: walking_tone2 :: bow_and_arrow:

――Comment gagner en ne comptant que sur l'arc! Un tireur qui tire une flèche vers l'arrière et jamais "warrior.rest!". Je n'utilise pas ce que j'ai appris. Est-ce que ça va?

Devenez un guerrier rubis

image.png

Veuillez me faire savoir si vous avez un meilleur code!

Recommended Posts

Jeu de code nostalgique, Ruby Warrior est bon
Code d'écriture Ruby