-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.rb
More file actions
35 lines (28 loc) · 720 Bytes
/
game.rb
File metadata and controls
35 lines (28 loc) · 720 Bytes
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
require_relative 'board.rb'
require_relative 'human_player.rb'
require 'colorize'
class Game
def initialize
@board = Board.new
@white = HumanPlayer.new("white")
@black = HumanPlayer.new("black")
@current_player = @white
end
def play
until @board.checkmate?(@current_player.color)
@board.display
begin
move = @current_player.play_turn
@board.move(move["start"], move["end"], @current_player.color)
rescue ArgumentError => e
puts "Try again. #{e.message}"
retry
end
@current_player = @current_player == @white ? @black : @white
end
@board.display
puts "#{@current_player.color} lost!"
end
end
g = Game.new
g.play