Class: BareGato::Game
- Inherits:
-
Object
- Object
- BareGato::Game
- Defined in:
- lib/bare_gato/game.rb
Instance Attribute Summary collapse
-
#strategies ⇒ Object
Returns the value of attribute strategies.
Instance Method Summary collapse
- #got_a_winner? ⇒ Boolean
- #includes_player?(player) ⇒ Boolean
-
#initialize(args) ⇒ Game
constructor
A new instance of Game.
- #next ⇒ Object
- #next?(player) ⇒ Boolean
- #play(move) ⇒ Object
- #status ⇒ Object
Constructor Details
#initialize(args) ⇒ Game
Returns a new instance of Game.
5 6 7 8 9 10 11 12 |
# File 'lib/bare_gato/game.rb', line 5 def initialize args @grid = [ [nil, nil, nil], [nil, nil, nil], [nil, nil, nil], ] @players = args[:players] end |
Instance Attribute Details
#strategies ⇒ Object
Returns the value of attribute strategies.
3 4 5 |
# File 'lib/bare_gato/game.rb', line 3 def strategies @strategies end |
Instance Method Details
#got_a_winner? ⇒ Boolean
18 19 20 21 22 23 |
# File 'lib/bare_gato/game.rb', line 18 def got_a_winner? !!strategies.find do |strategy_class| strategy = strategy_class.new @grid strategy.winner? end end |
#includes_player?(player) ⇒ Boolean
14 15 16 |
# File 'lib/bare_gato/game.rb', line 14 def includes_player? player @players.include? player end |
#next ⇒ Object
25 26 27 |
# File 'lib/bare_gato/game.rb', line 25 def next @players.last end |
#next?(player) ⇒ Boolean
29 30 31 |
# File 'lib/bare_gato/game.rb', line 29 def next? player @players.last == player end |
#play(move) ⇒ Object
33 34 35 36 37 |
# File 'lib/bare_gato/game.rb', line 33 def play move raise "Unexpected player moving" unless next? move.player @grid[move.y][move.x] = move.player @players.reverse! end |
#status ⇒ Object
39 40 41 42 43 44 |
# File 'lib/bare_gato/game.rb', line 39 def status { game: @grid, next: self.next } end |