Class: ConnectFour::Player
- Inherits:
-
Object
- Object
- ConnectFour::Player
- Defined in:
- lib/connect_four/player.rb
Overview
Player
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#sign ⇒ Object
readonly
Returns the value of attribute sign.
Instance Method Summary collapse
-
#initialize(sign) ⇒ Player
constructor
A new instance of Player.
- #input_move(board) ⇒ Object
- #input_name ⇒ Object
Constructor Details
#initialize(sign) ⇒ Player
Returns a new instance of Player.
9 10 11 12 |
# File 'lib/connect_four/player.rb', line 9 def initialize(sign) @name = nil @sign = sign end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/connect_four/player.rb', line 7 def name @name end |
#sign ⇒ Object (readonly)
Returns the value of attribute sign.
7 8 9 |
# File 'lib/connect_four/player.rb', line 7 def sign @sign end |
Instance Method Details
#input_move(board) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/connect_four/player.rb', line 18 def input_move(board) value = '10' until valid_move?(value, board) value = $stdin.gets.chomp # moving cursor in directions i want to print output print "\e[1A\e[#{@name.length + 9}C invalid_move try again. \e[36D" unless valid_move?(value, board) end value.to_i end |
#input_name ⇒ Object
14 15 16 |
# File 'lib/connect_four/player.rb', line 14 def input_name @name = gets.chomp end |