Class: HumanPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/ttt_malisa/human_player.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mark, board, display) ⇒ HumanPlayer

Returns a new instance of HumanPlayer.



4
5
6
7
8
# File 'lib/ttt_malisa/human_player.rb', line 4

def initialize(mark, board, display)
  @board = board
  @display = display
  @mark = mark
end

Instance Attribute Details

#markObject (readonly)

Returns the value of attribute mark.



2
3
4
# File 'lib/ttt_malisa/human_player.rb', line 2

def mark
  @mark
end

Instance Method Details

#moveObject



10
11
12
13
14
# File 'lib/ttt_malisa/human_player.rb', line 10

def move
  @display.make_move_message(@mark)
  index = @display.retrieve_user_input.to_i - 1
  @board.valid_move?(index) ? @board.mark(index, @mark) : move
end