Class: TresRaya::HumanPlayer
- Inherits:
-
Player
- Object
- Player
- TresRaya::HumanPlayer
show all
- Defined in:
- lib/tres_raya/human_player.rb
Instance Attribute Summary
Attributes inherited from Player
#mark
Instance Method Summary
collapse
Methods inherited from Player
#initialize
Instance Method Details
#finish(final_board) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/tres_raya/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/tres_raya/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
|