aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeddy Wing2015-04-14 17:57:55 -0400
committerTeddy Wing2015-04-14 17:57:55 -0400
commite6910571b4bb9f65a241df9ff28ff4cfbb832aa5 (patch)
tree1762dbea5cb9854c7e481b04cd45426222d1721a
parent231060de4c493a9c6ba3510a9be4d405517af5c6 (diff)
downloadtic-tac-toe-e6910571b4bb9f65a241df9ff28ff4cfbb832aa5.tar.bz2
Player: Add `initialize` method, use insignia constants
Add an `initialize` method to get rid of our test errors and use the constants we created in 231060de4c493a9c6ba3510a9be4d405517af5c6 when creating new `Player`s.
-rw-r--r--main.rb4
-rw-r--r--player.rb5
-rw-r--r--spec/player_spec.rb2
3 files changed, 8 insertions, 3 deletions
diff --git a/main.rb b/main.rb
index ad9eb72..dedf9f7 100644
--- a/main.rb
+++ b/main.rb
@@ -2,8 +2,8 @@ require_relative 'board'
require_relative 'player'
board = Board.new
-player_1 = Player.new('X', board)
-player_2 = Player.new('O', board)
+player_1 = Player.new(Player::INSIGNIAS[:x], board)
+player_2 = Player.new(Player::INSIGNIAS[:o], board)
board.current_player = player_1
until board.winner
diff --git a/player.rb b/player.rb
index 842e565..d19ee36 100644
--- a/player.rb
+++ b/player.rb
@@ -3,4 +3,9 @@ class Player
:x => 'X',
:o => 'O'
}
+
+ def initialize(insignia, board)
+ @insignia = insignia
+ @board = board
+ end
end
diff --git a/spec/player_spec.rb b/spec/player_spec.rb
index 3306095..4dee7e7 100644
--- a/spec/player_spec.rb
+++ b/spec/player_spec.rb
@@ -16,7 +16,7 @@ describe Player do
describe '#move' do
before do
board = Board.new
- @player = Player.new('X', board)
+ @player = Player.new(Player::INSIGNIAS[:x], board)
end
it 'raises an ArgumentError given invalid coordinates' do