Class: OXO::Human

Inherits:
Object
  • Object
show all
Defined in:
lib/oxo/human.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(color) ⇒ Human

Returns a new instance of Human.



8
9
10
# File 'lib/oxo/human.rb', line 8

def initialize(color)
  @color = color
end

Instance Attribute Details

#colorObject (readonly)

Returns the value of attribute color.



6
7
8
# File 'lib/oxo/human.rb', line 6

def color
  @color
end

Instance Method Details

#make_move(board) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/oxo/human.rb', line 16

def make_move(board)
  move = :illegal

  while move == :illegal
    print "Your move (1...9, 0/q=quit)? "
    answer = gets.chomp

    move = parse_answer(answer, board)

    puts "Illegal move: #{answer}"  if move == :illegal
  end

  move
end

#nameObject



12
13
14
# File 'lib/oxo/human.rb', line 12

def name
  "Human"
end