gloomhaven 0.1.0
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 +7 -0
- data/.gitignore +12 -0
- data/.rspec +3 -0
- data/.travis.yml +7 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +47 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +6 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/config/cards.yml +43 -0
- data/gloomhaven.gemspec +36 -0
- data/lib/gloomhaven.rb +9 -0
- data/lib/gloomhaven/card.rb +45 -0
- data/lib/gloomhaven/deck.rb +96 -0
- data/lib/gloomhaven/version.rb +3 -0
- metadata +129 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 51ab7e89f61d4b4e19d929d6c99a52a00dbd83092b7efd75b86af8228a9c8e58
|
4
|
+
data.tar.gz: 8ddb9a3f7e9e12e0221e941d13f61fad593b7d0c721db42f1c20507e3f99c31f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '088a131e3241dca17364a65346818f23b748abdabeb262a69d21b287e49f528225f11ee7bd29d37e2ba017ae8464eb6b98b203309fba169db876c9ca48809c9c'
|
7
|
+
data.tar.gz: 25843bb532e996763e42ab7c51c29b8041d5b079a2d97d02a9bdce57b0d2285908f08b12c808c646e1cf7febccc87d1cae407f5284ab3bba525ae62f4c9ab292
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
gloomhaven (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
coderay (1.1.2)
|
10
|
+
diff-lcs (1.3)
|
11
|
+
docile (1.3.2)
|
12
|
+
method_source (0.9.2)
|
13
|
+
pry (0.12.2)
|
14
|
+
coderay (~> 1.1.0)
|
15
|
+
method_source (~> 0.9.0)
|
16
|
+
rake (10.5.0)
|
17
|
+
rspec (3.9.0)
|
18
|
+
rspec-core (~> 3.9.0)
|
19
|
+
rspec-expectations (~> 3.9.0)
|
20
|
+
rspec-mocks (~> 3.9.0)
|
21
|
+
rspec-core (3.9.1)
|
22
|
+
rspec-support (~> 3.9.1)
|
23
|
+
rspec-expectations (3.9.0)
|
24
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
25
|
+
rspec-support (~> 3.9.0)
|
26
|
+
rspec-mocks (3.9.1)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.9.0)
|
29
|
+
rspec-support (3.9.2)
|
30
|
+
simplecov (0.18.4)
|
31
|
+
docile (~> 1.1)
|
32
|
+
simplecov-html (~> 0.11)
|
33
|
+
simplecov-html (0.12.1)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
bundler (~> 2.0)
|
40
|
+
gloomhaven!
|
41
|
+
pry
|
42
|
+
rake (~> 10.0)
|
43
|
+
rspec (~> 3.0)
|
44
|
+
simplecov
|
45
|
+
|
46
|
+
BUNDLED WITH
|
47
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Teo Dell'Amico
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
# Gloomhaven
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/gloomhaven`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'gloomhaven'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install gloomhaven
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gloomhaven.
|
36
|
+
|
37
|
+
## License
|
38
|
+
|
39
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
40
|
+
# gloomhaven
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "gloomhaven"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/config/cards.yml
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
---
|
2
|
+
1:
|
3
|
+
name: 'Attack +0'
|
4
|
+
attack: 0
|
5
|
+
starting_count: 6
|
6
|
+
2:
|
7
|
+
name: 'Attack +1'
|
8
|
+
attack: 1
|
9
|
+
starting_count: 5
|
10
|
+
3:
|
11
|
+
name: 'Attack -1'
|
12
|
+
attack: -1
|
13
|
+
starting_count: 5
|
14
|
+
4:
|
15
|
+
name: 'Attack +2'
|
16
|
+
attack: 2
|
17
|
+
starting_count: 1
|
18
|
+
5:
|
19
|
+
name: 'Attack -2'
|
20
|
+
attack: -2
|
21
|
+
starting_count: 1
|
22
|
+
6: &crit_miss
|
23
|
+
name: 'Null'
|
24
|
+
attack: 0
|
25
|
+
starting_count: 1
|
26
|
+
shuffle: true
|
27
|
+
miss: true
|
28
|
+
7: &crit_hit
|
29
|
+
name: '2x'
|
30
|
+
attack: 0
|
31
|
+
starting_count: 1
|
32
|
+
shuffle: true
|
33
|
+
crit: true
|
34
|
+
8:
|
35
|
+
<<: *crit_miss
|
36
|
+
name: 'Curse'
|
37
|
+
shuffle: false
|
38
|
+
starting_count: 0
|
39
|
+
9:
|
40
|
+
<<: *crit_hit
|
41
|
+
name: 'Bless'
|
42
|
+
shuffle: false
|
43
|
+
starting_count: 0
|
data/gloomhaven.gemspec
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
lib = File.expand_path("lib", __dir__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require "gloomhaven/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "gloomhaven"
|
7
|
+
spec.version = Gloomhaven::VERSION
|
8
|
+
spec.authors = ["Teo Dell'Amico"]
|
9
|
+
spec.email = ["teo.dellamico@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "Ruby gem to manage Gloomhaven attack modifier decks"
|
12
|
+
# spec.description = %q{TODO: Write a longer description or delete this line.}
|
13
|
+
# spec.homepage = "TODO: Put your gem's website or public repo URL here."
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
# spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
17
|
+
|
18
|
+
# spec.metadata["homepage_uri"] = spec.homepage
|
19
|
+
# spec.metadata["source_code_uri"] = "TODO: Put your gem's public repo URL here."
|
20
|
+
# spec.metadata["changelog_uri"] = "TODO: Put your gem's CHANGELOG.md URL here."
|
21
|
+
|
22
|
+
# Specify which files should be added to the gem when it is released.
|
23
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
24
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
25
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
end
|
27
|
+
spec.bindir = "exe"
|
28
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
|
+
spec.require_paths = ["lib"]
|
30
|
+
|
31
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
32
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
34
|
+
spec.add_development_dependency "pry"
|
35
|
+
spec.add_development_dependency 'simplecov'
|
36
|
+
end
|
data/lib/gloomhaven.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
module Gloomhaven
|
2
|
+
class Card
|
3
|
+
attr_reader :attack
|
4
|
+
attr_reader :crit
|
5
|
+
attr_reader :name
|
6
|
+
attr_reader :miss
|
7
|
+
attr_reader :shuffle
|
8
|
+
|
9
|
+
# returns a card object from the card name
|
10
|
+
def self.find(name)
|
11
|
+
Card.new(find_id_by_name(name))
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(number)
|
15
|
+
validate_card_number!(number)
|
16
|
+
|
17
|
+
data = CARDS[number]
|
18
|
+
@name = data['name']
|
19
|
+
@attack = data['attack']
|
20
|
+
@crit = data['crit'] == true
|
21
|
+
@miss = data['miss'] == true
|
22
|
+
@shuffle = data['shuffle'] == true
|
23
|
+
end
|
24
|
+
|
25
|
+
def bless?
|
26
|
+
name.downcase == 'bless'
|
27
|
+
end
|
28
|
+
|
29
|
+
def curse?
|
30
|
+
name.downcase == 'curse'
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
# returns yaml-id of the card by name
|
36
|
+
def self.find_id_by_name(name)
|
37
|
+
CARDS.select { |id, attributes| attributes['name'].downcase == name.downcase }.keys.first
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_card_number!(number)
|
41
|
+
raise ArgumentError.new('Number must be an integer') unless number.is_a?(Integer)
|
42
|
+
raise ArgumentError.new('Number is not supported') unless Gloomhaven::CARDS.keys.include?(number)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module Gloomhaven
|
2
|
+
class Deck
|
3
|
+
attr_reader :cards
|
4
|
+
attr_reader :drawn_cards
|
5
|
+
|
6
|
+
##
|
7
|
+
# Creates a basic 20-card attack deck
|
8
|
+
def initialize
|
9
|
+
@cards = []
|
10
|
+
@drawn_cards = []
|
11
|
+
build_base_deck!
|
12
|
+
end
|
13
|
+
|
14
|
+
##
|
15
|
+
# Adds a card to the current deck.
|
16
|
+
# Useful for updating decks based on character-specific perks.
|
17
|
+
# Ex:
|
18
|
+
#
|
19
|
+
# deck = Deck.new
|
20
|
+
# card = Card.find('Attack +3')
|
21
|
+
# deck.add!(card)
|
22
|
+
def add!(card)
|
23
|
+
raise TypeError.new('Card must be a Gloomhaven::Card') unless card.is_a?(Gloomhaven::Card)
|
24
|
+
|
25
|
+
@cards << card
|
26
|
+
@cards
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Adds a bless card to the current deck, then soft shuffles
|
31
|
+
def bless!
|
32
|
+
@cards << Card.find('Bless')
|
33
|
+
shuffle!(soft_shuffle: true)
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Adds a curse card to the current deck, then soft shuffles
|
38
|
+
def curse!
|
39
|
+
@cards << Card.find('Curse')
|
40
|
+
shuffle!(soft_shuffle: true)
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# Removes the top card from the deck, adds it to the @drawn_cards array (unless it's a bless/curse)
|
45
|
+
# Returns the drawn card.
|
46
|
+
# Ex: Deck.new.draw
|
47
|
+
# => #<Card >
|
48
|
+
def draw
|
49
|
+
card = @cards.shift
|
50
|
+
@drawn_cards << card unless card.bless? || card.curse?
|
51
|
+
card
|
52
|
+
end
|
53
|
+
|
54
|
+
##
|
55
|
+
# Removes a card from the current deck.
|
56
|
+
# Useful for updating decks based on character-specific perks.
|
57
|
+
# Ex:
|
58
|
+
#
|
59
|
+
# deck = Deck.new
|
60
|
+
# card = Card.find('Attack -1')
|
61
|
+
# deck.remove!(card)
|
62
|
+
def remove!(card)
|
63
|
+
raise TypeError.new('Card must be a Gloomhaven::Card') unless card.is_a?(Gloomhaven::Card)
|
64
|
+
|
65
|
+
index = cards.index { |c| c.name == card.name }
|
66
|
+
raise ArgumentError.new("Card: '#{card.name}' not found in deck") unless index
|
67
|
+
|
68
|
+
@cards.delete_at(index)
|
69
|
+
@cards
|
70
|
+
end
|
71
|
+
|
72
|
+
##
|
73
|
+
# Randomizes the order of #cards
|
74
|
+
# By default, will shuffle all cards together.
|
75
|
+
#
|
76
|
+
# Can override with `options = { soft_shuffle: true }` to
|
77
|
+
# only shuffle cards not yet drawn (useful for blesses/curses)
|
78
|
+
def shuffle!(options = {})
|
79
|
+
options[:soft_shuffle] ||= false
|
80
|
+
return @cards.shuffle! if options[:soft_shuffle]
|
81
|
+
|
82
|
+
@cards = (@cards + @drawn_cards).shuffle
|
83
|
+
@drawn_cards = []
|
84
|
+
@cards
|
85
|
+
end
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def build_base_deck!
|
90
|
+
CARDS.each do |card|
|
91
|
+
id, attributes = card
|
92
|
+
attributes['starting_count'].times { cards << Card.new(id) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
metadata
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gloomhaven
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Teo Dell'Amico
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-25 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- teo.dellamico@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- config/cards.yml
|
101
|
+
- gloomhaven.gemspec
|
102
|
+
- lib/gloomhaven.rb
|
103
|
+
- lib/gloomhaven/card.rb
|
104
|
+
- lib/gloomhaven/deck.rb
|
105
|
+
- lib/gloomhaven/version.rb
|
106
|
+
homepage:
|
107
|
+
licenses:
|
108
|
+
- MIT
|
109
|
+
metadata: {}
|
110
|
+
post_install_message:
|
111
|
+
rdoc_options: []
|
112
|
+
require_paths:
|
113
|
+
- lib
|
114
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
requirements: []
|
125
|
+
rubygems_version: 3.0.4
|
126
|
+
signing_key:
|
127
|
+
specification_version: 4
|
128
|
+
summary: Ruby gem to manage Gloomhaven attack modifier decks
|
129
|
+
test_files: []
|