Queen_Of_Diamonds 0.3-mswin32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. data/README +21 -0
  2. data/images/back.png +0 -0
  3. data/images/c10.png +0 -0
  4. data/images/c2.png +0 -0
  5. data/images/c3.png +0 -0
  6. data/images/c4.png +0 -0
  7. data/images/c5.png +0 -0
  8. data/images/c6.png +0 -0
  9. data/images/c7.png +0 -0
  10. data/images/c8.png +0 -0
  11. data/images/c9.png +0 -0
  12. data/images/ca.png +0 -0
  13. data/images/cj.png +0 -0
  14. data/images/ck.png +0 -0
  15. data/images/cq.png +0 -0
  16. data/images/d10.png +0 -0
  17. data/images/d2.png +0 -0
  18. data/images/d3.png +0 -0
  19. data/images/d4.png +0 -0
  20. data/images/d5.png +0 -0
  21. data/images/d6.png +0 -0
  22. data/images/d7.png +0 -0
  23. data/images/d8.png +0 -0
  24. data/images/d9.png +0 -0
  25. data/images/da.png +0 -0
  26. data/images/dj.png +0 -0
  27. data/images/dk.png +0 -0
  28. data/images/dq.png +0 -0
  29. data/images/h10.png +0 -0
  30. data/images/h2.png +0 -0
  31. data/images/h3.png +0 -0
  32. data/images/h4.png +0 -0
  33. data/images/h5.png +0 -0
  34. data/images/h6.png +0 -0
  35. data/images/h7.png +0 -0
  36. data/images/h8.png +0 -0
  37. data/images/h9.png +0 -0
  38. data/images/ha.png +0 -0
  39. data/images/hj.png +0 -0
  40. data/images/hk.png +0 -0
  41. data/images/hq.png +0 -0
  42. data/images/jx.png +0 -0
  43. data/images/s10.png +0 -0
  44. data/images/s2.png +0 -0
  45. data/images/s3.png +0 -0
  46. data/images/s4.png +0 -0
  47. data/images/s5.png +0 -0
  48. data/images/s6.png +0 -0
  49. data/images/s7.png +0 -0
  50. data/images/s8.png +0 -0
  51. data/images/s9.png +0 -0
  52. data/images/sa.png +0 -0
  53. data/images/sj.png +0 -0
  54. data/images/sk.png +0 -0
  55. data/images/sq.png +0 -0
  56. data/images/table.png +0 -0
  57. data/lib/Queen_Of_Diamonds.rb +174 -0
  58. data/lib/Queen_Of_Diamonds_no_graphics.rb +220 -0
  59. data/lib/gosu/gosu.so +0 -0
  60. data/lib/gosu/msvcp71.dll +0 -0
  61. data/lib/gosu/msvcr71.dll +0 -0
  62. data/lib/gosu/unicows.dll +0 -0
  63. data/samples/blackjack.rb +227 -0
  64. data/samples/pwnage.rb +43 -0
  65. metadata +113 -0
