Skip to content

Commit ed3b24a

Browse files
committedFeb 29, 2016
Refactor and draft spec for Player
1 parent 2527bcb commit ed3b24a

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed
 

‎lib/models/game.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module RubyConnect
44
class Game
5-
attr_reader :board
5+
attr_accessor :board, :winning_move
66

77
def initialize(player1, player2)
88
@board = Board.new
@@ -12,13 +12,13 @@ def initialize(player1, player2)
1212
end
1313

1414
def done?
15-
board.full? || @winning_move
15+
board.full? || winning_move
1616
end
1717

1818
def make_move(column, color)
1919
raise GameOverError if done?
2020
board.insert_into_column column, color
21-
@winning_move = false # TODO: winning_move?
21+
winning_move = false # TODO: winning_move?
2222
end
2323
end
2424
end

‎lib/models/player.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
module RubyConnect
22
class Player
3+
attr_reader :game, :color
4+
35
def initialize(info = {})
46
@name = info[:name]
57
@phone_number = info[:phone_number]
68
@color = info[:color]
9+
@game = info[:game]
710
end
811

9-
def move(game, column)
10-
game.make_move(column, @color)
12+
def make_move(column)
13+
game.make_move(column, color)
1114
end
1215
end
1316
end

‎spec/models/player_spec.rb

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
module RubyConnect
44
describe Player do
5-
5+
let(:player) { Player.new color: :red, name: "John", game: 1 }
6+
7+
context '#make_move' do
8+
9+
end
610
end
711
end

0 commit comments

Comments
 (0)
Please sign in to comment.