0
- The program asks for a monster. If you type in @Dragon@, then the @monster_class@ variable
0
- will contain the string @"Dragon"@. Inside the @eval@, a few strings get added together
0
- to make the string @"monster = Dragon.new"@. And when the @eval@ executes this string,
0
- the @monster@ variable contains a @Dragon@ object. Ready for battle.
0
+ O programa pede por um monstro. Se você digitar @Dragao@, então a variável da @classe_monstro@
0
+ irá conter a string @"Dragao"@. Dentro do @eval@ algumas strings serão adicionadas juntas
0
+ para formar a string @"monstro = Dragao.new"@. E quando o @eval@ executa essa string, a
0
+ variável @monstro@ contém um objeto @Dragao@. Pronto pra batalha.
0
- This is great! Now we can leave it up to the player to pick a monster! Of course,
0
- we're trusting the player to supply a real monster class. If they type in @BotanicalWitch@
0
- and there is no @BotanicalWitch@ class, they'll get an exception tossed in their face.
0
+ Isso é maravilhoso! Agora podemos deixar que o jogador escolha um monstro! Claro, estamos
0
+ confiando no jogador para que ele forneça uma classe real de monstro. Se eles digitarem
0
+ @BruxaBotanica@ e não existe a classe @BruxaBotanica@, eles terão uma exceção jogada na sua cara.
0
- So, in short, @eval@ lets you make up code as you go. Which can be useful and which can
0
+ Então, em resumo, o @eval@ permite que você crie um código a medida que prossegue. O que
0
+ pode ser útil e pode ser perigoso ao mesmo tempo.
0
- The @instance_eval@ and @class_eval@ method used in the metaprogramming for the @Creature@
0
- class are slightly different from the normal @eval@. These two special methods run code just like
0
- @eval@ does, but they duck into classes and objects and run the code there.
0
+ Os métodos @instance_eval@ e @class_eval usado na metaprogramação para a classe @Criatura@
0
+ são levemente diferente do normal @eval@. Esses dois métodos especiais passam o código assim
0
+ como o @eval@ faz, mas eles mergulham em classes e objetos e passam o código lá.
0
- # The instance_eval method runs code as if it were run inside an
0
- # object's instance method.
0
- irb> drgn = Dragon.new
0
+ # O método instance_eval executa o código como se ele fosse executado dentro
0
+ # do objeto do método de instância.
0
+ irb> drgn = Dragao.new
0
irb> drgn.instance_eval do
0
- irb> drgn.instance_variable_get( "@n
ame" )
0
+ irb> drgn.instance_variable_get( "@n
ome" )
0
- # The class_eval method runs code is if inside a class definition.
0
- irb> Dragon.class_eval do
0
- irb> def name; @name; end
0
+ # O método class_eval executa o código se estiver dentro da definição de classe.
0
+ irb> Dragao.class_eval do
0
+ irb> def nome; @nome; end
0
- As you can see above, the @instance_eval@ and @class_eval@ methods also can take a code block
0
- instead of a string. Which is just how things are done in Dwemthy's Array.
0
+ Como você pode ver acima, os métodos @instance_eval@ e @class_eval@ também podem pegar um bloco
0
+ de código ao invés de uma string. O que é exatamente como as coisas foram feitas no Labirinto de Dwemthy.
0
- h3.
Enough Belittling Instruction and Sly Juxtaposition -- Where Is Dwemthy's Array??
0
+ h3.
Bastante instrução depreciante e Ardilosa Justaposição -- Onde está o Labirinto de Dwemthy??
0
- Tread carefully -- here is *the other half of DWEMTHY'S ARRAY!!*
0
- *Add these lines to @dwemthy.rb@.*
0
+ Vá com cuidado -- aqui está *a outra metade do LABIRINTO DE DWEMTHY!!*
0
+ *Adicione essas linhas a @dwemthy.rb@.*
0
- # This method applies a hit taken during a fight.
0
- p_up = rand( charisma )
0
- puts "[#{ self.class } magick powers up #{ p_up }!]"
0
+ # Este método aplica um golpe recebido durante uma luta.
0
+ aumento_poder = rand( carisma )
0
+ if aumento_poder % 9 == 7
0
+ @vida += aumento_poder / 4
0
+ puts "[Aumento de poderes mágicos de #{ self.class } #{ aumento_poder }!]"
0
- puts "[#{ self.class } has died.]" if @life <= 0
0
+ puts "[#{ self.class } está morto.]" if @vida <= 0
0
- # This method takes one turn in a fight.
0
- def fight( enemy, weapon )
0
- puts "[#{ self.class } is too dead to fight!]"
0
+ # Este método obtém uma rodada em uma luta.
0
+ def lutar( inimigo, arma )
0
+ puts "[#{ self.class } está muito morto para lutar!]"
0
- your_hit = rand( strength + weapon )
0
- puts "[You hit with #{ your_hit } points of damage!]"
0
- enemy_hit = rand( enemy.strength + enemy.weapon )
0
- puts "[Your enemy hit with #{ enemy_hit } points of damage!]"
0
+ seu_golpe = rand( forca + arma )
0
+ puts "[Seu golpe com #{ seu_golpe } pontos de dano!]"
0
+ inimigo.golpear( seu_golpe )
0
+ inimigo_golpe = rand( inimigo.forca + inimigo.arma )
0
+ puts "[Seu inimigo golpeia com #{ inimigo_golpe } pontos de dano!]"
0
+ self.golpear( inimigo_golpe )
0
- class
DwemthysArray < Array
0
+ class
LabirintoDwemthy < Array
0
def inspect; "#<#{ self.class }#{ _inspect }>"; end
0
def method_missing( meth, *args )
0
- answer = first.send( meth, *args )
0
+ resposta = first.send( meth, *args )
0
- puts "[
Whoa. You decimated Dwemthy's Array!]"
0
+ puts "[
Uauu. Você dizimou o Labirinto de Dwemthy!]"
0
- puts "[
Get ready. #{ first.class } has emerged.]"
0
+ puts "[
Prepare-se. #{ first.class } surgiu.]"
0
- This code adds two methods to @Creature@. The @hit@ method which reacts to a hit from another
0
- @Creature@. And the @fight@ method which lets you place your own blows against that @Creature@.
0
+ Esse código adiciona dois métodos a @Criatura@. O método @golpear@ que reage ao golpe de outra
0
+ @Criatura@. E o método @lutar@ que permite que você coloque os seus próprios golpes contra aquela @Criatura@.
0
- When your @Creature@ takes a hit, a bit of defense kicks in and your @charisma@ value is used to generate a power-up. Don't
0
- ask me to explain the secrets behind this phenomenon. A random number is picked, some simple math
0
- is done, and, if you're lucky, you get a couple life points. @@life += p_up / 4@.
0
+ Quando a sua @Criatura@ leva um golpe, um pouco da defesa contribui e o seu valor @carisma@ é usado para gerar um aumento de
0
+ poder. Não me peça para explicar os segredos por trás deste fenômeno. Um número aleatório é escolhido, uma matemática
0
+ simples é feita e se você tiver sorte, você consegue alguns pontos vitais. @@vida += aumento_poder / 4@.
0
-
Then, the enemy's blow is landed. @@life -= damage@. That's how the @Creature#hit@ method works.
0
+
Então o golpe do inimigo está dado. @@vida -= dano@. É assim que o método da @Criatura#golpear@ trabalha.
0
- The @fight@ method checks to see if your @Creature@ is alive. Next, a random
0
- hit is placed on your opponent. If your opponent lives through the hit, it gets
0
- a chance to strike back. Those are the workings of the @Creature#fight@ method.
0
+ O método @lutar@ checa se a sua @Criatura@ está viva. Em seguida, um golpe aleatório
0
+ é dado no seu oponente. Se o seu oponente sobreviver a este golpe, ele ganha uma
0
+ chance de atacar de volta. Estas são as atividades do método @Criatura#lutar@.
0
- I'll explain @DwemthysArray@ in a second. I really will. I'm having fun doing it.
0
- Let's stick with hitting and fighting for now.
0
+ Irei explicar o @LabirintoDwemthy@ em um segundo. Realmente explicarei. Estou me divertindo fazendo isso.
0
+ Por hora, vamos nos concentrar em golpear e lutar.
0
+ h3.
Apresentando: Você.
0
- You may certainly tinker with derivations on this rabbit. But official
0
- Dwemthy Paradigms explicitly denote the code -- and the altogether character -- inscribed
0
- below. *Save this as @rabbit.rb@.*
0
+ Você talvez tenha trabalhado com derivações neste coelho. Mas o oficial
0
+ Paradigma de Dwemthy explicitamente denota o código -– e os caracteres todos juntos -–
0
+ inscritos abaixo. *Salve isto como @rabbit.rb@.*
0
- class Rabbit < Creature
0
+ class Coelho < Criatura
0
+ caracteristicas :bombas
0
- # the hero's sword is unlimited!!
0
- fight( enemy, rand( 4 + ( ( enemy.life % 10 ) ** 2 ) ) )
0
+ # a espada do herói é ilimitada!!
0
+ lutar( inimigo, rand( 4 + ( ( inimigo.vida % 10 ) ** 2 ) ) )
0
- # lettuce will build your strength and extra ruffage
0
- # will fly in the face of your opponent!!
0
- lettuce = rand( charisma )
0
- puts "[Healthy lettuce gives you #{ lettuce } life points!!]"
0
+ # alface irá formar a sua força e extras substâncias indigestas
0
+ # voarão na cara de seu oponente!!
0
+ alface = rand( carisma )
0
+ puts "[Saudável alface lhe dá #{ alface } pontos de vida!!]"
0
- # bombs, but you only have three!!
0
- puts "[UHN!! You're out of bombs!!]"
0
+ # bombas, mas você possui somente três!!
0
+ puts "[HUMM!! Você está sem bombas!!]"
Comments
No one has commented yet.