Class: Human

Inherits:
Actor
  • Object
show all
Defined in:
lib/human.rb

Direct Known Subclasses

MockHuman, Zombie

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_pattern, world) ⇒ Human

Returns a new instance of Human.



14
15
16
17
18
19
20
# File 'lib/human.rb', line 14

def initialize(test_pattern, world)
  @status = nil #Currently only used by zombie
  @world = world
  @successful_step_count = 0
  @health = :alive
  @test_handler = TestUnitHandler.new(test_pattern, self)
end

Instance Attribute Details

#successful_step_countObject (readonly)

Returns the value of attribute successful_step_count.



8
9
10
# File 'lib/human.rb', line 8

def successful_step_count
  @successful_step_count
end

Class Method Details

.new_using_test_unit_handler(test_pattern, world) ⇒ Object



10
11
12
# File 'lib/human.rb', line 10

def self.new_using_test_unit_handler(test_pattern, world)
  new(test_pattern, world)
end

Instance Method Details

#actor_directionObject



54
55
56
# File 'lib/human.rb', line 54

def actor_direction
  270.0
end

#actor_stateObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/human.rb', line 42

def actor_state
  return "attacking" if @status == :attacking
  case @health
  when :alive
    "moving"
  when :dying
    "dying"
  when :dead
    "dead"
  end
end

#actor_typeObject



38
39
40
# File 'lib/human.rb', line 38

def actor_type
  'robot'
end

#current_symbolObject



27
28
29
30
31
32
33
34
35
36
# File 'lib/human.rb', line 27

def current_symbol
  case @health
  when :alive
    "@"
  when :dying
    "*"
  when :dead
    "+"
  end
end

#dead?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/human.rb', line 72

def dead?
  @health == :dead
end

#dying?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/human.rb', line 68

def dying?
  @health == :dying
end

#finish_dyingObject



76
77
78
79
80
81
82
# File 'lib/human.rb', line 76

def finish_dying
  sleep 0.5
  raise "I'm not dead yet!" unless dying?
  @health = :dead
  notify_world
  sleep 0.5
end

#get_eatenObject



88
89
90
# File 'lib/human.rb', line 88

def get_eaten
  @health = :dying unless dead?
end

#notify_failing_stepObject



63
64
65
66
# File 'lib/human.rb', line 63

def notify_failing_step
  @health = :dying
  notify_world
end

#notify_passing_stepObject



58
59
60
61
# File 'lib/human.rb', line 58

def notify_passing_step
  @successful_step_count += 1
  notify_world
end

#notify_worldObject



84
85
86
# File 'lib/human.rb', line 84

def notify_world
  @world.something_happened
end

#runObject



22
23
24
25
# File 'lib/human.rb', line 22

def run
  notify_world
  @test_handler.run
end

#test_suite_sizeObject



92
93
94
# File 'lib/human.rb', line 92

def test_suite_size
  @test_handler.test_suite_size
end