Class: Tictactoe::HumanPlayer

Inherits:
Player
  • Object
show all
Defined in:
lib/tictactoe/humanplayer.rb

Instance Attribute Summary

Attributes inherited from Player

#mark

Instance Method Summary collapse

Methods inherited from Player

#initialize

Constructor Details

This class inherits a constructor from Tictactoe::Player

Instance Method Details

#finish(final_board) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/tictactoe/humanplayer.rb', line 21

def finish( final_board )
  print final_board
  
  if final_board.won? == @mark
    print "Congratulations, you win.\n\n"
  elsif final_board.won? == " "
    print "Tie game.\n\n"
  else
    print "You lost tic-tac-toe?!\n\n"
  end
end

#move(board) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/tictactoe/humanplayer.rb', line 8

def move( board )
  print board
  
  moves = board.moves
  print "Your move?  (format: b3)  "
  move = $stdin.gets
  until moves.include?(move.chomp.downcase)
    print "Invalid move.  Try again.  "
    move = $stdin.gets
  end
  move.chomp
end