p10 0.0.0.pre.alpha0 → 0.0.0.pre.alpha1
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.
- checksums.yaml +4 -4
- data/bin/p10 +3 -0
- data/lib/p10/card.rb +15 -0
- data/lib/p10/deck.rb +28 -0
- data/lib/p10/number_card.rb +61 -0
- data/lib/p10/skip_card.rb +9 -0
- data/lib/p10/version.rb +32 -0
- data/lib/p10/wild_card.rb +9 -0
- data/lib/p10.rb +6 -0
- metadata +13 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3cd5f83a7e748e7a3ec78879cbb332976e0769d
|
4
|
+
data.tar.gz: a2f8f35aba907b4f5f4d77efad8204ee0d903c8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62b7eaa330be7a84dccfcd0e553fdde7b7b06614048c1e369997b5210d12f8b7f7c4e9be6a3d82bf1c85908a7bbd37c8cead756d582eece51cd2287f4c2efe19
|
7
|
+
data.tar.gz: 70ca6adaf8c7115d15a73981016561de2e57b52570697965b3cb708da18b3ad669e65a521d3ddf9e107876818167b46aa006cb7e3fc6da2b9c7970769b09f7d1
|
data/bin/p10
ADDED
data/lib/p10/card.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
module Phase10
|
2
|
+
class Card
|
3
|
+
def wild?
|
4
|
+
self.class.name.to_sym == :"Phase10::WildCard"
|
5
|
+
end
|
6
|
+
|
7
|
+
def skip?
|
8
|
+
self.class.name.to_sym == :"Phase10::SkipCard"
|
9
|
+
end
|
10
|
+
|
11
|
+
def number?
|
12
|
+
self.class.name.to_sym == :"Phase10::NumberCard"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
data/lib/p10/deck.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'p10/number_card'
|
2
|
+
require 'p10/skip_card'
|
3
|
+
require 'p10/wild_card'
|
4
|
+
|
5
|
+
module Phase10
|
6
|
+
class Deck < Array
|
7
|
+
def initialize
|
8
|
+
super ([:red, :blue, :green, :yellow].product((1..12).to_a * 2).map do |color, number|
|
9
|
+
NumberCard.new(color, number)
|
10
|
+
end.to_a +
|
11
|
+
|
12
|
+
8.times.map do
|
13
|
+
WildCard.new
|
14
|
+
end.to_a +
|
15
|
+
|
16
|
+
4.times.map do
|
17
|
+
SkipCard.new
|
18
|
+
end.to_a).flatten
|
19
|
+
end
|
20
|
+
|
21
|
+
def add(card)
|
22
|
+
raise ArgumentError, 'Given argument is not a Card' unless
|
23
|
+
card.is_a?(Card)
|
24
|
+
|
25
|
+
insert((rand * self.count).floor, card)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require 'p10/card'
|
2
|
+
|
3
|
+
module Phase10
|
4
|
+
class NumberCard < Card
|
5
|
+
attr_reader :color, :number
|
6
|
+
|
7
|
+
def initialize(color, number)
|
8
|
+
@color = color if validate_color color
|
9
|
+
@number = number if validate_number number
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate_color(color)
|
13
|
+
raise ArgumentError, 'Color is invalid' unless
|
14
|
+
colors.include? color
|
15
|
+
|
16
|
+
true
|
17
|
+
end
|
18
|
+
|
19
|
+
def validate_number(number)
|
20
|
+
raise ArgumentError, 'Number is invalid' unless
|
21
|
+
numbers.include? number
|
22
|
+
|
23
|
+
true
|
24
|
+
end
|
25
|
+
|
26
|
+
def point_value
|
27
|
+
case @number
|
28
|
+
when (1..9)
|
29
|
+
5
|
30
|
+
when (10..12)
|
31
|
+
10
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def red?
|
36
|
+
@color == :red
|
37
|
+
end
|
38
|
+
|
39
|
+
def blue?
|
40
|
+
@color == :blue
|
41
|
+
end
|
42
|
+
|
43
|
+
def green?
|
44
|
+
@color == :green
|
45
|
+
end
|
46
|
+
|
47
|
+
def yellow?
|
48
|
+
@color == :yellow
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def colors
|
54
|
+
[:red, :blue, :green, :yellow]
|
55
|
+
end
|
56
|
+
|
57
|
+
def numbers
|
58
|
+
(1..12).to_a
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
data/lib/p10/version.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
module Phase10
|
2
|
+
class Version
|
3
|
+
attr_reader :major, :minor, :patch, :pre
|
4
|
+
|
5
|
+
def initialize(major, minor = 0, patch = 0, pre = nil)
|
6
|
+
@major = major
|
7
|
+
@minor = minor
|
8
|
+
@patch = patch
|
9
|
+
@pre = pre
|
10
|
+
end
|
11
|
+
|
12
|
+
def format(format)
|
13
|
+
format % [ @major, @minor, @patch, prerelease_string ]
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_s
|
17
|
+
format(version_format)
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
|
22
|
+
def version_format
|
23
|
+
'%s.%s.%s%s'
|
24
|
+
end
|
25
|
+
|
26
|
+
def prerelease_string
|
27
|
+
@pre ? "-#{@pre}" : ''
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
VERSION = Version.new(0, 0, 0, 'alpha1')
|
32
|
+
end
|
data/lib/p10.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: p10
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.pre.
|
4
|
+
version: 0.0.0.pre.alpha1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kristofer Rye
|
@@ -125,10 +125,19 @@ dependencies:
|
|
125
125
|
description: A simulation/representation of the card game Phase 10, designed for use
|
126
126
|
in large applications or microscopic testing environments.
|
127
127
|
email: kristofer.rye@gmail.com
|
128
|
-
executables:
|
128
|
+
executables:
|
129
|
+
- p10
|
129
130
|
extensions: []
|
130
131
|
extra_rdoc_files: []
|
131
|
-
files:
|
132
|
+
files:
|
133
|
+
- bin/p10
|
134
|
+
- lib/p10.rb
|
135
|
+
- lib/p10/card.rb
|
136
|
+
- lib/p10/deck.rb
|
137
|
+
- lib/p10/number_card.rb
|
138
|
+
- lib/p10/skip_card.rb
|
139
|
+
- lib/p10/version.rb
|
140
|
+
- lib/p10/wild_card.rb
|
132
141
|
homepage: https://github.com/rye/p10
|
133
142
|
licenses:
|
134
143
|
- MIT
|
@@ -149,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
149
158
|
version: 1.3.1
|
150
159
|
requirements: []
|
151
160
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.5.0
|
153
162
|
signing_key:
|
154
163
|
specification_version: 4
|
155
164
|
summary: A simulation/representation of the card game Phase 10.
|