Class: PFM::MiningGame::Diggable

Inherits:
Object
  • Object
show all
Defined in:
scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(hash) ⇒ Diggable

Returns a new instance of Diggable.



327
328
329
330
331
332
333
334
335
336
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 327

def initialize(hash)
  @x = @y = 0
  @symbol = hash[:symbol]
  @origin_pattern = @pattern = hash[:layout].map(&:clone)
  @accepted_rotation = hash[:accepted_max_rotation]
  @rotation = 0
  set_new_rotation
  @is_an_item = GameData::MiningGame::DATA_ITEM.keys.include?(@symbol)
  @placed = @revealed = false
end

Instance Attribute Details

#accepted_rotation

Returns the value of attribute accepted_rotation.



321
322
323
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 321

def accepted_rotation
  @accepted_rotation
end

#height

Returns the value of attribute height.



316
317
318
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 316

def height
  @height
end

#is_an_item

Returns the value of attribute is_an_item.



323
324
325
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 323

def is_an_item
  @is_an_item
end

#origin_pattern

Returns the value of attribute origin_pattern.



318
319
320
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 318

def origin_pattern
  @origin_pattern
end

#patternArray<Array<Boolean>>

Returns:

  • (Array<Array<Boolean>>)


320
321
322
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 320

def pattern
  @pattern
end

#placed

Returns the value of attribute placed.



324
325
326
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 324

def placed
  @placed
end

#revealed

Returns the value of attribute revealed.



325
326
327
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 325

def revealed
  @revealed
end

#rotation

Returns the value of attribute rotation.



322
323
324
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 322

def rotation
  @rotation
end

#symbol

Returns the value of attribute symbol.



317
318
319
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 317

def symbol
  @symbol
end

#width

Returns the value of attribute width.



315
316
317
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 315

def width
  @width
end

#x

Returns the value of attribute x.



313
314
315
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 313

def x
  @x
end

#y

Returns the value of attribute y.



314
315
316
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 314

def y
  @y
end

Instance Method Details

#overlap?(diggable) ⇒ Boolean

Test if another diggable is overlapping this diggable

Parameters:

Returns:

  • (Boolean)


347
348
349
350
351
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 347

def overlap?(diggable)
  return false if self == diggable || !@placed
  return true if range_overlapping?(@x..(@x + @width - 1), (diggable.x..diggable.x + diggable.width)) &&
                 range_overlapping?(@y..(@y + @height - 1), (diggable.y..diggable.y + diggable.height))
end

#set_new_rotation



338
339
340
341
342
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 338

def set_new_rotation
  @rotation = @accepted_rotation != 0 ? rand(0..@accepted_rotation) : 0
  rotate_object
  set_width_and_length
end