Class: Player

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

Direct Known Subclasses

Vira

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nickname = nil) ⇒ Player

Returns a new instance of Player.



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

def initialize(nickname=nil)
  @cards = Array.new
  @nickname = nickname
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



2
3
4
# File 'lib/player.rb', line 2

def cards
  @cards
end

#nicknameObject

Returns the value of attribute nickname.



3
4
5
# File 'lib/player.rb', line 3

def nickname
  @nickname
end

Instance Method Details

#delete_card(card) ⇒ Object



42
43
44
# File 'lib/player.rb', line 42

def delete_card(card)
  cards.delete_if { |x| x == card }
end

#display_cardsObject



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

def display_cards
  cards.each do |card|
    puts card.suit.to_s + " " + card.value.to_s
  end
  nil
end

#display_posible_movesObject



28
29
30
31
32
33
# File 'lib/player.rb', line 28

def display_posible_moves
  posible_moves.each_pair do |k,v|
    puts "#{k} | #{v.to_s}"
  end
  nil
end

#play(n) ⇒ Object



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

def play(n)
  card = posible_moves[n]
  cards.reject!{ |c| c == card }
  card
end

#posible_movesObject



20
21
22
23
24
25
26
# File 'lib/player.rb', line 20

def posible_moves
  h = Hash.new
  cards.count.times do |n|
    h[n + 1] = cards[n]
  end
  h
end