Class: Player
- Inherits:
-
Object
- Object
- Player
- Defined in:
- lib/player.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#nickname ⇒ Object
Returns the value of attribute nickname.
Instance Method Summary collapse
- #delete_card(card) ⇒ Object
- #display_cards ⇒ Object
- #display_posible_moves ⇒ Object
-
#initialize(nickname = nil) ⇒ Player
constructor
A new instance of Player.
- #play(n) ⇒ Object
- #posible_moves ⇒ Object
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
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
2 3 4 |
# File 'lib/player.rb', line 2 def cards @cards end |
#nickname ⇒ Object
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_cards ⇒ Object
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_moves ⇒ Object
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_moves ⇒ Object
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 |