-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.rb
More file actions
46 lines (34 loc) · 823 Bytes
/
game.rb
File metadata and controls
46 lines (34 loc) · 823 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
36
37
38
39
40
41
42
43
44
45
46
require "./board"
require "./pieces"
require './player'
class Game
def initialize(player1,player2)
@players = [player1, player2]
@board = Board.new(true)
end
def turn(player)
move=player.choose_movement
raise InvalideMoveError, "That's not you" if @board[move[0]] && @board[move[0]].color != player.color
@board.move(move)
end
def play
while !@board.over?
begin
system "clear"
print @board
puts "#{@players.first} is your turn!"
turn(@players.first)
rescue InvalideMoveError => e
p e.message
p "Try again, press return"
gets
retry
end
@players.rotate!
end
p "Game Over"
print @board
end
end
g = Game.new(Player.new(:b), Player.new(:r))
g.play