-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.rb
More file actions
66 lines (57 loc) · 1.1 KB
/
user.rb
File metadata and controls
66 lines (57 loc) · 1.1 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require_relative 'hand'
class User
attr_accessor :name, :money, :check_available, :cards, :hand
def initialize(name, hand)
@name = name
@money = 100
@hand = hand
new_game
end
def new_game
make_bet
@check_available = true
@cards = []
get_card(2)
end
def points
calculate_points
end
def make_bet
if @money - 10 >= 0
@money -= 10
else
raise 'no more money'
end
end
def add_money(cash = 20)
@money += cash
end
def print_cards
@cards.each {|card| puts card}
end
def get_card(n=1)
if @cards.size < 3
#@cards.concat(hand.deck.get_card(n))
@cards.push(*hand.deck.get_card(n))
calculate_points
else
raise 'max cards count reached'
end
end
def calculate_points
points = @cards[0].count
#значение очков туза == 11
@cards[1..-1].each do |card|
if card.name == "A" && points + card.count > 21
points +=1
else
points += card.count
end
end
points
end
#пропустить
def check
@check_available = false
end
end