Class: TicTacToe::Player

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#colorObject (readonly)

Returns the value of attribute color.



18
19
20
# File 'lib/tic_tac_toe.rb', line 18

def color
  @color
end

#nameObject (readonly)

Returns the value of attribute name.



18
19
20
# File 'lib/tic_tac_toe.rb', line 18

def name
  @name
end

#symbolObject (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

#winsObject



28
29
30
# File 'lib/tic_tac_toe.rb', line 28

def wins
  puts "#{name} wins!"
end