1 #zatial zjednodusene pravidla:
8 class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; end
12 attr_accessor :a, :cards, :pk, :name#, :bet
13 # pk - Poradie v Kartach
15 self.a = [2,3,4,5,6,7,8,9,10,10,10,10,11] * 4
23 self.cards[self.pk] = self.a.delete_at(self.a.index(self.a.sample))
24 if self.cards[self.pk] == 11 and self.cards.sum > 21 then
25 if self.cards.sum - 11 + 1 <= 21#eso nahradim za 1
26 self.cards[self.pk] = 1
29 self.pk = self.pk.next
33 puts "\b \n#{self.name} has #{self.cards.sum}"
37 self.cards[self.pk] = self.a.delete_at(self.a.index(self.a.sample))
38 if self.cards[self.pk] == 11 and self.cards.sum > 21 then
39 if self.cards.sum - 11 + 1 <= 21#eso nahradim za 1
40 self.cards[self.pk] = 1
43 self.pk = self.pk.next
45 # if not self.cards[self.cards.index(x)+1] # == nil :)
53 # puts "#{self.name} has #{self.cards.sum}"
55 if self.check and ask == true then p self.cards; puts "#{self.name} has #{self.cards.sum}"; self.askMe
56 elsif not self.check then
57 if @@on.cards.length == 1 then @@on.hit(false)
58 else p self.cards; results(@@on.cards.sum,@@ja.cards.sum)
60 else self.stay(@@ja.cards.sum) #probably now's playing The Dealer!
65 if self.cards.sum > 21
75 if self.cards.length == 2
76 more = "3. Double down"
79 if self.cards.length == 2 and self.cards[0] == self.cards[1]
80 more = more + "\n 4. Split"
81 avail = [1,2,"dd","split"]
87 if i == 1 then self.hit(true)
88 elsif i == 2 then @@on.stay(@@ja.cards.sum)
89 elsif avail[2] == "dd" then
92 #puts "#{self.name}'s bet is #{self.bet}"
93 #puts "Dunno what's bet"
95 @@on.stay(@@ja.cards.sum)
97 elsif avail[3] == "split" then
98 if i == 4 then return "I don't know this feature so far..." end
104 onSum = self.cards.sum
106 onSum >= 17 then p self.cards; puts "#{self.name} has #{self.cards.sum}"; results(onSum,jaSum)
108 onSum >= 2 and onSum <= 15 then self.hit(false)
110 onSum - jaSum >= 10 then p self.cards; puts "#{self.name} has #{self.cards.sum}"; results(onSum,jaSum)
112 onSum - jaSum < 10 then self.hit(false)
114 puts "Error occurred"
120 def results(onSum,jaSum)
121 print "You have: #{@@ja.cards.sum} ="
123 print "Dealer has: #{@@on.cards.sum} ="
126 if onSum > 21 and jaSum > 21 then puts "You lost the game"
127 elsif onSum > 21 and jaSum <= 21 then puts "Winner is: #{@@ja.name}"
128 elsif jaSum > 21 and onSum <= 21 then puts "Winner is: #{@@on.name}"
129 elsif jaSum == 21 and onSum == 21 and @@ja.cards.sum == 2 and @@on.cards.sum != 2 then "Blackjack!"
131 if onSum < jaSum then puts "Winner is: #{@@ja.name}"
132 elsif onSum > jaSum then puts "Winner is: #{@@on.name}"
136 puts "-----------\nWanna play again?"
139 if ans == "y" or ans == "Y" then playGame
140 elsif ans == "n" or ans == "N" then exit
147 #puts "#{@@ja.name}'s bet is #{@@ja.bet}\n----\n"
150 @@ja = Players.new(" Frankie ")
151 @@on = Players.new(" Dealer ")