-
Notifications
You must be signed in to change notification settings - Fork 0
/
game.rb
47 lines (41 loc) · 1.13 KB
/
game.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
42
43
44
45
46
47
require_relative 'board'
require_relative 'display'
require_relative 'human_player'
class Game
def initialize
@board = Board.new
@display = Display.new(@board)
@player_one = HumanPlayer.new("player_one", :white, @display, @board)
@player_two = HumanPlayer.new("player_two", :black, @display, @board)
@current_player = @player_one
end
def play
system('clear')
puts "Zoom in for optimal gameplay."
puts "Use your arrow buttons to move your cursor."
puts "Press enter to select your starting/ending move."
sleep(4)
until @board.check_mate?(@current_player.color)
begin
@display.current_color = @current_player.color
start_pos, end_pos = @current_player.get_input
@board.move_piece(start_pos, end_pos, @current_player.color)
@display.selected_pos = nil
switch_players
rescue
print "Invalid Move"
@display.selected_pos = nil
sleep(1)
retry
end
end
end
private
def switch_players
if @current_player == @player_one
@current_player = @player_two
else
@current_player = @player_one
end
end
end