Class: Nethack

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-doom.rb

Constant Summary collapse

DEFAULT_SIZE =
20

Instance Method Summary collapse

Constructor Details

#initialize(start, size) ⇒ Nethack

Returns a new instance of Nethack.



885
886
887
888
889
890
# File 'lib/ruby-doom.rb', line 885

def initialize(start,size)
  @start = start
  @map = Array.new(size)
  @map.each_index {|x| @map[x] = Array.new(size, ".") }
  @prev = @start
end

Instance Method Details

#line_to(current) ⇒ Object



891
892
893
894
# File 'lib/ruby-doom.rb', line 891

def line_to(current)
  @prev.lineto(current).each {|pt| @map[pt.y/100][pt.x/100] = "X" }
  @prev = current
end

#renderObject



899
900
901
902
903
904
905
906
907
908
# File 'lib/ruby-doom.rb', line 899

def render
  res = ""
  @map.each_index do |x|
    @map[x].each_index do 
      |y| res << @map[@map.size-1-x][y-1] + " " 
    end
    res << "\n"
  end
  res
end

#thing(t) ⇒ Object



895
896
897
898
# File 'lib/ruby-doom.rb', line 895

def thing(t)
  puts "#{(t.location.y/100)},#{((@map.size-1) - (t.location.x/100))} -> #{Dictionary.get.thing_for_type_id(t.type_id).symbol}"
  @map[t.location.y/100][(@map.size-1) - (t.location.x/100)] = Dictionary.get.thing_for_type_id(t.type_id).symbol
end