Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save chrisscherer/7716306 to your computer and use it in GitHub Desktop.
Save chrisscherer/7716306 to your computer and use it in GitHub Desktop.
phase 0 unit 2 week 1 boggle class challenge
class BoggleBoard
attr_reader :dice_grid
def initialize(dice_grid)
@dice_grid = dice_grid
end
def get_row(row)
print dice_grid[row]
puts ""
end
def get_col(col)
i = 0
ary = []
while i < dice_grid.size
#print "\"" + board[i][col] + "\", "
ary[i] = dice_grid[i][col]
i += 1
end
print ary
end
def create_word(*coords)
coords.map { |coord| dice_grid[coord.first][coord.last]}.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([1,2],[1,1],[2,1],[3,2])
k = 0
while k < 4
boggle_board.get_col(k)
boggle_board.get_row(k)
k += 1
end
# create driver test code to retrieve a value at a coordinate here:
puts boggle_board.create_word([3,2])
#review and reflect
#With methods being written in classes, everything is much easier to manipulate without the need to nitpick over each line of code. Changes can be made with simple rewrites of the original object or methods within the object
#Objects are much easier to reference than individual methods, and give the coder a better idea of what is happening in the code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment