Last active
December 15, 2015 15:49
-
-
Save pjkelly/5284752 to your computer and use it in GitHub Desktop.
Generate a grid of squares for betting on a game.
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
require 'axis' | |
set = (0..9).to_a | |
top = Axis.new('Top Numbers', set.dup) | |
side = Axis.new('Side Numbers', set.dup) | |
top.generate_values! | |
side.generate_values! |
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
require 'lingo' | |
require 'roller' | |
class Axis | |
include Lingo | |
attr_reader :name | |
attr_accessor :set, :values | |
def initialize(name, set) | |
@name = name | |
@set = set | |
@values = [] | |
end | |
def generate_values! | |
lingo.speak(name) | |
while !self.set.empty? do | |
value, self.set = Roller.new(self.set).shoot! | |
self.values << value | |
end | |
lingo.speak(values.join(' ')) | |
lingo.silence | |
end | |
protected | |
def lingo | |
@lingo ||= Lingo.new | |
end | |
end |
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
module Lingo | |
def speak(words) | |
puts "==> #{words}" | |
end | |
def silence | |
puts | |
end | |
end |
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
class Roller | |
attr_reader :set | |
def initialize(set = []) | |
@set = set | |
end | |
def shoot! | |
shake_em_up | |
value = self.set.pop | |
return value, self.set | |
end | |
protected | |
def shake_em_up | |
self.set.shuffle! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment