Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save mario10king/9840586 to your computer and use it in GitHub Desktop.
Save mario10king/9840586 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1boggle class challenge
class BoggleBoard
def initialize(dice_grid)
@dice_grid=dice_grid
end
def create_word(*coords)
coords.map { |coord| @dice_grid[coord.first][coord.last]}.join("")
end
def get_row(row)
@dice_grid[row].join""
end
def get_col(col)
column=[]
i=0
while i<4
column[i]=@dice_grid[i][col]
i+=1
end
return column.join""
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:
puts boggle_board.create_word([2,1], [1,1], [1,2], [0,3]) #=>code
puts boggle_board.get_col(0) #=>biet
puts boggle_board.get_col(1) #=>roca
puts boggle_board.get_col(2) #=>adlk
puts boggle_board.get_col(3) #=>etre
puts boggle_board.get_row(0) #=>brae
puts boggle_board.get_row(1) #=>iodt
puts boggle_board.get_row(2) #=>eclr
puts boggle_board.get_row(3) #=>take
# create driver test code to retrieve a value at a coordinate here:
puts boggle_board.create_word([2,1]) #=>c
#REFLECTION
# I feel that since I'm barely startting to learn the principal
# of object-oriented programming the actual programming part of
# it is a little harder than what I'm used to. I think the advantages
#of this method are that the conceptcs are actually easier to understand
# ,they are just a little harder to implement. I think another advantage
# is that games like this one make sense doing it this way because you can
# just create a different grid and not have to change anything else to play
# a new game.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment