Class: Board
- Inherits:
-
Object
- Object
- Board
- Defined in:
- lib/tumblr-game/board.rb
Overview
BOARD CLASS. This class represents the “game board” that each tile is drawn on. The initialize function accepts 10 images that will be stored in the board object’s tile_array. This represents the entire game board. This class effectively acts as an interface to the game tiles. The draw board function calls the draw functions for each of the tiles. This class contains various utility functions described below to interface appropriately with the tiles.
Instance Method Summary collapse
-
#draw_board ⇒ Object
draw function of the board class: this will go through the tile array and draw each tile.
-
#flip_tile(ind, bool) ⇒ Object
this function will flip a given tile to the face indicated by the parameter bool.
-
#get_id(ind) ⇒ Object
this function will get the id from the desired tile.
-
#inc_match ⇒ Object
this function will increment the match counter to reflect a user successfully matching tiles.
-
#initialize(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) ⇒ Board
constructor
initialize function of the board class: this will accept 10 parameters that are each a path to an image it will then populate the tile array appropriately with each image.
-
#is_matched(ind) ⇒ Object
this function will get the matched status of a specific tile and return it.
-
#matchTile(ind) ⇒ Object
this function will set a tile to its “matched” configuration.
-
#return_count ⇒ Object
this function will return the amount of matched tiles.
Constructor Details
#initialize(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) ⇒ Board
initialize function of the board class: this will accept 10 parameters that are each a path to an image it will then populate the tile array appropriately with each image
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/tumblr-game/board.rb', line 12 def initialize(t1, t2, t3, t4, t5, t6, t7, t8, t9, t10) @tile_Array = Array.new(10) @tile_Array[0] = t1 @tile_Array[1] = t2 @tile_Array[2] = t3 @tile_Array[3] = t4 @tile_Array[4] = t5 @tile_Array[5] = t6 @tile_Array[6] = t7 @tile_Array[7] = t8 @tile_Array[8] = t9 @tile_Array[9] = t10 # counter that will keep track of how many matches have occurred. when this counter reaches 5 before the time limit ends, the player wins @matchedCount = 0 end |
Instance Method Details
#draw_board ⇒ Object
draw function of the board class: this will go through the tile array and draw each tile
30 31 32 33 34 |
# File 'lib/tumblr-game/board.rb', line 30 def draw_board for i in 0..9 @tile_Array[i].draw end end |
#flip_tile(ind, bool) ⇒ Object
this function will flip a given tile to the face indicated by the parameter bool. false = facedown, true = face up
37 38 39 |
# File 'lib/tumblr-game/board.rb', line 37 def flip_tile(ind, bool) @tile_Array[ind].flip(bool) end |
#get_id(ind) ⇒ Object
this function will get the id from the desired tile
42 43 44 |
# File 'lib/tumblr-game/board.rb', line 42 def get_id(ind) return @tile_Array[ind].return_id end |
#inc_match ⇒ Object
this function will increment the match counter to reflect a user successfully matching tiles
57 58 59 |
# File 'lib/tumblr-game/board.rb', line 57 def inc_match @matchedCount += 1 end |
#is_matched(ind) ⇒ Object
this function will get the matched status of a specific tile and return it
52 53 54 |
# File 'lib/tumblr-game/board.rb', line 52 def is_matched(ind) return @tile_Array[ind].return_match end |
#matchTile(ind) ⇒ Object
this function will set a tile to its “matched” configuration
47 48 49 |
# File 'lib/tumblr-game/board.rb', line 47 def matchTile(ind) @tile_Array[ind].set_match end |
#return_count ⇒ Object
this function will return the amount of matched tiles
62 63 64 |
# File 'lib/tumblr-game/board.rb', line 62 def return_count return @matchedCount end |