Class: TexasHoldem::Player

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cash) ⇒ Player

Returns a new instance of Player.



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

def initialize(name,cash)
  @name, @cash = name, cash
  @cards = []
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



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

def cards
  @cards
end

#cashObject (readonly)

Returns the value of attribute cash.



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

def cash
  @cash
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

Instance Method Details

#bet(amount) ⇒ Object

Raises:



15
16
17
18
19
20
21
22
# File 'lib/player.rb', line 15

def bet(amount)
  # TODO: add remaining cash instead of raising an error
  raise NotEnoughCashError unless enough_cash_for?(amount)
  @cash -= amount
  changed true
  notify_observers :bet => { :player => self, :amount => amount }
  amount
end

#checkObject



24
25
26
# File 'lib/player.rb', line 24

def check
  bet 0
end

#foldObject



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

def fold
  changed true
  notify_observers :fold => true
end

#take_winnings(amount) ⇒ Object



33
34
35
# File 'lib/player.rb', line 33

def take_winnings(amount)
  @cash += amount
end