-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplayer.rb
More file actions
executable file
·56 lines (45 loc) · 1.04 KB
/
Copy pathplayer.rb
File metadata and controls
executable file
·56 lines (45 loc) · 1.04 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
#!/usr/bin/ruby
require_relative './object.rb'
# player.rb
class Player
attr_accessor :cards, :money, :index, :bet, :score, :name, :status
def initialize(money, name)
self.money = (money.number? ? money : 0)
self.cards = []
self.index = nil
self.bet = 0
self.score = 0
self.name = name
self.status = ''
end
def add_money(money)
self.money += money if money.number?
end
def place_bet(money)
if money.number? && (self.money - money) >= 0
self.money -= money
self.bet += money
true
else
false
end
end
def add_card(card)
num_cards = cards.length
cards << card if card.class.name.to_s == 'Card' && card.valid?
num_cards != cards.length
end
def remove_cards
cards = self.cards
self.cards = []
cards
end
def to_s
cards = ''
self.cards.each_with_index do |card, index|
cards += card.to_s
cards += ', ' if index != self.cards.length - 1
end
"#{name} has #{cards}#{(!status.empty? ? ' and ' + status : '')}"
end
end