Class: Human
- Inherits:
-
Actor
- Object
- Actor
- Human
- Defined in:
- lib/human.rb
Instance Attribute Summary collapse
-
#successful_step_count ⇒ Object
readonly
Returns the value of attribute successful_step_count.
Class Method Summary collapse
Instance Method Summary collapse
- #actor_direction ⇒ Object
- #actor_state ⇒ Object
- #actor_type ⇒ Object
- #current_symbol ⇒ Object
- #dead? ⇒ Boolean
- #dying? ⇒ Boolean
- #finish_dying ⇒ Object
- #get_eaten ⇒ Object
-
#initialize(test_pattern, world) ⇒ Human
constructor
A new instance of Human.
- #notify_failing_step ⇒ Object
- #notify_passing_step ⇒ Object
- #notify_world ⇒ Object
- #run ⇒ Object
- #test_suite_size ⇒ Object
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_count ⇒ Object (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_direction ⇒ Object
54 55 56 |
# File 'lib/human.rb', line 54 def actor_direction 270.0 end |
#actor_state ⇒ Object
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_type ⇒ Object
38 39 40 |
# File 'lib/human.rb', line 38 def actor_type 'robot' end |
#current_symbol ⇒ Object
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
72 73 74 |
# File 'lib/human.rb', line 72 def dead? @health == :dead end |
#dying? ⇒ Boolean
68 69 70 |
# File 'lib/human.rb', line 68 def @health == :dying end |
#finish_dying ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/human.rb', line 76 def sleep 0.5 raise "I'm not dead yet!" unless @health = :dead notify_world sleep 0.5 end |
#get_eaten ⇒ Object
88 89 90 |
# File 'lib/human.rb', line 88 def get_eaten @health = :dying unless dead? end |
#notify_failing_step ⇒ Object
63 64 65 66 |
# File 'lib/human.rb', line 63 def notify_failing_step @health = :dying notify_world end |
#notify_passing_step ⇒ Object
58 59 60 61 |
# File 'lib/human.rb', line 58 def notify_passing_step @successful_step_count += 1 notify_world end |
#notify_world ⇒ Object
84 85 86 |
# File 'lib/human.rb', line 84 def notify_world @world.something_happened end |
#run ⇒ Object
22 23 24 25 |
# File 'lib/human.rb', line 22 def run notify_world @test_handler.run end |
#test_suite_size ⇒ Object
92 93 94 |
# File 'lib/human.rb', line 92 def test_suite_size @test_handler.test_suite_size end |