Forked from dbc-challenges/0.2.1-boggle_class_from_methods.rb
Last active
August 29, 2015 13:56
-
-
Save midorineko/9168174 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
#my goal is to save the grid in initialize | |
#then refer to the grid directly, thus removing one of my necessary variables to call | |
#I liked the math simon and I developed so I want to keep that as similar as possible | |
dice_grid = [["b", "r", "a", "e"], | |
["i", "o", "d", "t"], | |
["e", "c", "l", "r"], | |
["t", "a", "k", "e"]] | |
class BoggleBoard | |
def initialize(dice_grid) | |
@dice_grid = dice_grid | |
print 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] | |
end | |
def get_col(col) | |
@dice_grid.flatten.each_with_index {|obj, int| puts obj if int % 4 == col } | |
end | |
end | |
boggle_board = BoggleBoard.new(dice_grid) | |
print boggle_board.create_word([1,2], [1,1], [2,1], [3,2]) | |
print boggle_board.get_row(0) | |
print boggle_board.get_row(1) | |
print boggle_board.get_row(2) | |
print boggle_board.get_row(3) | |
print boggle_board.get_col(0) | |
print boggle_board.get_col(1) | |
print boggle_board.get_col(2) | |
print boggle_board.get_col(3) | |
print boggle_board.create_word([3,2]) | |
# implement tests for each of the methods here: | |
# create driver test code to retrieve a value at a coordinate here: | |
#actually i liked this implimentation better, i didnt have to call boggle_board every method | |
#i only had to refer to the class that already had the board saved in it | |
#I was able to use this code with any board, thus boggle boards can change and the code will still work | |
#I liked this test I learned a lot about makinga class and writing tests |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment