Class: PFM::MiningGame::GridHandler
- Defined in:
- scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb
Overview
Class handling the grid for the mining game
Constant Summary collapse
- MIN_ITEM_COUNT =
Constant telling the minimum amount of item possible on a grid
2
- MAX_ITEM_COUNT =
Constant telling the maximum amount of item possible on a grid
5
Instance Attribute Summary collapse
-
#arr_irons ⇒ Array<Diggable>
readonly
Get the list of irons.
-
#arr_items ⇒ Array<Diggable>
readonly
Get the list of diggable items.
-
#arr_tiles_state ⇒ Array<Array<Integer>>
readonly
Get the tile states.
-
#height ⇒ Integer
readonly
Get the grid height.
-
#width ⇒ Integer
readonly
Get the grid width.
Instance Method Summary collapse
-
#check_presence_of_diggable(x, y) ⇒ Diggable, Boolean
Check if a diggable is present at the said coordinate and return it if it's an item.
-
#initialize(wanted_items, item_count, grid_width, grid_height) ⇒ GridHandler
constructor
Create a new grid handler.
-
#ready? ⇒ Boolean
Tell if the mining game grid is ready.
Constructor Details
#initialize(wanted_items, item_count, grid_width, grid_height) ⇒ GridHandler
Create a new grid handler
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 29 def initialize(wanted_items, item_count, grid_width, grid_height) @item_count = (item_count || wanted_items&.size || rand(MIN_ITEM_COUNT..MAX_ITEM_COUNT)).clamp(MIN_ITEM_COUNT, MAX_ITEM_COUNT) @wanted_items = (map_symbol2hash(wanted_items) || randomize_items(@item_count)).take(@item_count) @width = grid_width @height = grid_height @nb_irons = rand(4..7) # @type [Array<Diggable>] @arr_irons = [] @ready = false # We create all the grids @arr_tiles_state = Array.new(@height) { Array.new(@width, 0) } @mgt = Random::MINING_GAME_TILES initialize_grid_content end |
Instance Attribute Details
#arr_irons ⇒ Array<Diggable> (readonly)
Get the list of irons
23 24 25 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 23 def arr_irons @arr_irons end |
#arr_items ⇒ Array<Diggable> (readonly)
Get the list of diggable items
20 21 22 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 20 def arr_items @arr_items end |
#arr_tiles_state ⇒ Array<Array<Integer>> (readonly)
Get the tile states
17 18 19 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 17 def arr_tiles_state @arr_tiles_state end |
#height ⇒ Integer (readonly)
Get the grid height
14 15 16 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 14 def height @height end |
#width ⇒ Integer (readonly)
Get the grid width
11 12 13 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 11 def width @width end |
Instance Method Details
#check_presence_of_diggable(x, y) ⇒ Diggable, Boolean
Check if a diggable is present at the said coordinate and return it if it's an item
54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 54 def check_presence_of_diggable(x, y) diggable = @arr_items.find { |item| (item.x...item.x + item.width).cover?(x) && (item.y...item.y + item.height).cover?(y) } if diggable return diggable if diggable.pattern[y - diggable.y][x - diggable.x] end diggable = @arr_irons.find { |item| (item.x...item.x + item.width).cover?(x) && (item.y...item.y + item.height).cover?(y) } if diggable return true if diggable.pattern[y - diggable.y][x - diggable.x] end return false end |
#ready? ⇒ Boolean
Tell if the mining game grid is ready
46 47 48 |
# File 'scripts/01450 Systems/08001 Mining Game/00020 PFM_Mining_Game/00002 MiningGame_GridHandler.rb', line 46 def ready? return @ready end |