Class: Room

Inherits:
DrawableObject show all
Includes:
RoomContent, RoomDraw
Defined in:
lib/rooms/room.rb

Constant Summary collapse

SQUARES_BETWEEN_ROOMS =
Hallway::HALLWAYS_LENGTH
ROOM_SQUARE_SIZE =
12

Constants included from RoomContent

RoomContent::CONTENT_DESC_EMPTY, RoomContent::CONTENT_DESC_MONSTERS_CLEARED, RoomContent::CONTENT_DESC_TRAP_CLEARED

Constants inherited from DrawableObject

DrawableObject::BACKGROUND_COLOR, DrawableObject::GRID_COLOR, DrawableObject::SQUARE_SIZE_IN_PIXELS, DrawableObject::TEXT_COLOR

Instance Attribute Summary collapse

Attributes included from RoomContent

#encounters_difficulty, #party_levels

Instance Method Summary collapse

Methods included from RoomDraw

#draw

Methods included from RoomContent

#clear, #set_entry_room, #set_treasure_room

Constructor Details

#initialize(top, left, lair, room_data = {}) ⇒ Room

Returns a new instance of Room.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/rooms/room.rb', line 18

def initialize( top, left, lair, room_data = {} )
  @top = room_data['top'] ? room_data['top'].to_i : top
  @left = room_data['left'] ? room_data['left'].to_i : left
  @content = room_data['content']
  @content_description = room_data['content_description']
  @entry_room = room_data['entry_room']
  @id = room_data['id'] ? room_data['id'] : [ top, left ]

  @decorations = []
  if room_data['decorations']
    load_decoration_from_json(room_data['decorations'] )
  else
    create_decorations
  end

  create_encounters( lair ) unless room_data['content_description']
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/rooms/room.rb', line 12

def content
  @content
end

#content_descriptionObject (readonly)

Returns the value of attribute content_description.



12
13
14
# File 'lib/rooms/room.rb', line 12

def content_description
  @content_description
end

#decorationsObject (readonly)

Returns the value of attribute decorations.



12
13
14
# File 'lib/rooms/room.rb', line 12

def decorations
  @decorations
end

#entry_roomObject (readonly)

Returns the value of attribute entry_room.



12
13
14
# File 'lib/rooms/room.rb', line 12

def entry_room
  @entry_room
end

#idObject

Returns the value of attribute id.



13
14
15
# File 'lib/rooms/room.rb', line 13

def id
  @id
end

#leftObject (readonly)

Returns the value of attribute left.



12
13
14
# File 'lib/rooms/room.rb', line 12

def left
  @left
end

#max_xObject (readonly)

Returns the value of attribute max_x.



12
13
14
# File 'lib/rooms/room.rb', line 12

def max_x
  @max_x
end

#max_yObject (readonly)

Returns the value of attribute max_y.



12
13
14
# File 'lib/rooms/room.rb', line 12

def max_y
  @max_y
end

#min_xObject (readonly)

Returns the value of attribute min_x.



12
13
14
# File 'lib/rooms/room.rb', line 12

def min_x
  @min_x
end

#min_yObject (readonly)

Returns the value of attribute min_y.



12
13
14
# File 'lib/rooms/room.rb', line 12

def min_y
  @min_y
end

#topObject (readonly)

Returns the value of attribute top.



12
13
14
# File 'lib/rooms/room.rb', line 12

def top
  @top
end

Instance Method Details

#compute_coordsObject



45
46
47
48
49
50
# File 'lib/rooms/room.rb', line 45

def compute_coords
  @min_x = ( ( @left-1 ) * ROOM_SQUARE_SIZE + @left * SQUARES_BETWEEN_ROOMS ) * SQUARE_SIZE_IN_PIXELS
  @max_x = @min_x + ROOM_SQUARE_SIZE * SQUARE_SIZE_IN_PIXELS
  @min_y = ( ( @top-1 ) * ROOM_SQUARE_SIZE + @top * SQUARES_BETWEEN_ROOMS ) * SQUARE_SIZE_IN_PIXELS
  @max_y = @min_y + ROOM_SQUARE_SIZE * SQUARE_SIZE_IN_PIXELS
end

#compute_coords_at_originObject



52
53
54
55
56
57
# File 'lib/rooms/room.rb', line 52

def compute_coords_at_origin
  @min_x = SQUARES_BETWEEN_ROOMS * SQUARE_SIZE_IN_PIXELS
  @max_x = @min_x + ROOM_SQUARE_SIZE * SQUARE_SIZE_IN_PIXELS
  @min_y = SQUARES_BETWEEN_ROOMS * SQUARE_SIZE_IN_PIXELS
  @max_y = @min_y + ROOM_SQUARE_SIZE * SQUARE_SIZE_IN_PIXELS
end

#decal_at_originObject



40
41
42
43
# File 'lib/rooms/room.rb', line 40

def decal_at_origin
  @top = 1
  @left = 1
end

#to_hash(hallways) ⇒ Object



59
60
61
62
63
# File 'lib/rooms/room.rb', line 59

def to_hash( hallways )
  {id: @id, entry_room: @entry_room, content: @content, content_description: @content_description,
   top: @top, left: @left, decorations: @decorations.map{ |d| d[:decoration_type] },
   connected_hallways: hallways.connected_hallways( self ).map{ |k, h| { k => h.to_hash } } }
end

#to_json_hash(hallways) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/rooms/room.rb', line 65

def to_json_hash( hallways )
  if @decorations.count > 1
    a = :true
  end
  h = to_hash( hallways )
  h.delete(:connected_hallways)
  h
end

#top_left_arrayObject



36
37
38
# File 'lib/rooms/room.rb', line 36

def top_left_array
  [ @top, @left ]
end