Class: Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Indexable

#index_column

Constructor Details

#initialize(board) ⇒ Player

Returns a new instance of Player.



8
9
10
11
12
# File 'lib/player.rb', line 8

def initialize(board)
  @name = nil
  @player_piece = 'x'
  @board = board
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#player_pieceObject (readonly)

Returns the value of attribute player_piece.



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

def player_piece
  @player_piece
end

Instance Method Details

#assign_player_name(name) ⇒ Object



35
36
37
# File 'lib/player.rb', line 35

def assign_player_name(name)
  @name = name
end

#player_turn(board) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/player.rb', line 14

def player_turn(board)
  puts "Choose which column A-G to place your piece."
  column = gets.chomp.upcase
  until @board.valid_column(column) == true
    puts "Choose which column A-G to place your piece."
    column = gets.chomp.upcase
  end
  integer = index_column(column)
  until @board.column_full(integer) == false
    puts "This column is full. Select another column."
    column = gets.chomp.upcase
    until @board.valid_column(column) == true
      puts "Choose which column A-G to place your piece."
      column = gets.chomp.upcase
    end
    # column = gets.chomp.upcase
  integer = index_column(column)
  end
  board.drop_disc(integer, @player_piece)
end