data/README ADDED
@@ -0,0 +1,21 @@
1
+ Queen Of Diamonds v0.3
2
+ Dirk Meijer
3
+ 17th April 2006
4
+
5
+ Queen Of Diamonds is released under:
6
+ GNU General Public License (GPL) version 3.
7
+
8
+ Queen Of Diamonds uses the gosu library v0.62
9
+ (http://www.raschke.de/julian/gosu/).
10
+
11
+ Queen Of Diamonds is a library that makes it easy
12
+ to create Windows-like card games.
13
+
14
+ ./samples/blackjack.rb is an example of a cardgame
15
+ without graphics (at the moment).
16
+
17
+ ./samples/pwnage.rb is an example that does use
18
+ graphics.
19
+
20
+ Enjoy it!
21
+ Dirk.
data/images/back.png ADDED
Binary file
data/images/c10.png ADDED
Binary file
data/images/c2.png ADDED
Binary file
data/images/c3.png ADDED
Binary file
data/images/c4.png ADDED
Binary file
data/images/c5.png ADDED
Binary file
data/images/c6.png ADDED
Binary file
data/images/c7.png ADDED
Binary file
data/images/c8.png ADDED
Binary file
data/images/c9.png ADDED
Binary file
data/images/ca.png ADDED
Binary file
data/images/cj.png ADDED
Binary file
data/images/ck.png ADDED
Binary file
data/images/cq.png ADDED
Binary file
data/images/d10.png ADDED
Binary file
data/images/d2.png ADDED
Binary file
data/images/d3.png ADDED
Binary file
data/images/d4.png ADDED
Binary file
data/images/d5.png ADDED
Binary file
data/images/d6.png ADDED
Binary file
data/images/d7.png ADDED
Binary file
data/images/d8.png ADDED
Binary file
data/images/d9.png ADDED
Binary file
data/images/da.png ADDED
Binary file
data/images/dj.png ADDED
Binary file
data/images/dk.png ADDED
Binary file
data/images/dq.png ADDED
Binary file
data/images/h10.png ADDED
Binary file
data/images/h2.png ADDED
Binary file
data/images/h3.png ADDED
Binary file
data/images/h4.png ADDED
Binary file
data/images/h5.png ADDED
Binary file
data/images/h6.png ADDED
Binary file
data/images/h7.png ADDED
Binary file
data/images/h8.png ADDED
Binary file
data/images/h9.png ADDED
Binary file
data/images/ha.png ADDED
Binary file
data/images/hj.png ADDED
Binary file
data/images/hk.png ADDED
Binary file
data/images/hq.png ADDED
Binary file
data/images/jx.png ADDED
Binary file
data/images/s10.png ADDED
Binary file
data/images/s2.png ADDED
Binary file
data/images/s3.png ADDED
Binary file
data/images/s4.png ADDED
Binary file
data/images/s5.png ADDED
Binary file
data/images/s6.png ADDED
Binary file
data/images/s7.png ADDED
Binary file
data/images/s8.png ADDED
Binary file
data/images/s9.png ADDED
Binary file
data/images/sa.png ADDED
Binary file
data/images/sj.png ADDED
Binary file
data/images/sk.png ADDED
Binary file
data/images/sq.png ADDED
Binary file
data/images/table.png ADDED
Binary file
@@ -0,0 +1,174 @@
1
+ =begin
2
+ name: Queen of Diamonds v0.3
3
+ author: Dirk Meijer
4
+ date: April 17th 2006
5
+ description: The graphic part of the app, almost ready!
6
+ =end
7
+
8
+ require "gosu/gosu"
9
+ require "Queen_Of_Diamonds_no_graphics"
10
+
11
+ class Table < Gosu::Window
12
+ attr_accessor(:hand, :visible_cards)
13
+
14
+ def initialize(hand=Deck.new, width=640, height=480, fullscreen=false , framerate=20, caption="Queen of Diamonds", background="#{File.dirname(__FILE__)}/../images/table.png")
15
+ raise TypeError.new unless caption.respond_to?(:to_s)
16
+ raise TypeError.new unless background.respond_to?(:to_s)
17
+ super(width, height, fullscreen, framerate)
18
+ self.caption=caption.to_s
19
+ @background=Gosu::Image.new(self, background, false)
20
+ @visible_cards=[]
21
+ @hand=hand
22
+ assign_images
23
+ end
24
+
25
+ def draw
26
+ @background.draw(0,0,0)
27
+ @visible_cards.each do |card|
28
+ card.draw
29
+ end
30
+ end
31
+
32
+ def update
33
+ @visible_cards.each do |card|
34
+ card.action
35
+ end
36
+ end
37
+
38
+ def assign_images
39
+ @hand.each do |card|
40
+ card.front=Gosu::Image.new(self, "#{File.dirname(__FILE__)}/../images/#{card.suit.to_s.downcase}#{card.value.to_s.downcase}.png", false)
41
+ card.back=Gosu::Image.new(self, "#{File.dirname(__FILE__)}/../images/back.png", false)
42
+ card.side=card.front
43
+ card.x = 0
44
+ card.y = 0
45
+ card.z = 1
46
+ card.zoom_x = 1
47
+ card.zoom_y = 1
48
+ card.angle = 1
49
+ card.movements=[]
50
+ end
51
+ true
52
+ end
53
+ end
54
+
55
+
56
+
57
+ class Card
58
+ attr_accessor(:x, :y, :zoom_x, :zoom_y, :z, :angle, :front, :back, :side, :movements)
59
+
60
+ def draw
61
+ @side.draw_rot(@x, @y, @z, @angle, 0.5, 0.5, @zoom_x, @zoom_y)
62
+ end
63
+
64
+ def action
65
+ @movements.each do |move|
66
+ @movements -= [move] if move.step
67
+ end
68
+ end
69
+
70
+ def new_slide(*args)
71
+ @movements<<Slide.new(self, *args)
72
+ end
73
+
74
+ def new_rotation(*args)
75
+ @movements<<Rotation.new(self, *args)
76
+ end
77
+
78
+ def new_flip(*args)
79
+ @movements<<Flip.new(self, *args)
80
+ end
81
+ end
82
+
83
+
84
+
85
+ class Slide
86
+ def initialize(card, dest_x, dest_y, steps)
87
+ @card=card
88
+ @step_x=(dest_x-@card.x)/steps.to_f
89
+ @step_y=(dest_y-@card.y)/steps.to_f
90
+ @dest_x=dest_x
91
+ @dest_y=dest_y
92
+ @steps=steps
93
+ @steps_done=0
94
+ end
95
+
96
+ def step
97
+ @card.x+=@step_x
98
+ @card.y+=@step_y
99
+ @steps_done+=1
100
+ if @steps_done==@steps
101
+ @card.x=@dest_x
102
+ @card.y=@dest_y
103
+ return true
104
+ end
105
+ return false
106
+ end
107
+ end
108
+
109
+
110
+
111
+ class Rotation
112
+ def initialize(card, dest_angle, steps)
113
+ @card=card
114
+ @step_angle=(dest_angle-@card.angle)/steps.to_f
115
+ @dest_angle=dest_angle
116
+ @steps=steps
117
+ @steps_done=0
118
+ end
119
+
120
+ def step
121
+ @card.angle+=@step_angle
122
+ @steps_done+=1
123
+ if @steps_done==@steps
124
+ @card.angle=@dest_angle
125
+ return true
126
+ end
127
+ return false
128
+ end
129
+ end
130
+
131
+
132
+
133
+ class Flip
134
+ def initialize(card, x_or_y, steps)
135
+ @card=card
136
+ case x_or_y
137
+ when :x
138
+ @step_zoom_x=-2/steps.to_f
139
+ when :y
140
+ @step_zoom_y=-2/steps.to_f
141
+ end
142
+ @x_or_y=x_or_y
143
+ @steps=steps
144
+ @steps_done=0
145
+ end
146
+
147
+ def step
148
+ case @x_or_y
149
+ when :x
150
+ @card.zoom_x+=@step_zoom_x
151
+ when :y
152
+ @card.zoom_y+=@step_zoom_y
153
+ end
154
+ @steps_done+=1
155
+ if @steps_done==@steps/2
156
+ case @card.side
157
+ when @card.front
158
+ @card.side=@card.back
159
+ when @card.back
160
+ @card.side=@card.front
161
+ end
162
+ case @x_or_y
163
+ when :x
164
+ @step_zoom_x=2/@steps.to_f
165
+ when :y
166
+ @step_zoom_y=2/@steps.to_f
167
+ end
168
+ elsif @steps_done==@steps
169
+ @card.zoom_x=@card.zoom_y=1
170
+ return true
171
+ end
172
+ return false
173
+ end
174
+ end
@@ -0,0 +1,220 @@
1
+ =begin
2
+ name: Queen of Diamonds v0.3
3
+ author: Dirk Meijer
4
+ date: April 17th 2006
5
+ description: The basis of the app, contains the classes.
6
+ =end
7
+
8
+
9
+ class Game
10
+ attr_accessor(:window, :hand)
11
+
12
+ def initialize(window=Window.new, hand=Deck.new)
13
+ window.verify_class(Window)
14
+ hand.verify_class(Hand, Deck)
15
+ @window=window
16
+ @hand=hand
17
+ end
18
+
19
+ def play
20
+ @window.show
21
+ end
22
+ end
23
+
24
+
25
+ class Card
26
+ @@value_order="2345678910JQKAX"
27
+ @@suit_order="CDSHJ"
28
+ @@suits_over_values=false
29
+ include Comparable
30
+ attr_reader(:value, :suit)
31
+
32
+ def initialize(value, suit)
33
+ value.verify_class(Fixnum, Symbol, String)
34
+ suit.verify_class(Symbol, String)
35
+ if (2..10).include?(value.to_i)
36
+ @value=value.to_i
37
+ elsif value.to_s =~ /^[JQKA]$/i
38
+ @value=value.to_s.upcase.to_sym
39
+ else
40
+ raise "invalid card value"
41
+ end
42
+ raise "invalid card suit" if suit.to_s !~ /^[HSDC]$/i
43
+ @suit=suit.to_s.upcase.to_sym
44
+ end
45
+
46
+ def to_s
47
+ outp=""
48
+ if (2..10).include?(@value.to_i)
49
+ outp << @value.to_s
50
+ elsif @value==:J
51
+ outp << "Jack"
52
+ elsif @value==:Q
53
+ outp << "Queen"
54
+ elsif @value==:K
55
+ outp << "King"
56
+ elsif @value==:A
57
+ outp << "Ace"
58
+ end
59
+ outp << " of "
60
+ if @suit==:H
61
+ outp << "Hearts"
62
+ elsif @suit==:S
63
+ outp << "Spades"
64
+ elsif @suit==:D
65
+ outp << "Diamonds"
66
+ elsif @suit==:C
67
+ outp << "Clubs"
68
+ end
69
+ end
70
+
71
+ def <=>(other)
72
+ other.verify_class(Card, Joker)
73
+ compare_suits=(@@suit_order =~ /#{suit.to_s}/)<=>(@@suit_order =~ /#{other.suit.to_s}/)
74
+ compare_values=(@@value_order =~ /#{value.to_s}/)<=>(@@value_order =~ /#{other.value.to_s}/)
75
+ case @@suits_over_values
76
+ when true
77
+ return compare_suits if compare_suits != 0
78
+ compare_values
79
+ when false
80
+ return compare_values if compare_values != 0
81
+ compare_suits
82
+ end
83
+ end
84
+
85
+ def inspect
86
+ "{Card##{to_s}}"
87
+ end
88
+ end
89
+
90
+
91
+ class Joker < Card
92
+ def initialize
93
+ @suit=:J
94
+ @value=:X
95
+ end
96
+
97
+ def to_s
98
+ "Joker"
99
+ end
100
+ end
101
+
102
+
103
+ class Hand
104
+ attr_reader(:cards)
105
+
106
+ def initialize(*cards)
107
+ @cards=cards.flatten
108
+ @cards.each do |item|
109
+ item.verify_class(Card, Joker)
110
+ end
111
+ end
112
+
113
+ def +(hand)
114
+ hand.verify_class(Hand, Deck)
115
+ Hand.new(@cards+hand.cards)
116
+ end
117
+
118
+ def -(hand)
119
+ hand.verify_class(Hand, Deck)
120
+ Hand.new(@cards-hand.cards)
121
+ end
122
+
123
+ def each &block
124
+ @cards.each &block
125
+ self
126
+ end
127
+
128
+ def each_with_index &block
129
+ @cards.each_with_index &block
130
+ self
131
+ end
132
+
133
+ def to_a
134
+ @cards
135
+ end
136
+
137
+ def <<(*cards)
138
+ cards.each do |item|
139
+ item.verify_class(Card, Joker)
140
+ end
141
+ @cards << cards
142
+ @cards.flatten!
143
+ self
144
+ end
145
+
146
+ def [](index)
147
+ @cards[index]
148
+ end
149
+
150
+ def sort
151
+ Hand.new(@cards.sort)
152
+ end
153
+
154
+ def sort!
155
+ @cards.sort!
156
+ self
157
+ end
158
+
159
+ def shuffle
160
+ Hand.new(@cards.sort_by {rand})
161
+ end
162
+
163
+ def shuffle!
164
+ @cards = @cards.sort_by {rand}
165
+ self
166
+ end
167
+
168
+ def stock(amount)
169
+ raise "not enough cards" if amount > @cards.length
170
+ new = Hand.new(@cards[0...amount])
171
+ @cards -= @cards[0...amount]
172
+ new
173
+ end
174
+
175
+ def size
176
+ @cards.length
177
+ end
178
+
179
+ def to_s
180
+ @cards.join("\n")
181
+ end
182
+
183
+ def inspect
184
+ "{Hand#size:#{@cards.length}}"
185
+ end
186
+
187
+ def ==(other)
188
+ @cards==other.cards
189
+ end
190
+ end
191
+
192
+
193
+ class Deck < Hand
194
+ def initialize
195
+ @cards=[]
196
+ values=[2,3,4,5,6,7,8,9,10,:J,:Q,:K,:A]
197
+ suits=[:C,:D,:S,:H]
198
+ values.each do |v|
199
+ suits.each do |s|
200
+ @cards << Card.new(v,s)
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+
207
+ class Object
208
+ def verify_class(*classes)
209
+ if classes.include?(self.class)
210
+ return true
211
+ else
212
+ if classes.length>2
213
+ class_names="#{classes[0..-2].join(', ')} or #{classes[-1]}"
214
+ else
215
+ class_names=classes.join(" or ")
216
+ end
217
+ raise TypeError.new("can't convert #{self.class} into #{class_names}")
218
+ end
219
+ end
220
+ end
data/lib/gosu/gosu.so ADDED
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,227 @@
1
+ =begin
2
+ name: BlackJack v0.2
3
+ author: Dirk Meijer
4
+ date: January 31st 2006
5
+ description: A simple BlackJack game using the Queen of Diamonds library,
6
+ it uses a simple terminal window, until I have finished the
7
+ graphic part. I'm probably about half-way through.
8
+ =end
9
+
10
+ require "Queen_Of_Diamonds"
11
+
12
+ #addition to the Card class, an ace can only be degraded once,
13
+ #otherwise certain situations would keep a player (or dealer) from losing
14
+ class Card
15
+ attr_accessor :ace_degraded
16
+ end
17
+
18
+ class Hand
19
+ def calculate_score
20
+ score=0
21
+ each do |card|
22
+ if card.value == :A #if it's an ace
23
+ score += 11 #add 11 points
24
+ score -= 10 if card.ace_degraded
25
+ elsif (2..10).include?(card.value) #if it's a 2 upto a 10
26
+ score += card.value #add that value
27
+ else #if it's something else
28
+ score += 10 #add 10 points
29
+ end
30
+ end
31
+ if score>21 #if your hand is more than 21
32
+ each do |card| #each card
33
+ if card.value == :A and card.ace_degraded != true #if an ace hasn't been degraded yet
34
+ score-=10 if score>21 #turn 11 points from ace into 1 point if your score still > 21
35
+ card.ace_degraded = true #tell the ace that it has been degraded
36
+ end
37
+ end
38
+ end
39
+ score
40
+ end
41
+ end
42
+
43
+
44
+ #the BlackJack class, which holds all the methods required to play blackjack
45
+ class BlackJack
46
+ attr_reader :player_score, :dealer_score, :player_hand, :dealer_hand, :winner, :money, :bet
47
+
48
+ def initialize(money=50)
49
+ @money=money
50
+ end
51
+
52
+
53
+ #the play methods, call this method to start a game
54
+ def play
55
+ loop do
56
+ @deck = Deck.new.shuffle #create a new (and shuffled) deck
57
+ @player_score=0 #your score is nullified
58
+ @dealer_score=0
59
+ @turn=0
60
+ puts "---------------------------\n Money: #{@money}\n How much money would you like to bet?"
61
+ bet=gets.to_i
62
+ until (1..@money).include?(bet)
63
+ puts "---------------------------\n Money: #{@money}\n How much money would you like to bet?"
64
+ bet=gets.to_i
65
+ end
66
+ @bet=bet
67
+ @money-=@bet
68
+ @player_hand=@deck.stock(2).sort #you get two cards
69
+ @player_score=@player_hand.calculate_score
70
+ puts "---------------------------\n Player's hand:",@player_hand," Score: #{@player_score}" #show your score
71
+ if @player_score==21 #if your score = 21
72
+ puts " Blackjack!" #tell player he has a blackjack
73
+ @winner=:player #player wins
74
+ @money+=(@bet*1.5).to_i
75
+ next #tell game to end
76
+ end
77
+ option= :choose #the first option is choose
78
+ loop do #until the game exits
79
+ option=__send__(option) #each method will return a symbol that is a method name, which will be evaluated, when the game is supposed to end, this will be :exit
80
+ break if option == :play
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+ #choose gives you four options, only the first two currently have effect
87
+ def choose
88
+ @turn+=1
89
+ puts "---------------------------\n Hit/Stand#{"/Double" if @turn==1 and ((9..11).include?(@player_score) or ([19,20].include?(@player_score) and (@player_hand[0].value==:A or @player_hand[1].value==:A))) and @money>=@bet}#{"/Split" if @turn==1 and @player_hand[0].value == @player_hand[1].value and @money>=@bet}#{"/Surrender" if @turn==1}?" #show options
90
+ g=gets #get string
91
+ if g=~/^h/i #if string starts with 'h'
92
+ return :hit #tell program to hit
93
+ elsif g=~/^st/i #if string starts with 'st'
94
+ return :dealer_move #tell program your done
95
+ elsif g=~/^d/i and @turn==1 and ((9..11).include?(@player_score) or ([19,20].include?(@player_score) and (@player_hand[0].value==:A or @player_hand[1].value==:A))) and @money>=@bet #if string starts with 'd'
96
+ return :double #double
97
+ elsif g=~/^sp/i and @turn==1 and @player_hand[0].value == @player_hand[1].value and @money>=@bet #if string starts with 'sp'
98
+ return :split #split cards
99
+ elsif g=~/^su/i and @turn==1
100
+ return :surrender
101
+ else #if no option was chosen
102
+ @turn-=1
103
+ return :choose #choose again
104
+ end
105
+ end
106
+
107
+
108
+ #you get another card
109
+ def hit
110
+ card=@deck.stock(1) #pop a card from the deck
111
+ (@player_hand+=card).sort! #add the popped card to hand
112
+ @player_score=@player_hand.calculate_score
113
+ puts "---------------------------\n Player's hand:",@player_hand," Score: #{@player_score}" #show your score
114
+ if @player_score>21 #if the player's score > 21
115
+ puts " Bust!" #tell the player that
116
+ @winner=:dealer #dealer wins
117
+ return :stop #tell game to end
118
+ end
119
+ if @player_hand.size==5 #if player has 5 cards
120
+ puts " Five cards!" #tell player
121
+ @winner=:player #player wins
122
+ return :stop #tell game to end
123
+ end
124
+ return :choose #if the game hasn't ended, tell the game you can choose again
125
+ end
126
+
127
+
128
+ #the dealers turn
129
+ def dealer_move
130
+ @dealer_score=0 #dealer score is nullified
131
+ @dealer_hand=@deck.stock(2).sort #deal 2 cards
132
+ @dealer_score=@dealer_hand.calculate_score
133
+ puts "---------------------------\n Dealer's hand:",@dealer_hand," Score: #{@dealer_score}" #show dealer score
134
+ if @dealer_score==21 #if blackjack
135
+ puts " Blackjack!" #tell player
136
+ @winner=:dealer #dealer wins
137
+ return :stop #end the game
138
+ end
139
+ while @dealer_score<@player_score #dealer will continue to hit himself, until his score is no longer less than player score
140
+ `pause` #game will pause, so the player can see what's going on
141
+ card=@deck.stock(1) #pop a card
142
+ @dealer_hand+=card #add the card to dealer hand
143
+ @dealer_score=@dealer_hand.calculate_score
144
+ puts "---------------------------\n Dealer's hand:",@dealer_hand," Score: #{@dealer_score}" #show dealers score
145
+ if @dealer_score>21 #if dealer score exceeds 21
146
+ puts " Bust!" #tell player
147
+ @winner=:player #player wins
148
+ return :stop #end the game
149
+ end
150
+ if @dealer_hand.size==5 #if dealer holds 5 cards
151
+ puts " Five cards!" #tell player
152
+ @winner=:dealer #dealer wins
153
+ return :stop #end game
154
+ end
155
+ end
156
+ @winner=:dealer #when dealer score equal or is more than player score, dealer wins
157
+ return :stop #end game
158
+ end
159
+
160
+
161
+ def double
162
+ @money-=@bet
163
+ @bet*=2
164
+ if @player_hand[0].value==:A
165
+ @player_score-=10
166
+ @player_hand[0].ace_degraded=true
167
+ elsif @player_hand[1].value==:A
168
+ @player_score-=10
169
+ @player_hand[1].ace_degraded=true
170
+ end
171
+ card=@deck.stock(1) #pop a card from the deck
172
+ (@player_hand+=card).sort! #add the popped card to hand
173
+ @player_score=@player_hand.calculate_score
174
+ puts "---------------------------\n Player's hand:",@player_hand," Score: #{@player_score}" #show your score
175
+ if @player_score>21 #if the player's score > 21
176
+ puts " Bust!" #tell the player that
177
+ @winner=:dealer #dealer wins
178
+ return :stop #tell game to end
179
+ end
180
+ return :dealer_move
181
+ end
182
+
183
+
184
+ def split
185
+ @money-=@bet
186
+ hand1=@player_hand.stock(1)
187
+ hand2=@player_hand.stock(1)
188
+ [hand1,hand2].each do |hand|
189
+ @player_hand=hand
190
+ (@player_hand+=@deck.stock(1)).sort! #you get two cards
191
+ @player_score=@player_hand.calculate_score
192
+ puts "---------------------------\n Player's hand:",@player_hand," Score: #{@player_score}" #show your score
193
+ option= :choose #the first option is choose
194
+ loop do #until the game exits
195
+ option=__send__(option) #each method will return a symbol that is a method name, which will be evaluated, when the game is supposed to end, this will be :exit
196
+ break if option == :play
197
+ end
198
+ end
199
+ :play
200
+ end
201
+
202
+
203
+ def surrender
204
+ @money+=(@bet*0.5).to_i
205
+ return :play
206
+ end
207
+
208
+
209
+ #what to do when the game ends
210
+ def stop
211
+ puts "---------------------------\n Player's score: #{@player_score}\n Dealer's score: #{@dealer_score}" #show scores
212
+ if @winner==:player #tell player who's won
213
+ puts " You win!"
214
+ @money+=@bet*2
215
+ else
216
+ puts " You lose!"
217
+ end
218
+ if @money>0
219
+ return :play
220
+ else
221
+ puts "---------------------------\n Game Over!\n No money left!\n---------------------------\n Blackjack\n Queen of Diamonds\n Dirk Meijer" #give credit to me
222
+ return :exit
223
+ end
224
+ end
225
+ end
226
+
227
+ BlackJack.new(5000).play #call the game!!
data/samples/pwnage.rb ADDED
@@ -0,0 +1,43 @@
1
+ require "Queen_Of_Diamonds"
2
+ $a=Table.new
3
+ $a.hand.cards<<Joker.new
4
+ $a.assign_images
5
+ $a.hand.shuffle!
6
+ $n=0
7
+ $card=$a.hand[0]
8
+ $tekst1=Gosu::Font.new($a,"Times New Roman",100)
9
+ $tekst2=Gosu::Font.new($a,"Century Gothic",50)
10
+
11
+
12
+ class Table
13
+ def draw
14
+ @background.draw(0,0,0)
15
+ $tekst1.draw_rel("PWN!!!",320,400,0,0.5,0.5,1,1,4278190080+rand(16777215))
16
+ $tekst2.draw_rel($card.to_s,320,100,0,0.5,0.5,1,1,0xffffff00) if $card
17
+ @visible_cards.each do |card|
18
+ card.draw
19
+ end
20
+ end
21
+
22
+ def update
23
+ @visible_cards.each do |card|
24
+ card.action
25
+ end
26
+ if $card.x==0
27
+ $card.x=-40
28
+ $card.angle=rand(720)-360
29
+ $card.y=rand(480)
30
+ $card.side=[$card.front,$card.back][rand(2)]
31
+ $a.visible_cards<<$card
32
+ $card.new_slide(680,rand(480),50)
33
+ $card.new_rotation(rand(720)-360,50)
34
+ $card.new_flip(:x,50)
35
+ elsif $card.x==680
36
+ $a.visible_cards-=[$card]
37
+ $n+=1
38
+ $card=$a.hand[$n]
39
+ end
40
+ end
41
+ end
42
+
43
+ $a.show
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: Queen_Of_Diamonds
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.3"
7
+ date: 2006-04-17 00:00:00 +02:00
8
+ summary: A library for creating Windows-like card games.
9
+ require_paths:
10
+ - lib
11
+ email: hawkman@gelooft.nl
12
+ homepage:
13
+ rubyforge_project:
14
+ description:
15
+ autorequire: Queen_Of_Diamonds
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: mswin32
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Dirk Meijer
30
+ files:
31
+ - images
32
+ - lib
33
+ - README
34
+ - samples
35
+ - tests
36
+ - images/back.png
37
+ - images/c10.png
38
+ - images/c2.png
39
+ - images/c3.png
40
+ - images/c4.png
41
+ - images/c5.png
42
+ - images/c6.png
43
+ - images/c7.png
44
+ - images/c8.png
45
+ - images/c9.png
46
+ - images/ca.png
47
+ - images/cj.png
48
+ - images/ck.png
49
+ - images/cq.png
50
+ - images/d10.png
51
+ - images/d2.png
52
+ - images/d3.png
53
+ - images/d4.png
54
+ - images/d5.png
55
+ - images/d6.png
56
+ - images/d7.png
57
+ - images/d8.png
58
+ - images/d9.png
59
+ - images/da.png
60
+ - images/dj.png
61
+ - images/dk.png
62
+ - images/dq.png
63
+ - images/h10.png
64
+ - images/h2.png
65
+ - images/h3.png
66
+ - images/h4.png
67
+ - images/h5.png
68
+ - images/h6.png
69
+ - images/h7.png
70
+ - images/h8.png
71
+ - images/h9.png
72
+ - images/ha.png
73
+ - images/hj.png
74
+ - images/hk.png
75
+ - images/hq.png
76
+ - images/jx.png
77
+ - images/s10.png
78
+ - images/s2.png
79
+ - images/s3.png
80
+ - images/s4.png
81
+ - images/s5.png
82
+ - images/s6.png
83
+ - images/s7.png
84
+ - images/s8.png
85
+ - images/s9.png
86
+ - images/sa.png
87
+ - images/sj.png
88
+ - images/sk.png
89
+ - images/sq.png
90
+ - images/table.png
91
+ - lib/gosu
92
+ - lib/Queen_Of_Diamonds.rb
93
+ - lib/Queen_Of_Diamonds_no_graphics.rb
94
+ - lib/gosu/gosu.so
95
+ - lib/gosu/msvcp71.dll
96
+ - lib/gosu/msvcr71.dll
97
+ - lib/gosu/unicows.dll
98
+ - samples/blackjack.rb
99
+ - samples/pwnage.rb
100
+ test_files: []
101
+
102
+ rdoc_options: []
103
+
104
+ extra_rdoc_files: []
105
+
106
+ executables: []
107
+
108
+ extensions: []
109
+
110
+ requirements: []
111
+
112
+ dependencies: []
113
+