Class: Path
- Inherits:
-
Object
- Object
- Path
- Defined in:
- lib/ruby-doom.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#start ⇒ Object
readonly
Returns the value of attribute start.
Instance Method Summary collapse
- #add(p, count = 1) ⇒ Object
-
#initialize(startx, starty, path = "") ⇒ Path
constructor
A new instance of Path.
- #nethack(size = Nethack::DEFAULT_SIZE) ⇒ Object
- #segment_count ⇒ Object
- #segments ⇒ Object
- #to_s ⇒ Object
- #visit(visitor) ⇒ Object
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
840 841 842 |
# File 'lib/ruby-doom.rb', line 840 def path @path end |
#start ⇒ Object (readonly)
Returns the value of attribute start.
840 841 842 |
# File 'lib/ruby-doom.rb', line 840 def start @start end |
Instance Method Details
#add(p, count = 1) ⇒ Object
845 846 847 |
# File 'lib/ruby-doom.rb', line 845 def add(p,count=1) count.times {@path += p } end |
#nethack(size = Nethack::DEFAULT_SIZE) ⇒ Object
873 874 875 876 877 |
# File 'lib/ruby-doom.rb', line 873 def nethack(size=Nethack::DEFAULT_SIZE) n = Nethack.new(@start, size) visit(n) return n.render end |
#segment_count ⇒ Object
851 852 853 |
# File 'lib/ruby-doom.rb', line 851 def segment_count segments.size end |
#segments ⇒ Object
848 849 850 |
# File 'lib/ruby-doom.rb', line 848 def segments @path.split(/\//) end |
#to_s ⇒ Object
878 879 880 |
# File 'lib/ruby-doom.rb', line 878 def to_s @path end |
#visit(visitor) ⇒ Object
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 |
# File 'lib/ruby-doom.rb', line 854 def visit(visitor) cur = @start segments.each do |x| dir = x[0].chr len = x.slice(1, x.length-1).to_i if dir == "e" cur = cur.translate(len, 0) elsif dir == "n" cur = cur.translate(0, len) elsif dir == "w" cur = cur.translate(-len, 0) elsif dir == "s" cur = cur.translate(0, -len) else raise "Unrecognized direction " + dir.to_s + " in segment " + x.to_s end visitor.line_to(cur) end end |