Class: TaTeTi::HumanPlayer

Inherits:
Player
  • Object
show all
Defined in:
lib/ta_te_ti/human_player.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 TaTeTi::Player

Instance Method Details

#finish(final_board) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/ta_te_ti/human_player.rb', line 16

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



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/ta_te_ti/human_player.rb', line 3

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