Class: TicTacToe

Inherits:
Object
  • Object
show all
Defined in:
lib/tic_tac_toe.rb,
lib/tic_tac_toe/tui.rb,
lib/tic_tac_toe/board.rb,
lib/tic_tac_toe/rules.rb,
lib/tic_tac_toe/cursor.rb,
lib/tic_tac_toe/player.rb,
lib/tic_tac_toe/tui/board.rb,
lib/tic_tac_toe/tui/setup.rb,
lib/tic_tac_toe/tui/cursor.rb,
lib/tic_tac_toe/tui/status.rb

Defined Under Namespace

Classes: Board, Cursor, Player, PlayerList, Rules, TUI

Instance Method Summary collapse

Constructor Details

#initialize(size: 3, number_of_players: 2, goal: 3) ⇒ TicTacToe

Returns a new instance of TicTacToe.



8
9
10
11
12
13
# File 'lib/tic_tac_toe.rb', line 8

def initialize(size: 3, number_of_players: 2, goal: 3)
  @board   = TicTacToe::Board.new(size)
  @players = TicTacToe::PlayerList.new(number_of_players)
  @cursor  = TicTacToe::Cursor.new(@board)
  @rules   = TicTacToe::Rules.new(goal)
end

Instance Method Details

#startObject



15
16
17
18
19
20
21
22
# File 'lib/tic_tac_toe.rb', line 15

def start
  @tui = TicTacToe::TUI.new
  setup

  @tui.listen do |key|
    handle_keypress(key) unless game_over?
  end
end