Class: TicTacToe::PlayerList
- Inherits:
-
Object
- Object
- TicTacToe::PlayerList
- Includes:
- Enumerable
- Defined in:
- lib/tic_tac_toe/player.rb
Constant Summary collapse
- AVAILABLE_PLAYERS =
[ Player.new("x", :red), Player.new("○", :blue), Player.new("△", :yellow), Player.new("□", :green), Player.new("◇", :magenta), ]
Instance Method Summary collapse
- #colors ⇒ Object
- #current ⇒ Object
- #each(&block) ⇒ Object
-
#initialize(number) ⇒ PlayerList
constructor
A new instance of PlayerList.
- #next! ⇒ Object
Constructor Details
#initialize(number) ⇒ PlayerList
Returns a new instance of PlayerList.
15 16 17 18 |
# File 'lib/tic_tac_toe/player.rb', line 15 def initialize(number) @players = AVAILABLE_PLAYERS.first(number) @current_idx = 0 end |
Instance Method Details
#colors ⇒ Object
32 33 34 35 36 |
# File 'lib/tic_tac_toe/player.rb', line 32 def colors @players.inject({}) do |colors, player| colors.update(player.symbol => player.color) end end |
#current ⇒ Object
24 25 26 |
# File 'lib/tic_tac_toe/player.rb', line 24 def current @players[@current_idx] end |
#each(&block) ⇒ Object
20 21 22 |
# File 'lib/tic_tac_toe/player.rb', line 20 def each(&block) @players.each(&block) end |
#next! ⇒ Object
28 29 30 |
# File 'lib/tic_tac_toe/player.rb', line 28 def next! @current_idx = (@current_idx + 1) % @players.count end |