Class: ConnectFour::Player

Inherits:
Object
  • Object
show all
Defined in:
lib/connect_four/player.rb

Overview

Player

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/connect_four/player.rb', line 7

def name
  @name
end

#signObject (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_nameObject



14
15
16
# File 'lib/connect_four/player.rb', line 14

def input_name
  @name = gets.chomp
end