-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhumanplayer.rb
41 lines (37 loc) · 940 Bytes
/
humanplayer.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
require_relative "board"
require_relative "display"
class HumanPlayer < Player
def initialize(board, color, display)
super(board, color)
@display = display
end
def move
@display.reset
start_pos = @display.move
@display.show_options(start_pos)
end_pos = @display.move
@board.move(start_pos, end_pos)
@display.reset
@board.swap_color
rescue NoPieceError
puts "There's no piece there, try again!"
sleep(1)
retry
rescue CantMoveIntoCheckError
puts "You can't move yourself into check, try again!"
sleep(1)
retry
rescue InvalidMoveError
puts "Invalid move, try again!"
sleep(1)
retry
rescue CannotCastleInCheckError
puts "You cannot castle when you are in check, try again!"
sleep(1)
retry
rescue WrongColorError
puts "It's not your turn! Hand over the keyboard!"
sleep(1)
retry
end
end