gamemaker 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/gamemaker/card_game.rb +1 -0
- data/lib/gamemaker/card_game/deck.rb +28 -0
- data/lib/gamemaker/card_game/hand.rb +20 -0
- data/lib/gamemaker/card_game/playing_card.rb +52 -0
- data/lib/gamemaker/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc9c799ef34e5fa6def38e0c9ca605422066beb7
|
4
|
+
data.tar.gz: 71dfb99cd0ae105da715e2a95c8dd504dafb2c5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d9fb7600fad795a54207bc0ee96af83123ea675c5fd69b366217e8d1ce3afe04d6f42c4372a581255315eb1879baa50974218ba01d7b0bb9c6489e1527b85d53
|
7
|
+
data.tar.gz: 604c9d9304ec761dc990a16693032bef46f60fd79554894b2cfdb3eeb0bb2bc26d04596ab2cba879ae48d451f3e0550c6cc19dd9a22778516af09acbb418db24
|
data/lib/gamemaker/card_game.rb
CHANGED
@@ -30,6 +30,7 @@ module Gamemaker
|
|
30
30
|
|
31
31
|
def shuffle!
|
32
32
|
@cards.shuffle!
|
33
|
+
self
|
33
34
|
end
|
34
35
|
|
35
36
|
def draw(n = nil)
|
@@ -50,6 +51,33 @@ module Gamemaker
|
|
50
51
|
|
51
52
|
alias_method :take!, :draw!
|
52
53
|
|
54
|
+
def put(*cards, position: :bottom)
|
55
|
+
case position
|
56
|
+
when :top
|
57
|
+
undraw(*cards)
|
58
|
+
when :bottom
|
59
|
+
self << cards
|
60
|
+
else
|
61
|
+
raise ArgumentError, "Cannot put cards to #{position.inspect}"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def <<(*cards)
|
66
|
+
@cards.concat(cards.flatten)
|
67
|
+
self
|
68
|
+
end
|
69
|
+
|
70
|
+
def undraw(*cards)
|
71
|
+
@cards = cards.flatten + @cards
|
72
|
+
self
|
73
|
+
end
|
74
|
+
|
75
|
+
alias_method :untake, :undraw
|
76
|
+
|
77
|
+
def merge!(other)
|
78
|
+
self << other.draw(other.length)
|
79
|
+
end
|
80
|
+
|
53
81
|
def to_a
|
54
82
|
@cards.dup
|
55
83
|
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Gamemaker
|
2
|
+
module CardGame
|
3
|
+
class Hand < Deck
|
4
|
+
def self.card_class
|
5
|
+
raise NotImplementedError, "Hand is an abstract class, use Hand.of(CardType) to create a usable subclass"
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.of(card_class)
|
9
|
+
Class.new(self) do
|
10
|
+
define_singleton_method(:name) { super() || "#{card_class.name}Hand" }
|
11
|
+
define_singleton_method(:card_class) { card_class }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(cards = [])
|
16
|
+
super(cards)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -4,6 +4,14 @@ module Gamemaker
|
|
4
4
|
SUITS = [:clubs, :diamonds, :hearts, :spades]
|
5
5
|
RANKS = [:ace, 2, 3, 4, 5, 6, 7, 8, 9, 10, :jack, :queen, :king]
|
6
6
|
|
7
|
+
SUIT_GLYPHS = { clubs: "♣", diamonds: "♦", hearts: "♥", spades: "♠" }
|
8
|
+
CARD_GLYPHS = {
|
9
|
+
clubs: { ace: "🃑", 2 => "🃒", 3 => "🃓", 4 => "🃔", 5 => "🃕", 6 => "🃖", 7 => "🃗", 8 => "🃘", 9 => "🃙", 10 => "🃚", jack: "🃛", queen: "🃝", king: "🃞" },
|
10
|
+
diamonds: { ace: "🃁", 2 => "🃂", 3 => "🃃", 4 => "🃄", 5 => "🃅", 6 => "🃆", 7 => "🃇", 8 => "🃈", 9 => "🃉", 10 => "🃊", jack: "🃋", queen: "🃍", king: "🃎" },
|
11
|
+
hearts: { ace: "🂱", 2 => "🂲", 3 => "🂳", 4 => "🂴", 5 => "🂵", 6 => "🂶", 7 => "🂷", 8 => "🂸", 9 => "🂹", 10 => "🂺", jack: "🂻", queen: "🂽", king: "🂾" },
|
12
|
+
spades: { ace: "🂡", 2 => "🂢", 3 => "🂣", 4 => "🂤", 5 => "🂥", 6 => "🂦", 7 => "🂧", 8 => "🂨", 9 => "🂩", 10 => "🂪", jack: "🂫", queen: "🂭", king: "🂮" }
|
13
|
+
}
|
14
|
+
|
7
15
|
attr_reader :suit, :rank
|
8
16
|
|
9
17
|
def self.all
|
@@ -80,6 +88,29 @@ module Gamemaker
|
|
80
88
|
@rank == other.rank && @suit == other.suit
|
81
89
|
end
|
82
90
|
|
91
|
+
def to_s(format = :simple)
|
92
|
+
suit = SUIT_GLYPHS[@suit]
|
93
|
+
|
94
|
+
if Fixnum === @rank
|
95
|
+
rank = @rank.to_s
|
96
|
+
else
|
97
|
+
rank = @rank.to_s.upcase[0]
|
98
|
+
end
|
99
|
+
|
100
|
+
simple = suit + rank
|
101
|
+
|
102
|
+
case format
|
103
|
+
when :simple
|
104
|
+
simple
|
105
|
+
when :fancy
|
106
|
+
"┌──┐\n│#{simple.ljust(3,'|')}\n└──┘\n"
|
107
|
+
when :glyph
|
108
|
+
CARD_GLYPHS[@suit][@rank]
|
109
|
+
else
|
110
|
+
raise ArgumentError, "Unknown format #{format.inspect}"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
83
114
|
def as_json(*)
|
84
115
|
{ suit: @suit, rank: @rank }
|
85
116
|
end
|
@@ -87,5 +118,26 @@ module Gamemaker
|
|
87
118
|
|
88
119
|
class PlayingCardDeck < Deck.of(PlayingCard)
|
89
120
|
end
|
121
|
+
|
122
|
+
class PlayingCardHand < Hand.of(PlayingCard)
|
123
|
+
def to_s(format = :simple, seperator: ' ', seperators: nil)
|
124
|
+
if format != :fancy && seperators
|
125
|
+
raise ArgumentError, "Invalid option `seperators: #{seperators.inspect}` (did you mean `seperator`?)"
|
126
|
+
end
|
127
|
+
|
128
|
+
strings = @cards.map { |c| c.to_s(format) }
|
129
|
+
|
130
|
+
if format == :fancy
|
131
|
+
seperators ||= [' ' * seperator.length, ' ' * seperator.length, seperator]
|
132
|
+
strings.map(&:split)
|
133
|
+
.transpose
|
134
|
+
.zip(seperators)
|
135
|
+
.map { |line| line.inject(:join) }
|
136
|
+
.join("\n") + "\n"
|
137
|
+
else
|
138
|
+
strings.join(seperator)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
90
142
|
end
|
91
143
|
end
|
data/lib/gamemaker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gamemaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Godfrey Chan
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- lib/gamemaker/card_game.rb
|
88
88
|
- lib/gamemaker/card_game/card.rb
|
89
89
|
- lib/gamemaker/card_game/deck.rb
|
90
|
+
- lib/gamemaker/card_game/hand.rb
|
90
91
|
- lib/gamemaker/card_game/playing_card.rb
|
91
92
|
- lib/gamemaker/version.rb
|
92
93
|
homepage: http://gamemaker.io
|