-
Notifications
You must be signed in to change notification settings - Fork 0
/
player.rb
50 lines (40 loc) · 1.03 KB
/
player.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
require_relative 'hand'
class Player
attr_reader :bank, :name, :hand
def initialize(name = nil)
@name = name
@bank = 100
@hand = Hand.new
end
attr_writer :bank
def set_bet(sum)
self.bank > 0 ? self.bank -= sum : "no more money"
end
def get_money(sum, type = nil)
case type
when 'win'
puts 'You WIN !'
when 'tie'
puts 'Tie!'
end
self.bank += sum
end
def take_cart(cart)
@hand.cards_in_hand << cart
end
def show_hand
size = @hand.cards_in_hand.size
ranks = @hand.cards_in_hand.map(&:first)
suites = @hand.cards_in_hand.map(&:last)
puts "┌──────────┐ " * size
puts " %s " * size % ranks
puts "│ │ " * size
puts "│ │ " * size
puts " %s " * size % suites
puts "│ │ " * size
puts "│ │ " * size
puts " %s " * size % ranks
puts "└──────────┘ " * size
puts "\n SCORE - #{@hand.hand_sum}".red
end
end