Created
June 6, 2013 22:53
-
-
Save supertopher/5725669 to your computer and use it in GitHub Desktop.
Call a boggle grid of any size with random dice movement.
This file contains 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 | |
# because we wanted to | |
def initialize (board_size = 4) | |
@board_size = board_size | |
shake! | |
end | |
def shake! | |
possible_dice = [ | |
"AAEEGN", | |
"ELRTTY", | |
"AOOTTW", | |
"ABBJOO", | |
"EHRTVW", | |
"CIMOTU", | |
"DISTTY", | |
"EIOSST", | |
"DELRVY", | |
"ACHOPS", | |
"HIMNQU", | |
"EEINSU", | |
"EEGHNW", | |
"AFFKPS", | |
"HLNNRZ", | |
"DEILRX" | |
] | |
random_list = [] | |
total_spaces = @board_size**2 | |
total_spaces.times do | |
# random die finds one random dice | |
random_die = possible_dice.shuffle.first | |
# one random letter from the random die is added to the list | |
random_list << random_die.each_char.to_a.shuffle.first | |
end | |
@board = Array.new(@board_size) { random_list.shift(@board_size) } | |
to_s | |
end | |
def to_s | |
puts "BOGGLE!" | |
liner = " " | |
@board_size.times do | |
liner += "-" | |
end | |
puts liner | |
@board_size.times do |x_position| | |
print "|" | |
@board_size.times do |y_position| | |
if @board[x_position][y_position] != "Q" | |
print @board[x_position][y_position] | |
else | |
print "Qu" | |
end | |
end | |
print "|" | |
puts | |
end | |
puts liner | |
end | |
end | |
puts "Calling new Boggle to variable fun_awesome_time" | |
fun_awesome_time = BoggleBoard.new | |
puts "Calling shake! (which also calls to_s)" | |
fun_awesome_time.shake! | |
puts "Calling a 17 Grid board to fun_awesome_time" | |
fun_awesome_time = BoggleBoard.new(17) | |
puts "Calling to_s alone" | |
fun_awesome_time.to_s | |
# Qu works | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment