studio_game_2021 1.0.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.
@@ -0,0 +1,165 @@
1
+ require 'studio_game/player'
2
+
3
+ module StudioGame
4
+ describe "Player should" do
5
+
6
+ before do
7
+ # suppress test puts output only
8
+ $stdout = StringIO.new
9
+
10
+ # Set friendly test-only variables
11
+ @default_health = 100
12
+ @half_default_health = 50
13
+
14
+ # Set up example players
15
+ @larry = Player.new("larry")
16
+ @curly = Player.new("curly")
17
+ @moe = Player.new("moe", @half_default_health)
18
+ end
19
+
20
+ it "have a default name of 'Player'." do
21
+ nameless_player = Player.new
22
+
23
+ expect(nameless_player.name).to eq("Player")
24
+ end
25
+
26
+ it "have a capitalized name." do
27
+ expect(@larry.name).to eq("Larry")
28
+ expect(@curly.name).to eq("Curly")
29
+ end
30
+
31
+ it "allow name change requests." do
32
+ @larry.name = "lawrence" #larry's mum is mad
33
+ expect(@larry.name).to eq("Lawrence")
34
+ end
35
+
36
+ it "start with a default health of 100." do
37
+ expect(@larry.health).to eq(@default_health)
38
+ expect(@curly.health).to eq(@default_health)
39
+ end
40
+
41
+ it "allow a custom starting health." do
42
+ expect(@moe.health).to eq(@half_default_health)
43
+ end
44
+
45
+ it "introduce themselves and their health status." do
46
+ expect(@larry.print_health_status).to eq("Larry (100 health)")
47
+ expect(@curly.print_health_status).to eq("Curly (100 health)")
48
+ end
49
+
50
+ it "lose 10 health points when blammed." do
51
+ @larry.blam
52
+ expect(@larry.health).to eq(@default_health - 10)
53
+
54
+ @larry.blam
55
+ expect(@larry.health).to eq(@default_health - (10*2))
56
+ end
57
+
58
+ it "gain 15 health points when w00ted." do
59
+ @larry.w00t
60
+ expect(@larry.health).to eq(@default_health + 15)
61
+
62
+ @larry.w00t
63
+ expect(@larry.health).to eq(@default_health + (15*2))
64
+ end
65
+
66
+ it "have a score computed from their health and points." do
67
+ treasure = Treasure.new("pickaxe", 2)
68
+ TreasureTrove.stub(:random_treasure).and_return(treasure)
69
+ @larry.find_treasure
70
+
71
+ expect(@larry.score).to eq(@default_health + treasure.points)
72
+ end
73
+
74
+ it "provide their name and score information." do
75
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("pickaxe", 2))
76
+ @larry.find_treasure
77
+
78
+ expect(@larry.print_score).to eq("Larry.................... 102")
79
+ end
80
+
81
+ it "provide their name, health and score information." do
82
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("pickaxe", 2))
83
+ @larry.find_treasure
84
+ @curly.find_treasure
85
+ @moe.find_treasure
86
+
87
+ expect(@larry.to_s).to eq("Larry's health = 100 and score = 102")
88
+ expect(@curly.to_s).to eq("Curly's health = 100 and score = 102")
89
+ expect(@moe.to_s).to eq("Moe's health = 50 and score = 52")
90
+ end
91
+
92
+ it "be strong if their health is 100." do
93
+ expect(@curly).to be_strong
94
+ end
95
+
96
+ it "be strong if their health is 200." do
97
+ @double_initial_health = 200
98
+ @larry = Player.new("larry", @double_initial_health)
99
+
100
+ expect(@larry).to be_strong
101
+ end
102
+
103
+ it "be wimpy if their health below 100." do
104
+ @half_initial_health = 50
105
+ @one_below_initial_health = 99
106
+
107
+ @moe = Player.new("moe", @half_initial_health)
108
+ @curly = Player.new("curly", @one_below_initial_health)
109
+
110
+ expect(@moe).not_to be_strong
111
+ expect(@curly).not_to be_strong
112
+ end
113
+
114
+ it "find a random treasure" do
115
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("ruby", 300))
116
+
117
+ expect(@larry.find_treasure).to eq("Larry found a ruby worth 300 points")
118
+ end
119
+
120
+ context "accumulate" do
121
+ it "one treasure." do
122
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("ruby", 300))
123
+
124
+ @larry.find_treasure
125
+ expect(@larry.found_treasures.size).to eq(1)
126
+ end
127
+
128
+ it "two treasures." do
129
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("ruby", 300), Treasure.new("pickaxe", 2))
130
+
131
+ 2.times { @larry.find_treasure }
132
+ expect(@larry.found_treasures.size).to eq(2)
133
+ end
134
+
135
+ it "three treasures." do
136
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("ruby", 300), Treasure.new("pickaxe", 2), Treasure.new("kindle", 50))
137
+
138
+ 3.times { @larry.find_treasure }
139
+ expect(@larry.found_treasures.size).to eq(3)
140
+ end
141
+
142
+ it "two of the same treasures (counts as one treasure found)." do
143
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("ruby", 300))
144
+
145
+ 10.times { @larry.find_treasure }
146
+ expect(@larry.found_treasures.size).to eq(1)
147
+ end
148
+ end
149
+
150
+ it "earns points" do
151
+ TreasureTrove.stub(:random_treasure).and_return(Treasure.new("ruby", 300))
152
+
153
+ 2.times { @larry.find_treasure }
154
+ expect(@larry.points).to eq(600)
155
+ end
156
+
157
+ it "can be created from a CSV string" do
158
+ player = Player.from_csv("larry,150")
159
+
160
+ expect(player.name).to eq("Larry")
161
+ expect(player.health).to eq(150)
162
+ end
163
+
164
+ end
165
+ end
@@ -0,0 +1,28 @@
1
+ require 'studio_game/treasure'
2
+
3
+ module StudioGame
4
+ describe "Treasure should" do
5
+ before do
6
+ # suppress test puts output only
7
+ $stdout = StringIO.new
8
+
9
+ @fools_gold = Treasure.new("fools gold", 5)
10
+ @bells = Treasure.new("bells", 99)
11
+ end
12
+
13
+ it "have a name." do
14
+ expect(@fools_gold.name).to eq("fools gold")
15
+ expect(@bells.name).to eq("bells")
16
+ end
17
+
18
+ it "have a point value." do
19
+ expect(@fools_gold.points).to eq(5)
20
+ expect(@bells.points).to eq(99)
21
+ end
22
+
23
+ it "share their name and point information." do
24
+ expect(@fools_gold.to_s).to eq("#{@fools_gold.name} worth #{@fools_gold.points} points")
25
+ expect(@bells.to_s).to eq("#{@bells.name} worth #{@bells.points} points")
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,44 @@
1
+ require 'studio_game/treasure_trove'
2
+
3
+ module StudioGame
4
+ describe "TreasureTrove should" do
5
+ before do
6
+ # suppress test puts output only
7
+ $stdout = StringIO.new
8
+
9
+ @treasures = TreasureTrove::TREASURES
10
+ end
11
+
12
+ it "have six treasures, including:" do
13
+ expect(@treasures.size).to eq(6)
14
+ end
15
+
16
+ context "have treasures already" do
17
+ # Bad practice to test for content, but wanted to try out removing duplication by looping through and this was a good candidate (this is a toy app).
18
+
19
+ expected_treasures = {
20
+ "gold":100,
21
+ "stamp":30,
22
+ "pickaxe":2,
23
+ "kindle":50,
24
+ "ruby":300,
25
+ "gem":100
26
+ }
27
+
28
+ expected_treasures.each do |expected_name, expected_points|
29
+ it "* A #{expected_name} treasure worth #{expected_points}." do
30
+ expect(@treasures.any? { |actual_treasure|
31
+ actual_treasure.name == expected_name &&
32
+ actual_treasure.points == expected_points
33
+ })
34
+ end
35
+ end
36
+
37
+ it "can select a random treasure" do
38
+ treasure = TreasureTrove.random_treasure
39
+
40
+ expect(TreasureTrove::TREASURES).to include(treasure)
41
+ end
42
+ end
43
+ end
44
+ end
metadata ADDED
@@ -0,0 +1,231 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_2021
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Becca Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-05-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.8.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ description: |2
34
+
35
+ <!-- TABLE OF CONTENTS -->
36
+ <details open="open">
37
+ <summary>Table of Contents</summary>
38
+ <ol>
39
+ <li>
40
+ <a href="#about-the-project">About The Project</a>
41
+ <ul>
42
+ <li><a href="#built-with">Built With</a></li>
43
+ </ul>
44
+ </li>
45
+ <li>
46
+ <a href="#getting-started">Getting Started</a>
47
+ <ul>
48
+ <li><a href="#prerequisites">Prerequisites</a></li>
49
+ <li><a href="#installation">Installation</a></li>
50
+ </ul>
51
+ </li>
52
+ <li><a href="#usage">Usage</a></li>
53
+ <li><a href="#roadmap">Roadmap</a></li>
54
+ <li><a href="#contributing">Contributing</a></li>
55
+ <li><a href="#license">License</a></li>
56
+ <li><a href="#contact">Contact</a></li>
57
+ <li><a href="#acknowledgements">Acknowledgements</a></li>
58
+ </ol>
59
+ </details>
60
+
61
+ <!-- ABOUT THE PROJECT -->
62
+ ## About The Project
63
+
64
+ [![Product Name Screen Shot][Screenshot of gameplay and test list]](https://www.dropbox.com/s/mu1rrbx2mqowjkn/studio-game.png?dl=0)
65
+
66
+ This game is a project built following the [Pragmatic Studio Ruby Course](https://online.pragmaticstudio.com/courses/ruby/). I absolutely adored going through this course, because it was unlike other courses in that the main focus wasn't syntax, but how to build a principle-driven, object-oriented program that contains many of the skills we'd need to build real-world projects. The instructors purposefully created exercises to let us build a program using the skills they demonstrated by building a different program. This wasn't a copy and paste kind of course. This game was actually my second run-through, where I test-drove everything from the start based on the objectives only.
67
+
68
+ Skills I valued developing further with this project:
69
+ - Test-driven development (50+ tests).
70
+ - Using inheritance to model "is-a" relationships. For example, a clumsy player *is a* kind of player.
71
+ - Using mixins (modules) to reuse behaviours that are common between classes, but should not be modeled with an inheritance relationship. A good tip was to look for 'able' behaviors in a class to extract, like 'playable', 'printable', 'taxable' etc.
72
+ - Using a file block which lets you add in class usage examples that are only run when you run the class file specifically.
73
+ - Overriding default methods (like sort, and renaming things so that they keep a specific format)
74
+
75
+ Things I struggled with:
76
+ - Testing behaviour that uses blocks. I had a lightbulb moment when I realised I should test the behaviour performed inside the block on a single item. Testing the output of an entire block is like testing Ruby syntax works. Alternatively, test the before and after state of something that changes as a result of using a block. Cooool.
77
+ - Puts. It felt wrong to use puts to show the output in the console. I'd like to learn how to seperate the view logic for a command-line project later.
78
+
79
+ Things I did to make it my own:
80
+ - Wrote a lot more tests for my second run-through.
81
+ - Noticed and extracted further 'able' behaviours into modules (like printing stats, formatting output and handling csv files).
82
+
83
+
84
+ ### Built With
85
+
86
+ * [Ruby (language)](https://www.ruby-lang.org/en/)
87
+ * [RSpec (framework)](https://rspec.info/)
88
+ * [Vim (text-editor)](https://www.vim.org/)
89
+
90
+
91
+
92
+ <!-- GETTING STARTED -->
93
+ ## Getting Started
94
+
95
+ To get a local copy up and running follow these steps:
96
+
97
+ ### Prerequisites
98
+
99
+ This is an example of how to list things you need to use the software and how to install them.
100
+ * gem
101
+ ```sh
102
+ npm install npm@latest -g
103
+ ```
104
+
105
+ ### Installation
106
+
107
+ 1. Install the gem
108
+ ```sh
109
+ gem install studio_game_2021
110
+ ```
111
+
112
+ <!-- USAGE EXAMPLES -->
113
+ ## Usage
114
+ To play a game from the command-line, open a new command project and run the command-line script like so:
115
+ ```sh
116
+ studio_game
117
+ ```
118
+
119
+ Or, if you'd like to use the game as a library, here's an example of how to use it in `irb`. You can also check the bottom of each class or module file for further usage instructions
120
+
121
+ ```
122
+ >> require 'studio_game/game'
123
+ => true
124
+
125
+ >> game = StudioGame::Game.new("Knuckleheads")
126
+ => #<StudioGame::Game:0x007fdea10252d8 @title="Knuckleheads", @players=[]>
127
+
128
+ >> player = StudioGame::Player.new("Moe", 90)
129
+ => I'm Moe with health = 90, points = 0, and score = 90.
130
+
131
+ >> game.add_player(player)
132
+ => [I'm Moe with health = 90, points = 0, and score = 90.]
133
+
134
+ >> game.play(1)
135
+ ```
136
+
137
+
138
+ <!-- ROADMAP -->
139
+ ## Roadmap
140
+
141
+ I plan to customize this game further now that I have a solid foundation to explore from. It'll be fun to let the players interact with each other more, like swapping treasures, and maybe add some kind of board game with it's own features. That's my next focus.
142
+
143
+
144
+ ## Contributing
145
+
146
+ Feel free to fork this project and play around with it. Open to feedback-related pr requests.
147
+
148
+
149
+ <!-- LICENSE -->
150
+ ## License
151
+
152
+ Distributed under the MIT License. See `LICENSE` for more information.
153
+
154
+
155
+
156
+ <!-- CONTACT -->
157
+ ## Contact
158
+
159
+ Becca - [@becca9941](https://twitter.com/Becca9941) - becca@essentialistdev.com
160
+
161
+ Project Link: [https://gitlab.com/EssentialistDev/studio-game](https://gitlab.com/EssentialistDev/studio-game)
162
+
163
+
164
+
165
+ <!-- ACKNOWLEDGEMENTS -->
166
+ ## Acknowledgements
167
+
168
+ - [Pragmatic Studio](https://online.pragmaticstudio.com/courses/ruby/) for empowering me with awesome new development skills.
169
+ - [Best-README-Template](https://github.com/Becca9941/Best-README-Template) for helping me write a README for this project.
170
+ email: becca@essentialistdev.com
171
+ executables:
172
+ - studio_game
173
+ extensions: []
174
+ extra_rdoc_files: []
175
+ files:
176
+ - LICENSE
177
+ - README
178
+ - bin/avatar_players.csv
179
+ - bin/players.csv
180
+ - bin/studio_game
181
+ - lib/studio_game/auditable.rb
182
+ - lib/studio_game/berserk_player.rb
183
+ - lib/studio_game/clumsy_player.rb
184
+ - lib/studio_game/die.rb
185
+ - lib/studio_game/formatting.rb
186
+ - lib/studio_game/game.rb
187
+ - lib/studio_game/game_stats.rb
188
+ - lib/studio_game/game_turn.rb
189
+ - lib/studio_game/handle_csv.rb
190
+ - lib/studio_game/loaded_die.rb
191
+ - lib/studio_game/playable.rb
192
+ - lib/studio_game/player.rb
193
+ - lib/studio_game/printable.rb
194
+ - lib/studio_game/treasure.rb
195
+ - lib/studio_game/treasure_trove.rb
196
+ - spec/studio_game/berserk_player_spec.rb
197
+ - spec/studio_game/clumsy_player_spec.rb
198
+ - spec/studio_game/game_spec.rb
199
+ - spec/studio_game/player_spec.rb
200
+ - spec/studio_game/treasure_spec.rb
201
+ - spec/studio_game/treasure_trove_spec.rb
202
+ homepage: https://gitlab.com/EssentialistDev/studio-game
203
+ licenses:
204
+ - MIT
205
+ metadata: {}
206
+ post_install_message:
207
+ rdoc_options: []
208
+ require_paths:
209
+ - lib
210
+ required_ruby_version: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - ">="
213
+ - !ruby/object:Gem::Version
214
+ version: '1.9'
215
+ required_rubygems_version: !ruby/object:Gem::Requirement
216
+ requirements:
217
+ - - ">="
218
+ - !ruby/object:Gem::Version
219
+ version: '0'
220
+ requirements: []
221
+ rubygems_version: 3.1.2
222
+ signing_key:
223
+ specification_version: 4
224
+ summary: A text-based game
225
+ test_files:
226
+ - spec/studio_game/clumsy_player_spec.rb
227
+ - spec/studio_game/treasure_trove_spec.rb
228
+ - spec/studio_game/berserk_player_spec.rb
229
+ - spec/studio_game/player_spec.rb
230
+ - spec/studio_game/treasure_spec.rb
231
+ - spec/studio_game/game_spec.rb