Class: RDGC::Map::Area

Inherits:
Object
  • Object
show all
Includes:
TileType
Defined in:
lib/rdgc/map/area.rb,
lib/rdgc/map/blind_area.rb

Direct Known Subclasses

Block, Board, Road, Room

Constant Summary

Constants included from TileType

TileType::OUT, TileType::ROAD, TileType::ROOM, TileType::WALL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bottomObject

Returns the value of attribute bottom.



7
8
9
# File 'lib/rdgc/map/area.rb', line 7

def bottom
  @bottom
end

#leftObject

Returns the value of attribute left.



7
8
9
# File 'lib/rdgc/map/area.rb', line 7

def left
  @left
end

#rightObject

Returns the value of attribute right.



7
8
9
# File 'lib/rdgc/map/area.rb', line 7

def right
  @right
end

#topObject

Returns the value of attribute top.



7
8
9
# File 'lib/rdgc/map/area.rb', line 7

def top
  @top
end

Class Method Details

.create(top, bottom, left, right) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/rdgc/map/area.rb', line 9

def self.create(top, bottom, left, right)
  b = self.new
  b.top = top
  b.bottom = bottom
  b.left = left
  b.right = right
  b
end

Instance Method Details

#blind_levelObject



7
8
9
# File 'lib/rdgc/map/blind_area.rb', line 7

def blind_level
  @blind_level
end

#blind_level_blind?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/rdgc/map/blind_area.rb', line 25

def blind_level_blind?
  blind_level == :blind ? true : false
end

#blind_level_dark?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/rdgc/map/blind_area.rb', line 29

def blind_level_dark?
  blind_level == :dark ? true : false
end

#blind_level_none?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rdgc/map/blind_area.rb', line 17

def blind_level_none?
  blind_level == :none ? true : false
end

#blind_level_open?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rdgc/map/blind_area.rb', line 21

def blind_level_open?
  blind_level == :open ? true : false
end

#coordinatesObject Also known as: to_co



18
19
20
# File 'lib/rdgc/map/area.rb', line 18

def coordinates
  "t:#{top} b:#{bottom} l:#{left} r:#{right} / w:#{width} h:#{height}"
end

#eachObject



44
45
46
47
48
49
50
51
# File 'lib/rdgc/map/area.rb', line 44

def each
  return to_enum(:each) unless block_given?
  each_x do |x|
    each_y do |y|
      yield(x, y)
    end
  end
end

#each_tileObject



67
68
69
70
71
72
# File 'lib/rdgc/map/area.rb', line 67

def each_tile
  return to_enum(:each_tile) unless block_given?
  each do |x, y|
    yield(x, y, tile(x, y))
  end
end

#each_xObject



53
54
55
56
57
58
# File 'lib/rdgc/map/area.rb', line 53

def each_x
  return to_enum(:each_x) unless block_given?
  (left..right).each do |x|
    yield(x)
  end
end

#each_yObject



60
61
62
63
64
65
# File 'lib/rdgc/map/area.rb', line 60

def each_y
  return to_enum(:each_y) unless block_given?
  (top..bottom).each do |y|
    yield(y)
  end
end

#fillObject



74
75
76
# File 'lib/rdgc/map/area.rb', line 74

def fill
  # need override

end

#fill_tile(tile) ⇒ Object



78
79
80
81
82
83
84
# File 'lib/rdgc/map/area.rb', line 78

def fill_tile(tile)
  each do |x, y|
    set_tile(x, y, tile)
  end

  self
end

#has_xy?(x, y) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
35
36
37
38
# File 'lib/rdgc/map/area.rb', line 32

def has_xy?(x, y)
  return false if x < left
  return false if x > right
  return false if y < top
  return false if y > bottom
  true
end

#heightObject



24
25
26
# File 'lib/rdgc/map/area.rb', line 24

def height
  bottom - top + 1
end

#random_pointObject



40
41
42
# File 'lib/rdgc/map/area.rb', line 40

def random_point
  [range_rand(left, right), range_rand(top, bottom)]
end

#set_blind(level) ⇒ Object



11
12
13
14
15
# File 'lib/rdgc/map/blind_area.rb', line 11

def set_blind(level)
  return unless [:none, :open, :blind, :dark].include?(level)
  @blind_level = level
  self
end

#set_tile(x, y, tile) ⇒ Object



86
87
88
89
# File 'lib/rdgc/map/area.rb', line 86

def set_tile(x, y, tile)
  return unless has_xy?(x, y)
  tile_data[x][y] = tile
end

#tile(x, y) ⇒ Object



91
92
93
94
# File 'lib/rdgc/map/area.rb', line 91

def tile(x, y)
  return unless has_xy?(x, y)
  tile_data[x][y]
end

#widthObject



28
29
30
# File 'lib/rdgc/map/area.rb', line 28

def width
  right - left + 1
end