Class: LocalChessClient
- Inherits:
-
Object
- Object
- LocalChessClient
- Defined in:
- lib/local_chess_client.rb
Instance Method Summary collapse
-
#initialize ⇒ LocalChessClient
constructor
A new instance of LocalChessClient.
- #start ⇒ Object
Constructor Details
#initialize ⇒ LocalChessClient
Returns a new instance of LocalChessClient.
11 12 13 14 15 16 17 |
# File 'lib/local_chess_client.rb', line 11 def initialize @board = Board.new @turn_by_turn_playback = [] @board.display_board start end |
Instance Method Details
#start ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/local_chess_client.rb', line 19 def start # Gameplay loop do if @board.checkmate puts "\nTurn by Turn Playback : #{@turn_by_turn_playback}\n" exit end print "\nPiece to Move [#{@board.player_turn.capitalize}]: " from = gets.chomp.upcase begin print "Valid destinations: #{@board.valid_destinations(from).join(", ")}" print "\nLocation: " to = gets.chomp.upcase @board.move(from, to) rescue Exception => e puts "Invalid selection #{e if !ENV["DEV"].nil?}" else @turn_by_turn_playback << [from, to] end end end |