Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:56
-
-
Save sassygrody/9215137 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle 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) | |
@dice_grid = dice_grid | |
end | |
def create_word(*coords) #splat | |
coords.map { |coord| @dice_grid[coord.first][coord.last]}.join("") #dice_grid[row][column] | |
end | |
def get_row(row) | |
@dice_grid[row] | |
end | |
def get_col(board, col) | |
board.map {|x| x[col]}.to_s | |
end | |
# def get_col(column) | |
# col_array = [] | |
# @dice_grid.each { |row| col_array << row[column]} # pushing all elements at INDEX[__] to array | |
# return col_array | |
# end | |
def get_diagonal | |
diag_array = [] | |
end | |
# diagonal word has coordinates at [0,0],[1,1],[2,2],[3,3] or [0,3],[1,2],[2,1],[3,0] | |
# start at [0,0] and then +1 index on each. | |
# start at [0,3] and then -1 index on each? | |
end | |
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
boggle_board = BoggleBoard.new(dice_grid) | |
puts boggle_board.create_word([1,2],[1,1],[2,1],[3,2]) # dock | |
puts | |
puts boggle_board.get_row(0..3).to_s # this works! but doesn't work on columns... shows as | |
puts # "take" is a real word-- get_row(3) | |
puts boggle_board.get_col(0..1).to_s | |
puts boggle_board.get_col(1).to_s | |
puts boggle_board.get_col(2).to_s | |
puts boggle_board.get_col(3).to_s | |
# add total output--> meaning add the letters? without a method, just to know how many letters there are? puts dice_grid.join("").length | |
puts | |
puts dice_grid[3][2] # --> k | |
puts dice_grid[2][3].upcase # --> r | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment