Class: ConsoleInterface

Inherits:
Interface show all
Defined in:
lib/zombie-chaser/interface.rb

Direct Known Subclasses

NoInterface

Instance Attribute Summary

Attributes inherited from Interface

#human, #zombie_list

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Interface

#sleep

Constructor Details

#initializeConsoleInterface

Returns a new instance of ConsoleInterface.



25
26
27
28
29
30
# File 'lib/zombie-chaser/interface.rb', line 25

def initialize
  @representations = []
  @zombie_list = nil
  @progress_text_being_printed = false
  @output_lock = Monitor.new
end

Class Method Details

.widthObject



23
# File 'lib/zombie-chaser/interface.rb', line 23

def self.width; @width end

.width=(width) ⇒ Object



22
# File 'lib/zombie-chaser/interface.rb', line 22

def self.width=(width); @width = width end

Instance Method Details

#finish_if_neccessaryObject



103
104
105
106
107
# File 'lib/zombie-chaser/interface.rb', line 103

def finish_if_neccessary
  @output_lock.synchronize do
    print_newline_if_neccessary
  end
end

#interface_puts(*args) ⇒ Object



58
59
60
61
62
63
# File 'lib/zombie-chaser/interface.rb', line 58

def interface_puts(*args)
  @output_lock.synchronize do
    print_newline_if_neccessary
    super
  end
end

#no_living_zombies_apart_from_me?(desired_step_count, actor) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/zombie-chaser/interface.rb', line 80

def no_living_zombies_apart_from_me?(desired_step_count, actor)
  desired_position = adjust_for_screen_width(desired_step_count)
  return true if desired_position == adjust_for_screen_width(0) #Hack to allow multiple zombies at the start
  return true if desired_position == adjust_for_screen_width(@human.test_suite_size) #Always room for one more at the dinner table!
  return true if desired_position == adjust_for_screen_width(actor.successful_step_count) #In case there's no advancement involved, and there's multiple zombies in a square even though they shouldn't be
  @zombie_list.each_zombie do |zombie|
    next if zombie.equal? actor #Only checking for collisions with other actors, not with itself
    next if zombie.dead?
    zombie_position = adjust_for_screen_width(zombie.successful_step_count)
    #raise if adjust_for_screen_width(actor.successful_step_count) == zombie_position
    return false if zombie_position == desired_position
  end
  true
end

#something_happenedObject



44
45
46
47
48
49
# File 'lib/zombie-chaser/interface.rb', line 44

def something_happened
  @output_lock.synchronize do
    @representations << current_representation
    display_representation(@representations.last)
  end
end