Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
January 1, 2016 12:09
-
-
Save brittanmcg/8142558 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle class challenge
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BoggleBoard | |
def initialize | |
@dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
end | |
def words(*coords) | |
coords.map do |coord| | |
@dice_grid[coord.first][coord.last] | |
end.join("") | |
end | |
def get_row(row_num) | |
@dice_grid[row_num] | |
end | |
def get_col(col_num) | |
@dice_grid.map {|e| e[col_num] } | |
end | |
def get_char(*coords) | |
coords.map do |coord| | |
@dice_grid[coord.first][coord.last] | |
end | |
end | |
def get_diag(*first_coord) | |
@dice_grid.map {|diag_coord| diag_coord[first_coord.first][first_coord.last] } | |
first_coord.first += 1 | |
first_coord.last += 1 | |
until first_coord == last_coord | |
end | |
end | |
end | |
game = BoggleBoard.new | |
p game.words([0,1],[0,2],[2,1]) | |
p game.get_row(2) | |
p game.get_col(1) | |
p game.get_char([2,1]) | |
p game.get_diag([0,0],[3,3]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment