Class: FortressCreator::Area

Inherits:
Rectangle show all
Defined in:
app/models/fortress_creator.rb

Overview

This class describes sub-area of Fortress. Area is connected to another area by pathway.

Constant Summary

NARROW_BETWEEN_ROOM_AND_AREA_SIZE =

Least length between room border and area border.

1

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods inherited from Rectangle

#x_center, #y_center

Constructor Details

- (Area) initialize(x, y, size, direction, cells)

Returns a new instance of Area

Parameters:

  • x (Integer)

    x-coordinate of top-left.

  • y (Integer)

    y-coordinate of top-left.

  • size (Integer)

    side size of Area

  • cells (Array)

    Array of FortressCell.



218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# File 'app/models/fortress_creator.rb', line 218

def initialize(x, y, size, direction, cells)
  @x1 = x
  @y1 = y
  @x2 = x + size - 1
  @y2 = y + size - 1
  @area_size = size
  @room_size = random_room_size
  @room = Rectangle.new
  @room.x1 = @x1 + rand(@area_size - @room_size - 2).truncate + 1
  @room.y1 = @y1 + rand(@area_size - @room_size - 2).truncate + 1
  @room.x2 = @room.x1 + @room_size - 1
  @room.y2 = @room.y1 + @room_size - 1
  @exit_direction = direction
  @exit_path = nil
  @fortress_cells = cells
  set_exit_path
  update_cells
  @connected_directions = Array.new
end

Instance Attribute Details

- (Object) connected_directions

Returns the value of attribute connected_directions



212
213
214
# File 'app/models/fortress_creator.rb', line 212

def connected_directions
  @connected_directions
end

- (Object) room

Returns the value of attribute room



212
213
214
# File 'app/models/fortress_creator.rb', line 212

def room
  @room
end

- (Object) x1

Returns the value of attribute x1



212
213
214
# File 'app/models/fortress_creator.rb', line 212

def x1
  @x1
end

- (Object) x2

Returns the value of attribute x2



212
213
214
# File 'app/models/fortress_creator.rb', line 212

def x2
  @x2
end

- (Object) y1

Returns the value of attribute y1



212
213
214
# File 'app/models/fortress_creator.rb', line 212

def y1
  @y1
end

- (Object) y2

Returns the value of attribute y2



212
213
214
# File 'app/models/fortress_creator.rb', line 212

def y2
  @y2
end

Instance Method Details

- (Boolean) is_connected_east?

Return true or false whether east border of Area is connected to another Area or not.

Returns:

  • (Boolean)


240
241
242
243
# File 'app/models/fortress_creator.rb', line 240

def is_connected_east?
  return true if @connected_directions.include?(:east)
  return false
end

- (Boolean) is_connected_south?

Return true or false whether south border of Area is connected to another Area or not.

Returns:

  • (Boolean)


247
248
249
250
# File 'app/models/fortress_creator.rb', line 247

def is_connected_south?
  return true if @connected_directions.include?(:south)
  return false
end

- (Boolean) is_enough_space_room_east?

Return true or false whether there is larger space than NARROW_BETWEEN_ROOM_AND_AREA_SIZE between east border of Area and room or not.

Returns:

  • (Boolean)


254
255
256
257
# File 'app/models/fortress_creator.rb', line 254

def is_enough_space_room_east?
  return true if NARROW_BETWEEN_ROOM_AND_AREA_SIZE < @x2 - @room.x2
  return false
end

- (Boolean) is_enough_space_room_north?

Return true or false whether there is larger space than NARROW_BETWEEN_ROOM_AND_AREA_SIZE between north border of Area and room or not.

Returns:

  • (Boolean)


268
269
270
271
# File 'app/models/fortress_creator.rb', line 268

def is_enough_space_room_north?
  return true if NARROW_BETWEEN_ROOM_AND_AREA_SIZE < @room.y1 - @y1
  return false
end

- (Boolean) is_enough_space_room_south?

Return true or false whether there is larger space than NARROW_BETWEEN_ROOM_AND_AREA_SIZE between south border of Area and room or not.

Returns:

  • (Boolean)


275
276
277
278
# File 'app/models/fortress_creator.rb', line 275

def is_enough_space_room_south?
  return true if NARROW_BETWEEN_ROOM_AND_AREA_SIZE < @y2 - @room.y2
  return false
end

- (Boolean) is_enough_space_room_west?

Return true or false whether there is larger space than NARROW_BETWEEN_ROOM_AND_AREA_SIZE between west border of Area and room or not.

Returns:

  • (Boolean)


261
262
263
264
# File 'app/models/fortress_creator.rb', line 261

def is_enough_space_room_west?
  return true if NARROW_BETWEEN_ROOM_AND_AREA_SIZE < @room.x1 - @x1
  return false
end