Sha256: f6a4234a2bd7b987343b11a3519ecbba3ff7c85e22ed1b3408ac2e021ad5961b

Contents?: true

Size: 697 Bytes

Versions: 2

Compression:

Stored size: 697 Bytes

Contents

# humanplayer.rb

require "game_tictactoe_alu4078/player"

module TicTacToe
  class HumanPlayer < Player
    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
    
    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
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
game-tictactoe-alu4078-0.0.2 lib/game_tictactoe_alu4078/humanplayer.rb
game-tictactoe-alu4078-0.0.1 lib/game_tictactoe_alu4078/humanplayer.rb