Class: TicTacToe::Game

Inherits:
Object
  • Object
show all
Defined in:
lib/tic_tac_toe/game.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGame

Returns a new instance of Game.



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

def initialize
  @board = Board.new
  @rules = Rules.new(@board)
  @computer_player = ComputerPlayer.new
  @marks = ["X", "O"]
end

Instance Attribute Details

#boardObject (readonly)

Returns the value of attribute board.



5
6
7
# File 'lib/tic_tac_toe/game.rb', line 5

def board
  @board
end

#computer_playerObject (readonly)

Returns the value of attribute computer_player.



5
6
7
# File 'lib/tic_tac_toe/game.rb', line 5

def computer_player
  @computer_player
end

Instance Method Details

#get_mark_at(position) ⇒ Object



24
25
26
# File 'lib/tic_tac_toe/game.rb', line 24

def get_mark_at(position)
  @board.get_mark_at(position)
end

#in_progress?Boolean

Returns:

  • (Boolean)


14
15
16
17
# File 'lib/tic_tac_toe/game.rb', line 14

def in_progress?
  return false if winner || tie
  return true
end

#move(position) ⇒ Object



19
20
21
22
# File 'lib/tic_tac_toe/game.rb', line 19

def move(position)
  @board.set_mark(current_mark, position)
  change_current_mark
end

#tieObject



32
33
34
# File 'lib/tic_tac_toe/game.rb', line 32

def tie
  @rules.tie
end

#winnerObject



28
29
30
# File 'lib/tic_tac_toe/game.rb', line 28

def winner
  @rules.winner
end