Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:55
-
-
Save buck3000/8735908 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
This file contains hidden or 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 | |
attr_accessor :dice_grid | |
def initialize(dice_grid) | |
@dice_grid = dice_grid | |
end | |
def create_word(coords) | |
array =[] | |
coords.each_index do |c| | |
array << @dice_grid[(coords[c].first)][(coords[c].last)] | |
end | |
word = array.join("") | |
puts word | |
end | |
def get_col(col) | |
array = [] | |
(0..3).each do |number| | |
array << @dice_grid[number][col] | |
end | |
puts array.join("") | |
end | |
def get_row(row) | |
array = [] | |
(0..3).each do |number| | |
array << @dice_grid[row][number] | |
end | |
puts array.join("") | |
end | |
# def get_diagonal(coords) | |
# array = [] | |
# # raise ArgumentError if coords != [0,0] || [3,3] || [3,0] || [0,3] | |
# if coords == [0,0] || [3,3] || [1,1] || [2,2] | |
# (0..3).each do |num| | |
# array << @dice_grid[num][num] | |
# end | |
# puts array.join("") | |
# elsif coords == [0,3] || [3,0] || [1,2] || [2,1] | |
# (0..3).each do |num| | |
# array << @dice_grid[(3-num)][num] | |
# end | |
# puts array.join("") | |
# else | |
# raise ArgumentError("Not on a Diagonal!") | |
# end | |
# end | |
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) | |
# implement tests for each of the methods here: | |
boggle_board.create_word([[1, 2], [1, 1], [2, 1], [3, 2]]) | |
boggle_board.get_col(0) | |
boggle_board.get_col(1) | |
boggle_board.get_col(2) | |
boggle_board.get_col(3) | |
boggle_board.get_row(0) | |
boggle_board.get_row(1) | |
boggle_board.get_row(2) | |
boggle_board.get_row(3) | |
# puts "diagonals" | |
# boggle_board.get_diagonal([3,0]) | |
# create driver test code to retrieve a value at a coordinate here: | |
puts boggle_board.dice_grid[3][2] | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment