Class: FortuneTeller::Game
- Inherits:
-
Object
- Object
- FortuneTeller::Game
- Defined in:
- lib/fortune_teller/game.rb
Constant Summary collapse
- DEFAULT_SELECTION_GROUPS =
[ lambda { Chooser.subset([ "dog", "chicken", "mouse", "cat", "dragon", "turtle", "tiger", "snake", "monkey" ], 4) }, lambda { Chooser.subset([ "3", "9", "5", "7", "10", "27", "100" ], 4) }, lambda { Chooser.subset([ "pink", "green", "blue", "yellow" ], 2) }, ].freeze
- DEFAULT_FORTUNES =
[ "Oops, you're in Jail!", "Yuck, you're in the mud!", "Wow, you get a cookie!", "Ouch, you got bit!", "Hey, you get a hug!", ].freeze
Instance Attribute Summary collapse
-
#chooser_class ⇒ Object
readonly
Returns the value of attribute chooser_class.
-
#chooser_options ⇒ Object
readonly
Returns the value of attribute chooser_options.
-
#fortunes ⇒ Object
readonly
Returns the value of attribute fortunes.
-
#panel_class ⇒ Object
readonly
Returns the value of attribute panel_class.
-
#reveal_class ⇒ Object
readonly
Returns the value of attribute reveal_class.
-
#selection_groups ⇒ Object
readonly
Returns the value of attribute selection_groups.
-
#ui ⇒ Object
readonly
Returns the value of attribute ui.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(selection_groups, fortunes, options = {}) ⇒ Game
constructor
A new instance of Game.
- #reset ⇒ Object
- #restart ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(selection_groups, fortunes, options = {}) ⇒ Game
Returns a new instance of Game.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/fortune_teller/game.rb', line 29 def initialize( selection_groups, fortunes, = {} ) @original_selection_groups = selection_groups @original_fortunes = fortunes @ui = [:ui] || CliUi.new(:game => self) @chooser_class = [:choose_class] || Chooser @reveal_class = [:reveal_class] || Reveal @panel_class = [:panel_class] || Panel @chooser_options = [:chooser_options] || {} @chooser_options[:ui] ||= ui reset end |
Instance Attribute Details
#chooser_class ⇒ Object (readonly)
Returns the value of attribute chooser_class.
26 27 28 |
# File 'lib/fortune_teller/game.rb', line 26 def chooser_class @chooser_class end |
#chooser_options ⇒ Object (readonly)
Returns the value of attribute chooser_options.
27 28 29 |
# File 'lib/fortune_teller/game.rb', line 27 def @chooser_options end |
#fortunes ⇒ Object (readonly)
Returns the value of attribute fortunes.
25 26 27 |
# File 'lib/fortune_teller/game.rb', line 25 def fortunes @fortunes end |
#panel_class ⇒ Object (readonly)
Returns the value of attribute panel_class.
26 27 28 |
# File 'lib/fortune_teller/game.rb', line 26 def panel_class @panel_class end |
#reveal_class ⇒ Object (readonly)
Returns the value of attribute reveal_class.
26 27 28 |
# File 'lib/fortune_teller/game.rb', line 26 def reveal_class @reveal_class end |
#selection_groups ⇒ Object (readonly)
Returns the value of attribute selection_groups.
25 26 27 |
# File 'lib/fortune_teller/game.rb', line 25 def selection_groups @selection_groups end |
#ui ⇒ Object (readonly)
Returns the value of attribute ui.
28 29 30 |
# File 'lib/fortune_teller/game.rb', line 28 def ui @ui end |
Class Method Details
.run(options = {}) ⇒ Object
19 20 21 22 23 |
# File 'lib/fortune_teller/game.rb', line 19 def self.run( = {} ) [:selection_groups] ||= DEFAULT_SELECTION_GROUPS.map(&:call) [:fortunes] ||= DEFAULT_FORTUNES new( .delete(:selection_groups), .delete(:fortunes), ).run end |
Instance Method Details
#reset ⇒ Object
49 50 51 52 |
# File 'lib/fortune_teller/game.rb', line 49 def reset @fortunes = @original_fortunes.dup @selection_groups = @original_selection_groups.dup end |
#restart ⇒ Object
44 45 46 47 |
# File 'lib/fortune_teller/game.rb', line 44 def restart reset run end |
#run ⇒ Object
54 55 56 |
# File 'lib/fortune_teller/game.rb', line 54 def run chooser_tree.choose end |