studio_game_erin 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +251 -0
- data/README +1 -0
- data/bin/game_studio +33 -0
- data/bin/high_scores.txt +6 -0
- data/bin/players.csv +3 -0
- data/lib/studio_game/auditable.rb +10 -0
- data/lib/studio_game/beserk_player.rb +38 -0
- data/lib/studio_game/clumsy_player.rb +44 -0
- data/lib/studio_game/die.rb +20 -0
- data/lib/studio_game/game.rb +102 -0
- data/lib/studio_game/game_turn.rb +33 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +19 -0
- data/lib/studio_game/player.rb +63 -0
- data/lib/studio_game/treasure.rb +23 -0
- data/spec/studio_game/berserk_player_spec.rb +37 -0
- data/spec/studio_game/clumsy_player_spec.rb +32 -0
- data/spec/studio_game/game_spec.rb +67 -0
- data/spec/studio_game/player_spec.rb +132 -0
- data/spec/studio_game/treasure_spec.rb +64 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 271d74ebe64cafe7311e1836a803384da87ae070
|
4
|
+
data.tar.gz: 66482fcacdf7572f715bf3a12f33c99f2c0cb5d8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7e7a5b3b415cac81787c65fdb8000877bfda250681b615f740453df5e9c0d5ea0b26a609c5629c1f60be68ec57f42640106791e7a54fc4e1ac3801d4c3fca81d
|
7
|
+
data.tar.gz: 6951bc99df9561b1917f07c95af933133a63088aba39a95e16d4d45f148cb9ffc02f5f82ffa17030dac27c810e2f96e89b34e59728b46d3dc0eb9c205547fe6f
|
data/LICENSE
ADDED
@@ -0,0 +1,251 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
Copyright (c) 2015 <Erin Polsfoot>
|
4
|
+
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
7
|
+
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
9
|
+
|
10
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
11
|
+
|
12
|
+
Comparison to other licenses
|
13
|
+
|
14
|
+
The MIT License is similar to the 3-clause "modified" BSD license, except that the BSD license contains a notice prohibiting the use of the name of the copyright holder in promotion. This is sometimes present in versions of the MIT License, as noted above.
|
15
|
+
|
16
|
+
The original BSD license also includes a clause requiring all advertising of the software to display a notice crediting its authors. This "advertising clause" (since disavowed by UC Berkeley[7]) is present in the modified MIT License used by XFree86.
|
17
|
+
|
18
|
+
The MIT License states more explicitly the rights given to the end-user, including the right to use, copy, modify, merge, publish, distribute, sublicense, and/or sell the software. The MIT license specifically grants the right to "sublicense" in the text of the license itself — a right not mentioned in the BSD license which simply grants the right to "redistribute and use." The right to sublicense means that the party that receives code under the MIT license grant has the legal right to grant all license rights it received downstream to a third party to whom that licensee distributes the MIT code.[8][better source needed]
|
19
|
+
|
20
|
+
Like the BSD license the MIT license does not include an express patent license. Both the BSD and the MIT licenses were drafted before the patentability of software was generally recognized under US law.[9]
|
21
|
+
|
22
|
+
The MIT license contains terms that are used in defining the rights of a patent holder in 35 U.S Code section 154 namely "use," and "sell." This has been construed by some commentators[10] 35 U.S. Code section 154 defines the right of a patent holder as follow: "Every patent shall contain a short title of the invention and a grant to the patentee, his heirs or assigns, of the right to exclude others from making, using, offering for sale, or selling the invention throughout the United States or importing the invention into the United States..."[11] The nature of the right conferred by a U.S. patent is not obvious at first, because it is a negative right, the key is in the words "right to exclude."[12] Any person is ordinarily free to make, use, or sell anything they want, and a grant do so is not needed. What a patent holder has is the right to exclude others from doing what they normally are free to do. So the inclusion of the words granting the right to "use" and "sell" can be construed as meaning no more than the licensee has all the rights they would normally have under a copyright grant. There is no need to infer that these commonly used words mean that the licensor was waiving its patent right to exclude others from such activity (and indeed presumes that the licensor had any such patent rights to exclude to begin with). Whether or not a court might imply a patent grant under the MIT license therefore remains an open question.
|
23
|
+
|
24
|
+
The Simplified BSD license used by FreeBSD is essentially identical[citation needed][discuss] to the MIT License, as it contains neither an advertising clause, nor a prohibition on promotional use of the copyright holder's name.
|
25
|
+
|
26
|
+
Also similar in terms is the ISC license, which has simpler language.
|
27
|
+
|
28
|
+
The University of Illinois/NCSA Open Source License combines text from both the MIT and BSD licenses; the license grant and disclaimer are taken from the MIT License.
|
29
|
+
See also
|
30
|
+
|
31
|
+
Category:Software using the MIT license
|
32
|
+
Comparison of free and open-source software licenses
|
33
|
+
|
34
|
+
Portal icon Free software portal
|
35
|
+
References
|
36
|
+
|
37
|
+
Lawrence Rosen, OPEN SOURCE LICENSING, p.85 (Prentice Hall PTR, 1st ed. 2004)
|
38
|
+
"Various Licenses and Comments about Them". Free Software Foundation. Retrieved 17 July 2013.
|
39
|
+
"Various Licenses and Comments about Them#Expat License". Free Software Foundation. Retrieved 5 December 2010.
|
40
|
+
"Various Licenses and Comments about Them#X11 License". Free Software Foundation. Retrieved 5 December 2010.
|
41
|
+
"Open Source Initiative OSI – The MIT License:Licensing". Open Source Initiative. Retrieved 5 December 2010.
|
42
|
+
Dickey, Thomas E. "NCURSES — Frequently Asked Questions (FAQ)".
|
43
|
+
"To All Licensees, Distributors of Any Version of BSD". University of California, Berkeley. 1999-07-22. Retrieved 2006-11-15.
|
44
|
+
Dictionary.com defines "sublicense" as "a license or contract granted to a third party by a licensee for specified rights or uses of a product, brand name, logo, etc." http://dictionary.reference.com/browse/sublicense
|
45
|
+
Stern and Allen, Open Source Licensing, p. 495 in Understanding the Intellectual Property License 2013 (Practicing Law Institute 2013)
|
46
|
+
Christian H. Nadan, Closing the Loophole; Open Source Licensing and the Implied Patent License, THE COMPUTER AND INTERNET LAWYER, Vol. 26, No. 8 (Aug. 2009) available at http://www.scribd.com/doc/46088081/Closing-the-Loophole-Open-Source-Licensing-and-the-Implied-Patent-License-Nadan who argues that “By using patent terms like “deal in,” “use,” and “sell,” the MIT license grant is more likely to be deemed to include express patent rights than the BSD license.
|
47
|
+
35 U.S. Code section 154 at http://www.law.cornell.edu/uscode/text/35/154; Stern and Allen, supra, p. 495
|
48
|
+
|
49
|
+
Bitlaw, 1996-2013 Daniel A. Tysver (Beck & Tysver) http://www.bitlaw.com/patent/rights.html
|
50
|
+
|
51
|
+
External links
|
52
|
+
|
53
|
+
MIT License variants
|
54
|
+
The MIT License template (Open Source Initiative official site)
|
55
|
+
Expat License
|
56
|
+
X11 License
|
57
|
+
|
58
|
+
[hide]
|
59
|
+
|
60
|
+
v
|
61
|
+
t
|
62
|
+
e
|
63
|
+
|
64
|
+
Free and open-source software
|
65
|
+
General
|
66
|
+
|
67
|
+
Alternative terms for free software
|
68
|
+
Comparison of open source and closed source
|
69
|
+
Comparison of open-source software hosting facilities
|
70
|
+
Formerly proprietary software
|
71
|
+
Free and open-source Android applications
|
72
|
+
Free and open-source software packages
|
73
|
+
Free software
|
74
|
+
Free software events
|
75
|
+
Free software movement
|
76
|
+
Free software project directories
|
77
|
+
Free software web applications
|
78
|
+
Gratis versus libre
|
79
|
+
Long-term support
|
80
|
+
Open-source software
|
81
|
+
Outline
|
82
|
+
SPDX
|
83
|
+
|
84
|
+
Operating system
|
85
|
+
families
|
86
|
+
|
87
|
+
AROS
|
88
|
+
BSD
|
89
|
+
Contiki
|
90
|
+
Darwin
|
91
|
+
eCos
|
92
|
+
FreeDOS
|
93
|
+
GNU
|
94
|
+
Haiku
|
95
|
+
Inferno
|
96
|
+
Linux
|
97
|
+
Mach
|
98
|
+
MINIX
|
99
|
+
OpenSolaris
|
100
|
+
Plan 9
|
101
|
+
ReactOS
|
102
|
+
TUD:OS
|
103
|
+
|
104
|
+
Development
|
105
|
+
|
106
|
+
Basic For Qt
|
107
|
+
Eclipse
|
108
|
+
Free Pascal
|
109
|
+
FreeBASIC
|
110
|
+
Gambas
|
111
|
+
GCC
|
112
|
+
Java
|
113
|
+
Julia
|
114
|
+
LLVM
|
115
|
+
Lua
|
116
|
+
NetBeans
|
117
|
+
Open64
|
118
|
+
OpenSSH
|
119
|
+
Perl
|
120
|
+
PHP
|
121
|
+
Python
|
122
|
+
ROSE
|
123
|
+
Ruby
|
124
|
+
Tcl
|
125
|
+
|
126
|
+
History
|
127
|
+
|
128
|
+
GNU
|
129
|
+
Haiku
|
130
|
+
Linux
|
131
|
+
Mozilla
|
132
|
+
Application Suite
|
133
|
+
Firefox
|
134
|
+
Thunderbird
|
135
|
+
|
136
|
+
Organizations
|
137
|
+
|
138
|
+
Android Open Source Project
|
139
|
+
Apache Software Foundation
|
140
|
+
Blender Foundation
|
141
|
+
The Document Foundation
|
142
|
+
Eclipse Foundation
|
143
|
+
Free Software Foundation
|
144
|
+
Europe
|
145
|
+
India
|
146
|
+
Latin America
|
147
|
+
FreeBSD Foundation
|
148
|
+
freedesktop.org
|
149
|
+
FSMI
|
150
|
+
GNOME Foundation
|
151
|
+
GNU Project
|
152
|
+
Google Code
|
153
|
+
KDE e.V.
|
154
|
+
Linux Foundation
|
155
|
+
Mozilla Foundation
|
156
|
+
Open Knowledge Foundation
|
157
|
+
Open Source Geospatial Foundation
|
158
|
+
Open Source Initiative
|
159
|
+
OpenBSD Foundation
|
160
|
+
Software Freedom Conservancy
|
161
|
+
SourceForge
|
162
|
+
Symbian Foundation
|
163
|
+
Ubuntu Foundation
|
164
|
+
VideoLAN Organization
|
165
|
+
Wikimedia Foundation
|
166
|
+
X.Org Foundation
|
167
|
+
Xiph.Org Foundation
|
168
|
+
XMPP Standards Foundation
|
169
|
+
|
170
|
+
Licenses
|
171
|
+
|
172
|
+
Apache
|
173
|
+
Artistic
|
174
|
+
Beerware
|
175
|
+
Boost
|
176
|
+
BSD
|
177
|
+
CC0
|
178
|
+
CDDL
|
179
|
+
GNU GPL
|
180
|
+
GNU LGPL
|
181
|
+
ISC
|
182
|
+
MIT
|
183
|
+
MPL
|
184
|
+
Ms-PL/RL
|
185
|
+
WTFPL
|
186
|
+
zlib
|
187
|
+
|
188
|
+
License types
|
189
|
+
and standards
|
190
|
+
|
191
|
+
Comparison of free and open-source software licenses
|
192
|
+
Contributor License Agreement
|
193
|
+
Copyfree
|
194
|
+
Copyleft
|
195
|
+
Debian Free Software Guidelines
|
196
|
+
Definition of Free Cultural Works
|
197
|
+
Free license
|
198
|
+
The Free Software Definition
|
199
|
+
The Open Source Definition
|
200
|
+
Open-source license
|
201
|
+
Permissive free software licence
|
202
|
+
Public domain
|
203
|
+
Viral license
|
204
|
+
|
205
|
+
Challenges
|
206
|
+
|
207
|
+
Binary blob
|
208
|
+
Digital rights management
|
209
|
+
Free and open-source graphics device driver
|
210
|
+
Comparison of open-source wireless drivers
|
211
|
+
Hardware restrictions
|
212
|
+
License proliferation
|
213
|
+
Mozilla software rebranding
|
214
|
+
Proprietary software
|
215
|
+
SCO–Linux controversies
|
216
|
+
Secure boot
|
217
|
+
Software patents
|
218
|
+
Software security
|
219
|
+
Trusted Computing
|
220
|
+
|
221
|
+
Related topics
|
222
|
+
|
223
|
+
The Cathedral and the Bazaar
|
224
|
+
Forking
|
225
|
+
Linux distribution
|
226
|
+
Microsoft Open Specification Promise
|
227
|
+
Revolution OS
|
228
|
+
|
229
|
+
Wikipedia book Book
|
230
|
+
Category Category
|
231
|
+
Commons page Commons
|
232
|
+
Portal Portal
|
233
|
+
|
234
|
+
Categories:
|
235
|
+
|
236
|
+
Free and open-source software licenses
|
237
|
+
X Window System
|
238
|
+
Massachusetts Institute of Technology
|
239
|
+
|
240
|
+
Navigation menu
|
241
|
+
|
242
|
+
Create account
|
243
|
+
Log in
|
244
|
+
|
245
|
+
Article
|
246
|
+
Talk
|
247
|
+
|
248
|
+
Read
|
249
|
+
Edit
|
250
|
+
|
251
|
+
More
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
A quick game that iterates through multiple players
|
data/bin/game_studio
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/studio_game/game'
|
4
|
+
require_relative '../lib/studio_game/clumsy_player'
|
5
|
+
require_relative '../lib/studio_game/beserk_player'
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
knuckleheads = StudioGame::Game.new('Knucklehead')
|
10
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
11
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
12
|
+
|
13
|
+
clumsy = StudioGame::ClumsyPlayer.new('klutz', 105)
|
14
|
+
knuckleheads.add_players(clumsy)
|
15
|
+
berserker = StudioGame::BerserkPlayer.new('berserker', 50)
|
16
|
+
knuckleheads.add_players(berserker)
|
17
|
+
|
18
|
+
|
19
|
+
loop do
|
20
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
21
|
+
answer = gets.chomp.downcase
|
22
|
+
case answer
|
23
|
+
when /^\d+$/
|
24
|
+
knuckleheads.play(answer.to_i)
|
25
|
+
when 'quit', 'exit'
|
26
|
+
knuckleheads.print_stats
|
27
|
+
break
|
28
|
+
else
|
29
|
+
puts "Please enter a number or 'quit'"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
knuckleheads.save_high_scores
|
data/bin/high_scores.txt
ADDED
data/bin/players.csv
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
class BerserkPlayer < Player
|
6
|
+
|
7
|
+
def initialize(name, health=100)
|
8
|
+
super(name, health)
|
9
|
+
@woot_count = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def beserk?
|
14
|
+
@woot_count > 5
|
15
|
+
end
|
16
|
+
|
17
|
+
def w00t
|
18
|
+
super
|
19
|
+
@woot_count += 1
|
20
|
+
puts "#{@name} is beserk!" if beserk?
|
21
|
+
end
|
22
|
+
|
23
|
+
def blam
|
24
|
+
if beserk?
|
25
|
+
w00t
|
26
|
+
else
|
27
|
+
super
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if __FILE__ == $0
|
33
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
34
|
+
6.times { berserker.w00t }
|
35
|
+
2.times { berserker.blam }
|
36
|
+
puts berserker.health
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
class ClumsyPlayer < Player
|
6
|
+
|
7
|
+
attr_reader :boost_factor
|
8
|
+
|
9
|
+
def initialize(name, health=100, boost_factor=1)
|
10
|
+
super(name, health)
|
11
|
+
@boost_factor = boost_factor
|
12
|
+
end
|
13
|
+
|
14
|
+
def boost
|
15
|
+
@boost_factor.times {super}
|
16
|
+
end
|
17
|
+
|
18
|
+
def found_treasure(treasure)
|
19
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points/ 2.0)
|
20
|
+
super(damaged_treasure)
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
if __FILE__ == $0
|
28
|
+
clumsy = ClumsyPlayer.new("klutz", 105, 3)
|
29
|
+
|
30
|
+
hammer = Treasure.new(:hammer, 50)
|
31
|
+
clumsy.found_treasure(hammer)
|
32
|
+
clumsy.found_treasure(hammer)
|
33
|
+
clumsy.found_treasure(hammer)
|
34
|
+
|
35
|
+
crowbar = Treasure.new(:crowbar, 400)
|
36
|
+
clumsy.found_treasure(crowbar)
|
37
|
+
|
38
|
+
clumsy.each_found_treasure do |treasure|
|
39
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
40
|
+
end
|
41
|
+
puts "#{clumsy.points} grand total points"
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'game_turn'
|
4
|
+
require_relative 'treasure'
|
5
|
+
module StudioGame
|
6
|
+
class Game
|
7
|
+
|
8
|
+
attr_reader :title
|
9
|
+
|
10
|
+
def initialize(title)
|
11
|
+
@title = title
|
12
|
+
@players = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_players(from_file)
|
16
|
+
File.readlines(from_file).each do |line|
|
17
|
+
add_players(Player.from_csv(line))
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def high_score_entry(player)
|
22
|
+
formatted_name = player.name.ljust(20, '.')
|
23
|
+
"#{formatted_name} #{player.score}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def save_high_scores(to_file="high_scores.txt")
|
27
|
+
File.open(to_file, "w") do |file|
|
28
|
+
file.puts "#{@title} High Scores:"
|
29
|
+
@players.sort.each do |player|
|
30
|
+
file.puts high_score_entry(player)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
def add_players(player)
|
37
|
+
@players << player
|
38
|
+
end
|
39
|
+
|
40
|
+
def total_points
|
41
|
+
@players.reduce(0) {|sum, player| sum + player.points}
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def play(rounds)
|
46
|
+
puts "There are #{@players.size} players in #{@title}:"
|
47
|
+
|
48
|
+
@players.each do |player|
|
49
|
+
puts player
|
50
|
+
end
|
51
|
+
|
52
|
+
treasures = TreasureTrove::TREASURES
|
53
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
54
|
+
treasures.each do |treasure|
|
55
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
56
|
+
end
|
57
|
+
|
58
|
+
1.upto(rounds) do |round|
|
59
|
+
if block_given?
|
60
|
+
break if yield
|
61
|
+
end
|
62
|
+
puts "\nRounds #{round}:"
|
63
|
+
@players.each do |player|
|
64
|
+
GameTurn.take_turn(player)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def print_name_and_health(player)
|
70
|
+
puts "#{player.name} (#{player.health})"
|
71
|
+
end
|
72
|
+
|
73
|
+
def print_stats
|
74
|
+
strong_players, wimpy_players = @players.partition {|player| player.strong?}
|
75
|
+
puts "\n#{@title} Statistics:"
|
76
|
+
|
77
|
+
puts "\n#{strong_players.size} strong players:"
|
78
|
+
strong_players.each do |player|
|
79
|
+
print_name_and_health(player)
|
80
|
+
end
|
81
|
+
puts "\n#{wimpy_players.size} wimpy players:"
|
82
|
+
wimpy_players.each do |player|
|
83
|
+
print_name_and_health(player)
|
84
|
+
end
|
85
|
+
|
86
|
+
puts "\n#{@title} High Scores:"
|
87
|
+
@players.sort.each do |player|
|
88
|
+
puts high_score_entry(player)
|
89
|
+
end
|
90
|
+
|
91
|
+
puts "\nPoint Stats:"
|
92
|
+
@players.each do |player|
|
93
|
+
puts "\n#{player.name}'s point totals:"
|
94
|
+
player.each_found_treasure {|treasure| puts "#{treasure.points} total #{treasure.name} points"}
|
95
|
+
puts "#{player.points} grand total points"
|
96
|
+
end
|
97
|
+
|
98
|
+
puts "\nGrand Total: #{total_points}"
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'treasure'
|
4
|
+
require_relative 'loaded_die'
|
5
|
+
module StudioGame
|
6
|
+
module GameTurn
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
def self.take_turn(player)
|
11
|
+
die = Die.new
|
12
|
+
|
13
|
+
case die.roll
|
14
|
+
when 1..2
|
15
|
+
player.blam
|
16
|
+
when 3..4
|
17
|
+
puts "#{player.name} was skipped"
|
18
|
+
else
|
19
|
+
player.w00t
|
20
|
+
end
|
21
|
+
|
22
|
+
treasure = TreasureTrove.random
|
23
|
+
player.found_treasure(treasure)
|
24
|
+
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
if __FILE__ == $0
|
30
|
+
player = Player.new("curly", 125)
|
31
|
+
GameTurn.take_turn(player)
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'treasure'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
include Playable
|
7
|
+
attr_accessor :name, :health
|
8
|
+
|
9
|
+
def initialize(name, health=100)
|
10
|
+
@name = name.capitalize
|
11
|
+
@health = health
|
12
|
+
@found_treasures = Hash.new(0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_csv(string)
|
16
|
+
name, health= string.split(",")
|
17
|
+
Player.new(name, Integer(health))
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def found_treasure(treasure)
|
22
|
+
@found_treasures[treasure.name] += treasure.points
|
23
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
24
|
+
puts "#{@name}'s treasures: #{@found_treasures}"
|
25
|
+
end
|
26
|
+
|
27
|
+
def points
|
28
|
+
@found_treasures.values.reduce(0, :+)
|
29
|
+
end
|
30
|
+
|
31
|
+
def score
|
32
|
+
@health + points
|
33
|
+
end
|
34
|
+
|
35
|
+
def <=>(other)
|
36
|
+
other.score <=> score
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
def to_s
|
41
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
42
|
+
end
|
43
|
+
|
44
|
+
def each_found_treasure
|
45
|
+
@found_treasures.each do |name, points|
|
46
|
+
treasure = Treasure.new(name, points)
|
47
|
+
yield treasure
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
if __FILE__ == $0
|
55
|
+
player = Player.new("moe")
|
56
|
+
puts player.name
|
57
|
+
puts player.health
|
58
|
+
player.w00t
|
59
|
+
puts player.health
|
60
|
+
player.blam
|
61
|
+
puts player.health
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
|
2
|
+
module StudioGame
|
3
|
+
Treasure = Struct.new(:name, :points)
|
4
|
+
|
5
|
+
module TreasureTrove
|
6
|
+
TREASURES = [
|
7
|
+
Treasure.new(:pie, 5),
|
8
|
+
Treasure.new(:bottle, 25),
|
9
|
+
Treasure.new(:hammer, 50),
|
10
|
+
Treasure.new(:skillet, 100),
|
11
|
+
Treasure.new(:broomstick, 200),
|
12
|
+
Treasure.new(:crowbar, 400)
|
13
|
+
]
|
14
|
+
|
15
|
+
def self.random
|
16
|
+
TREASURES.sample
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if __FILE__ == $0
|
21
|
+
puts TreasureTrove::TREASURES
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'studio_game/beserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe BerserkPlayer do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@initial_health = 50
|
8
|
+
@player = BerserkPlayer.new("berserker", @initial_health)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does not go berserk when w00ted up to 5 times" do
|
12
|
+
1.upto(5) { @player.w00t }
|
13
|
+
|
14
|
+
@player.beserk?.should be_falsey
|
15
|
+
|
16
|
+
# or if using Rspec 3.0:
|
17
|
+
# @player.berserk?.should be_falsey
|
18
|
+
end
|
19
|
+
|
20
|
+
it "goes berserk when w00ted more than 5 times" do
|
21
|
+
1.upto(6) { @player.w00t }
|
22
|
+
|
23
|
+
@player.beserk?.should be_truthy
|
24
|
+
|
25
|
+
# or if using Rspec 3.0:
|
26
|
+
# @player.berserk?.should be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
30
|
+
1.upto(6) { @player.w00t }
|
31
|
+
1.upto(2) { @player.blam }
|
32
|
+
|
33
|
+
@player.health.should == @initial_health + (8 * 15)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
module StudioGame
|
3
|
+
describe ClumsyPlayer do
|
4
|
+
before do
|
5
|
+
@player = ClumsyPlayer.new("klutz")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "only gets half the point value for each treasure" do
|
9
|
+
@player.points.should == 0
|
10
|
+
|
11
|
+
hammer = Treasure.new(:hammer, 50)
|
12
|
+
@player.found_treasure(hammer)
|
13
|
+
@player.found_treasure(hammer)
|
14
|
+
@player.found_treasure(hammer)
|
15
|
+
|
16
|
+
@player.points.should == 75
|
17
|
+
|
18
|
+
crowbar = Treasure.new(:crowbar, 400)
|
19
|
+
@player.found_treasure(crowbar)
|
20
|
+
|
21
|
+
@player.points.should == 275
|
22
|
+
|
23
|
+
yielded = []
|
24
|
+
@player.each_found_treasure do |treasure|
|
25
|
+
yielded << treasure
|
26
|
+
end
|
27
|
+
|
28
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Game do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@game = Game.new("Knuckleheads")
|
8
|
+
|
9
|
+
@initial_health = 100
|
10
|
+
@player = Player.new("moe", @initial_health)
|
11
|
+
|
12
|
+
@game.add_players(@player)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "high number is rolled" do
|
16
|
+
Die.any_instance.stub(:roll).and_return(5)
|
17
|
+
@game.play(2)
|
18
|
+
|
19
|
+
@player.health.should == (@initial_health + (15*2))
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
it "medium number is rolled" do
|
24
|
+
Die.any_instance.stub(:roll).and_return(3)
|
25
|
+
@game.play(2)
|
26
|
+
|
27
|
+
@player.health.should == @initial_health
|
28
|
+
end
|
29
|
+
|
30
|
+
it "low number is rolled" do
|
31
|
+
Die.any_instance.stub(:roll).and_return(1)
|
32
|
+
@game.play(2)
|
33
|
+
@player.health.should == (@initial_health - (10*2))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "assigns a treasure for points during a player's turn" do
|
37
|
+
game = Game.new("Knuckleheads")
|
38
|
+
player = Player.new("moe")
|
39
|
+
|
40
|
+
game.add_players(player)
|
41
|
+
|
42
|
+
game.play(1)
|
43
|
+
|
44
|
+
player.points.should_not be_zero
|
45
|
+
|
46
|
+
# or use alternate expectation syntax:
|
47
|
+
# expect(player.points).not_to be_zero
|
48
|
+
end
|
49
|
+
|
50
|
+
it "computes total points as the sum of all player points" do
|
51
|
+
game = Game.new("Knuckleheads")
|
52
|
+
|
53
|
+
player1 = Player.new("moe")
|
54
|
+
player2 = Player.new("larry")
|
55
|
+
|
56
|
+
game.add_players(player1)
|
57
|
+
game.add_players(player2)
|
58
|
+
|
59
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
60
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
61
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
62
|
+
|
63
|
+
game.total_points.should == 500
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'studio_game/player'
|
3
|
+
require 'studio_game/treasure'
|
4
|
+
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
describe Player do
|
8
|
+
|
9
|
+
before do
|
10
|
+
$stdout = StringIO.new
|
11
|
+
@initial_health = 150
|
12
|
+
@player = Player.new("larry", @initial_health)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
it "has a capitalized name" do
|
17
|
+
@player.name.should == "Larry"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has an initial health" do
|
21
|
+
@player.health.should == 150
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has a string representation" do
|
25
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
26
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
27
|
+
|
28
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
|
29
|
+
end
|
30
|
+
|
31
|
+
it "computes a score as the sum of its health and points" do
|
32
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
33
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
34
|
+
|
35
|
+
@player.score.should == 250
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
it "increase health by 15 when w00ted" do
|
40
|
+
@player.w00t
|
41
|
+
@player.health.should == (@initial_health+15)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "decreases health by 10 when blammed" do
|
45
|
+
@player.blam
|
46
|
+
@player.health.should == (@initial_health-10)
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'with a health greater than 100' do
|
50
|
+
before do
|
51
|
+
@player = Player.new("larry", 150)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "player is strong" do
|
55
|
+
@player.should be_strong
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'with a health less than 100' do
|
61
|
+
before do
|
62
|
+
@player = Player.new("larry", 100)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "player is wimpy" do
|
66
|
+
@player.should_not be_strong
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "in a collection of players" do
|
71
|
+
before do
|
72
|
+
@player1 = Player.new("moe", 100)
|
73
|
+
@player2 = Player.new("larry", 200)
|
74
|
+
@player3 = Player.new("curly", 300)
|
75
|
+
|
76
|
+
@players = [@player1, @player2, @player3]
|
77
|
+
end
|
78
|
+
|
79
|
+
it "is sorted by decreasing score" do
|
80
|
+
@players.sort.should == [@player3, @player2, @player1]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "computes points as the sum of all treasure points" do
|
85
|
+
@player.points.should == 0
|
86
|
+
|
87
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
88
|
+
|
89
|
+
@player.points.should == 50
|
90
|
+
|
91
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
92
|
+
|
93
|
+
@player.points.should == 450
|
94
|
+
|
95
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
96
|
+
|
97
|
+
@player.points.should == 500
|
98
|
+
end
|
99
|
+
|
100
|
+
it "can be created from a csv string" do
|
101
|
+
player = Player.from_csv("larry,150")
|
102
|
+
|
103
|
+
player.name.should == "Larry"
|
104
|
+
player.health.should == 150
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
it "yields each found treasure and its total points" do
|
110
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
111
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
112
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
113
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
114
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
115
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
116
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
117
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
118
|
+
|
119
|
+
yielded = []
|
120
|
+
@player.each_found_treasure do |treasure|
|
121
|
+
yielded << treasure
|
122
|
+
end
|
123
|
+
|
124
|
+
yielded.should == [
|
125
|
+
Treasure.new(:skillet, 200),
|
126
|
+
Treasure.new(:hammer, 50),
|
127
|
+
Treasure.new(:bottle, 25)
|
128
|
+
]
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'studio_game/treasure'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
|
6
|
+
describe Treasure do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@treasure = Treasure.new(:hammer, 50)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a name attribute" do
|
13
|
+
@treasure.name.should == :hammer
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a points attribute" do
|
17
|
+
@treasure.points.should == 50
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
describe TreasureTrove do
|
23
|
+
|
24
|
+
it "has six treasures" do
|
25
|
+
TreasureTrove::TREASURES.size.should == 6
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a pie worth 5 points" do
|
29
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a bottle worth 25 points" do
|
33
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a hammer worth 50 points" do
|
37
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a skillet worth 100 points" do
|
41
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has a broomstick worth 200 points" do
|
45
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has a crowbar worth 400 points" do
|
49
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "returns a random treasure" do
|
53
|
+
treasure = TreasureTrove.random
|
54
|
+
|
55
|
+
TreasureTrove::TREASURES.should include(treasure)
|
56
|
+
|
57
|
+
# or use alternate expectation syntax:
|
58
|
+
# expect(TreasureTrove::TREASURES).to include(treasure)
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio_game_erin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Erin Polsfoot
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-02-24 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: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: A quick game that iterates through multiple players
|
28
|
+
email: erinpolsfoot@gmail.com
|
29
|
+
executables:
|
30
|
+
- game_studio
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README
|
36
|
+
- bin/game_studio
|
37
|
+
- bin/high_scores.txt
|
38
|
+
- bin/players.csv
|
39
|
+
- lib/studio_game/auditable.rb
|
40
|
+
- lib/studio_game/beserk_player.rb
|
41
|
+
- lib/studio_game/clumsy_player.rb
|
42
|
+
- lib/studio_game/die.rb
|
43
|
+
- lib/studio_game/game.rb
|
44
|
+
- lib/studio_game/game_turn.rb
|
45
|
+
- lib/studio_game/loaded_die.rb
|
46
|
+
- lib/studio_game/playable.rb
|
47
|
+
- lib/studio_game/player.rb
|
48
|
+
- lib/studio_game/treasure.rb
|
49
|
+
- spec/studio_game/berserk_player_spec.rb
|
50
|
+
- spec/studio_game/clumsy_player_spec.rb
|
51
|
+
- spec/studio_game/game_spec.rb
|
52
|
+
- spec/studio_game/player_spec.rb
|
53
|
+
- spec/studio_game/treasure_spec.rb
|
54
|
+
homepage: http://erinpolsfoot.com
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.9'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.4.3
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Short Game for Fun
|
78
|
+
test_files:
|
79
|
+
- spec/studio_game/berserk_player_spec.rb
|
80
|
+
- spec/studio_game/player_spec.rb
|
81
|
+
- spec/studio_game/treasure_spec.rb
|
82
|
+
- spec/studio_game/clumsy_player_spec.rb
|
83
|
+
- spec/studio_game/game_spec.rb
|