Class: Tictactoe::Game
- Inherits:
-
Object
- Object
- Tictactoe::Game
- Defined in:
- lib/tictactoe/game.rb
Instance Attribute Summary collapse
-
#board_size ⇒ Object
Returns the value of attribute board_size.
-
#current_player ⇒ Object
Returns the value of attribute current_player.
-
#o_type ⇒ Object
Returns the value of attribute o_type.
-
#state ⇒ Object
Returns the value of attribute state.
-
#x_type ⇒ Object
Returns the value of attribute x_type.
Instance Method Summary collapse
- #available ⇒ Object
-
#initialize(players_factory, board_size, x_type, o_type) ⇒ Game
constructor
A new instance of Game.
- #is_finished? ⇒ Boolean
- #marks ⇒ Object
- #ready_to_tick? ⇒ Boolean
- #tick ⇒ Object
- #winner ⇒ Object
Constructor Details
#initialize(players_factory, board_size, x_type, o_type) ⇒ Game
Returns a new instance of Game.
10 11 12 13 14 15 16 |
# File 'lib/tictactoe/game.rb', line 10 def initialize(players_factory, board_size, x_type, o_type) self.players_factory = players_factory self.board_size = board_size self.x_type = x_type self.o_type = o_type reset end |
Instance Attribute Details
#board_size ⇒ Object
Returns the value of attribute board_size.
8 9 10 |
# File 'lib/tictactoe/game.rb', line 8 def board_size @board_size end |
#current_player ⇒ Object
Returns the value of attribute current_player.
7 8 9 |
# File 'lib/tictactoe/game.rb', line 7 def current_player @current_player end |
#o_type ⇒ Object
Returns the value of attribute o_type.
8 9 10 |
# File 'lib/tictactoe/game.rb', line 8 def o_type @o_type end |
#state ⇒ Object
Returns the value of attribute state.
7 8 9 |
# File 'lib/tictactoe/game.rb', line 7 def state @state end |
#x_type ⇒ Object
Returns the value of attribute x_type.
8 9 10 |
# File 'lib/tictactoe/game.rb', line 8 def x_type @x_type end |
Instance Method Details
#available ⇒ Object
42 43 44 |
# File 'lib/tictactoe/game.rb', line 42 def available state.available_moves end |
#is_finished? ⇒ Boolean
30 31 32 |
# File 'lib/tictactoe/game.rb', line 30 def is_finished? state.is_finished? end |
#marks ⇒ Object
38 39 40 |
# File 'lib/tictactoe/game.rb', line 38 def marks state.marks end |
#ready_to_tick? ⇒ Boolean
26 27 28 |
# File 'lib/tictactoe/game.rb', line 26 def ready_to_tick? !is_finished? && current_player.value.ready_to_move? end |
#tick ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/tictactoe/game.rb', line 18 def tick move = get_move if is_valid?(move) && !is_finished? update_state(move) advance_player end end |
#winner ⇒ Object
34 35 36 |
# File 'lib/tictactoe/game.rb', line 34 def winner state.winner end |