Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save neetabelthan/8013369 to your computer and use it in GitHub Desktop.
Save neetabelthan/8013369 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BOGGLEBOARD
dice_grid = [["b", "r", "a", "e"],
["i", "o", "d", "t"],
["e", "c", "l", "r"],
["t", "a", "k", "e"]]
def initialize(bb) # Created an initialize method and initialized the instance variable
@bb = bb
end
def create_word(board, *coords) # method create_word accepts two arguments. *coords represent any number of arguments as input.
coords.map { |coord| board[coord.first][coord.last]}.join("") #it collects all the coords the user inputs and joins all the coords.
end
def get_row(row) #get_row method accepts the user input and returns all the elements in the row
@bb[row] #it returns all the elements of the row the user wants.
end
def get_col(col) # get_col method accepts the column number from the user and returns all the elements from the column
@bb.map { |i| i[col] }
end
def get_diag() # methods retuns the diagonal elements from left to right
diag=[]
@bb.each_with_index do |element, index|
diag << element[index]
end
diag
end
boggle_board = BOGGLEBOARD.new(dice_grid) # creating the class object, boggle_board
p boggle_board.create_word(dice_grid, [2,1], [1,1], [1,2], [0,3]) #=> returns "code". Calling the create_word method on the object and printing it out to the screen
p boggle_board.create_word(dice_grid, [0,1], [0,2], [1,2]) #=> creates what california slang word?
p boggle_board.create_word(dice_grid,[1,2], [1,1], [2,1], [3,2]) #=> prints dock
p boggle_board.get_row(0) #=> returns first row. Calling the get_row method on object, obj and printing it out to the screen
p boggle_board.get_row(1)
p boggle_board.get_row(2)
p boggle_board.get_row(3)
p boggle_board.get_col(0)
p boggle_board.get_col(1)
p boggle_board.get_col(2)
p boggle_board.get_col(3)
p boggle_board.get_diag()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment