Level 4 Rubywarrior (clearing my code)

I learn programming through Ruby and I found the amazing Rubywarrior Ryan Bates from Railscasts. Unfortunately, I'm stuck with my code causing syntax error messages (unexpected end of $).

I do not ask for an answer, I would like to deal with it myself, but if someone can indicate where my code is getting the error from, it will be super. Thank!

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
+3
source share
3 answers

My suggestion:

def should_i_move?(warrior)
  if healthy? and alone?
    warrior.rest!
  else
    warrior.walk!
  end  # <<MISSING THIS ONE
end
+4
source

This error message means that a keyword is missing somewhere end. Check your code to make sure all of your statements are spelled correctly.

+4
source

Ruby 1.9.3, , :

-:46: warning: mismatched indentations at 'end' with 'if' at 42
-:57: warning: mismatched indentations at 'end' with 'def' at 41

-:57: syntax error, unexpected $end, expecting keyword_end

46 end def should_i_move?(warrior)

Ruby 1.9.

+1

All Articles