Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Created
December 1, 2013 07:56
-
-
Save JamieMcKenzie/7729675 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1
boggle 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 | |
def initialize(board) | |
@board = board | |
end | |
def create_word(*coords) | |
coords.map{|coord| @board[coord.first][coord.last]}.join("") | |
end | |
def get_row(row) | |
word = [] | |
counter = 0 | |
@board[row].size.times do | |
word << @board[row][counter] | |
counter+=1 | |
end | |
puts word.join("") | |
end | |
def get_col(col) | |
word = [] | |
counter = 0 | |
@board[col].size.times do | |
word << @board[counter][col] | |
counter+=1 | |
end | |
puts word.join("") | |
end | |
def get_coord(letter) | |
@board do |arraay| | |
if array.include?(letter) | |
puts "This method worked." | |
else | |
puts "This letter is not contained in the board." | |
end | |
end | |
end | |
def get_diag(start_point) | |
end | |
end | |
first_board = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
boggle_board = BoggleBoard.new(first_board) | |
puts boggle_board.create_word([0,1], [1,1], [2,1], [3,2]) #=> returns "rock" | |
puts boggle_board.create_word([0,1], [1,1], [1,2]) #=> returns "rod" | |
puts boggle_board.create_word([2,1], [2,2], [1,1], [1,2]) #=> returns "clod" | |
boggle_board.get_row(2) #=> returns "eclr" | |
boggle_board.get_row(0) #=> returns "brae" | |
boggle_board.get_col(1) #=> returns "roca" | |
boggle_board.get_col(3) #=> returns "etre" | |
boggle_board.get_coord("k") | |
boggle_board.get_coord("z") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment