我正在通过 Ruby 学习编程,并且我发现了 Railscasts 的 Ryan Bates 写的很棒的 Rubywarrior。不幸的是,我被困在我的代码抛出语法错误消息(意外的 $end)。
我不是在要求答案,我想自己解决这个问题,但如果有人能指出我的代码从哪里得到错误,那就太好了。谢谢!
class Player
def initialize
@maxhealth = 20
@dying = 7
@previoushealth = @maxhealth
@health = warrior.health
@warrior = warrior
end
def play_turn(warrior)
# If there are no enemies, rest until health is 100%
turn_start_check(warrior)
actions(warrior)
turn_end_check(warrior)
end
def actions(warrior)
if @damaged_since_last_turn
warrior.shoot!
elsif
@health < @maxhealth
warrior.rest!
else
warrior.walk!
end
end
def hurt?(warrior)
warrior.health < 20
end
def healthy?(warrior)
warrior.health = 20
end
def alone?(warrior)
warrior.feel.empty?
end
def should_i_move?(warrior)
if healthy? and alone?
warrior.rest!
else
warrior.walk!
end
# Put code here for if health from previous turn is less than last term
# If true don't rest and keep moving forward
def turn_start_check(warrior)
@damaged_since_last_turn = @previoushealth > warrior.health
end
def turn_end_check(warrior)
@previoushealth = warrior.health
end
end