Class: ConsoleInterface
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Interface
Instance Method Summary collapse
- #adjust_for_screen_width(step_count) ⇒ Object
- #current_representation ⇒ Object
- #display_representation(representation) ⇒ Object
- #finish ⇒ Object
- #human_position ⇒ Object
-
#initialize ⇒ ConsoleInterface
constructor
A new instance of ConsoleInterface.
- #something_happened ⇒ Object
- #zombie_position ⇒ Object
Constructor Details
#initialize ⇒ ConsoleInterface
Returns a new instance of ConsoleInterface.
7 8 9 10 |
# File 'lib/interface.rb', line 7 def initialize @representations = [] @current_zombie = nil end |
Instance Method Details
#adjust_for_screen_width(step_count) ⇒ Object
45 46 47 48 |
# File 'lib/interface.rb', line 45 def adjust_for_screen_width(step_count) max_position = 78.0 (step_count * max_position / [@human.test_suite_size, max_position].max).round end |
#current_representation ⇒ Object
12 13 14 15 16 17 18 19 20 |
# File 'lib/interface.rb', line 12 def current_representation if @current_zombie.nil? "." * human_position + @human.current_symbol elsif human_position > zombie_position "." * zombie_position + @current_zombie.current_symbol + "." * (human_position - zombie_position - 1) + @human.current_symbol else "." * zombie_position + @current_zombie.current_symbol end end |
#display_representation(representation) ⇒ Object
27 28 29 30 31 |
# File 'lib/interface.rb', line 27 def display_representation(representation) print "\r", representation STDOUT.flush sleep 0.2 end |
#finish ⇒ Object
33 34 35 |
# File 'lib/interface.rb', line 33 def finish puts end |
#human_position ⇒ Object
37 38 39 |
# File 'lib/interface.rb', line 37 def human_position adjust_for_screen_width(@human.successful_step_count) end |
#something_happened ⇒ Object
22 23 24 25 |
# File 'lib/interface.rb', line 22 def something_happened @representations << current_representation display_representation(@representations.last) end |
#zombie_position ⇒ Object
41 42 43 |
# File 'lib/interface.rb', line 41 def zombie_position adjust_for_screen_width(@current_zombie.successful_step_count) end |