分享 ruby 教学游戏 RubyWarror,有没有人玩过?

tony612 · July 28, 2013 · Last by u1376069219 replied at August 10, 2013 · 4520 hits

今天上午在微博看到,还没玩

#2 楼 @Tony612 嗯,Gravatar 这个网站有点难上

玩过了,挺有意思的

玩过了。有时间的话,可以玩玩。

关卡太少啦

玩这个游戏入门 ruby 的 当年 Highscore 还有第二名 现在记录已经被刷下好多..

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

第四关的,貌似有问题 求修正!

#9 楼 @karmue 没有问题,是可以打过去的。@health = warrior.health可以放在 if 的外面,def 的最后。还有if warrior.feel.empty?里面可以还要在加个elsif,你在想想,试一下吧,我昨晚上打过去手头没有过关的代码

@karmue @health = 0 写在 def 外面是没有作用的,可以改成 def initialize; @health = 0; end 或者 def play_turn(warrior); @health ||= 0 ... 如果写在外面,外面的@health相当于 Player 作为 Class 类的一个实例的 instance variable,跟里面的@health不是同一个东西。

Unknow user #12 August 10, 2013

我过关的代码。写的不好的地方欢迎指教。

https://github.com/dixia/rubywarrior/blob/master/warrior.rb

You need to Sign in before reply, if you don't have an account, please Sign up first.