Class: TicTacToe::Player
- Inherits:
-
Object
- Object
- TicTacToe::Player
- Defined in:
- lib/tic_tac_toe.rb
Overview
STYLE = :off # Use this if your terminal output looks gibberish if STYLE == :on
Constant Summary collapse
- COLOR_SET =
[*(31..36)].cycle
- @@num_of_registered_players =
0
- @@color =
COLOR_SET.each
Instance Attribute Summary collapse
-
#color ⇒ Object
readonly
Returns the value of attribute color.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#symbol ⇒ Object
readonly
Returns the value of attribute symbol.
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Player
constructor
A new instance of Player.
- #wins ⇒ Object
Constructor Details
#initialize(params = {}) ⇒ Player
Returns a new instance of Player.
20 21 22 23 24 25 26 |
# File 'lib/tic_tac_toe.rb', line 20 def initialize params = {} @@num_of_registered_players += 1 @color = @@color.next @name = params[:name] || "Player " + @@num_of_registered_players.to_s symbol = params[:symbol] @symbol = STYLE == :off ? symbol : "\e[#{color}m#{symbol}\e[0m" end |
Instance Attribute Details
#color ⇒ Object (readonly)
Returns the value of attribute color.
18 19 20 |
# File 'lib/tic_tac_toe.rb', line 18 def color @color end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
18 19 20 |
# File 'lib/tic_tac_toe.rb', line 18 def name @name end |
#symbol ⇒ Object (readonly)
Returns the value of attribute symbol.
18 19 20 |
# File 'lib/tic_tac_toe.rb', line 18 def symbol @symbol end |
Instance Method Details
#wins ⇒ Object
28 29 30 |
# File 'lib/tic_tac_toe.rb', line 28 def wins puts "#{name} wins!" end |