studio_game_dd2026 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.
- checksums.yaml +7 -0
- data/bin/players.csv +5 -0
- data/bin/studio_game +324 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +31 -0
- data/lib/studio_game/clumsy_player.rb +32 -0
- data/lib/studio_game/game.rb +104 -0
- data/lib/studio_game/playable.rb +11 -0
- data/lib/studio_game/player.rb +48 -0
- data/lib/studio_game/treasure_trove.rb +22 -0
- metadata +48 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 415e8de831595a60ce69a81642186d17d94f46c567614606070a503ac7828a85
|
|
4
|
+
data.tar.gz: 5f6534741b21ed111e3d0b2918583a2083101a9b8e4cf1973bec074aa1b0e6bc
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: ee9e466ccd85f70a736cac3405a9c5399776adb8604624809693b54ba5a5c5cfe7cc70c64bc104984904c94ed897d3ad00db217a4e1845e6a4fb76493688037a
|
|
7
|
+
data.tar.gz: 8a202d3f1786bc7c45fa4684686d74ca8bc722c33a303ae2ae36b6effd03ee3c3dfb418ee757f94c886b64cd0cd838ebf63325a23ce8fe4095e18f1b4861e5da
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
# # Objects Everywhere
|
|
4
|
+
|
|
5
|
+
# name = "finn"
|
|
6
|
+
# health = 60
|
|
7
|
+
# puts "#{name.capitalize}'s health is #{health}".center(50,"*")
|
|
8
|
+
# puts "#{name.capitalize.ljust(50, ".")} #{health} health"
|
|
9
|
+
|
|
10
|
+
# name = " \n finn \t "
|
|
11
|
+
# puts name.strip
|
|
12
|
+
|
|
13
|
+
# health = 123
|
|
14
|
+
# puts health.to_s.reverse
|
|
15
|
+
# puts health.to_s.reverse.to_i
|
|
16
|
+
# puts health.pow(2)
|
|
17
|
+
|
|
18
|
+
# # Making Methods
|
|
19
|
+
|
|
20
|
+
# def say_hello(name:, health: 100)
|
|
21
|
+
# "I'm #{name.capitalize} with a health of #{health}"
|
|
22
|
+
# end
|
|
23
|
+
|
|
24
|
+
# puts say_hello(name: "Dany")
|
|
25
|
+
# puts say_hello(health: 80, name: "Jhonatan")
|
|
26
|
+
# puts say_hello(name: "Willy")
|
|
27
|
+
|
|
28
|
+
# # Crafting Classes
|
|
29
|
+
|
|
30
|
+
# class Player
|
|
31
|
+
# def initialize(name, health=100)
|
|
32
|
+
# @name = name.capitalize
|
|
33
|
+
# @health = health
|
|
34
|
+
# end
|
|
35
|
+
|
|
36
|
+
# def to_s = "I'm #{@name} with a health of #{@health}"
|
|
37
|
+
|
|
38
|
+
# def drain
|
|
39
|
+
# @health -= 10
|
|
40
|
+
# end
|
|
41
|
+
|
|
42
|
+
# def boost
|
|
43
|
+
# @health += 15
|
|
44
|
+
# end
|
|
45
|
+
# end
|
|
46
|
+
|
|
47
|
+
# player_1 = Player.new("finn", 60)
|
|
48
|
+
# puts player_1
|
|
49
|
+
|
|
50
|
+
# player_2 = Player.new("lucy", 90)
|
|
51
|
+
# puts player_2
|
|
52
|
+
|
|
53
|
+
# player_3 = Player.new("jase")
|
|
54
|
+
# puts player_3
|
|
55
|
+
|
|
56
|
+
# player_4 = Player.new("alex", 125)
|
|
57
|
+
# puts player_4
|
|
58
|
+
# player_4.drain
|
|
59
|
+
# puts player_4
|
|
60
|
+
# player_4.boost
|
|
61
|
+
# puts player_4
|
|
62
|
+
|
|
63
|
+
# # Attr is for attribute
|
|
64
|
+
|
|
65
|
+
# class Player
|
|
66
|
+
# attr_reader :health
|
|
67
|
+
# attr_accessor :name
|
|
68
|
+
|
|
69
|
+
# def initialize(name, health=100)
|
|
70
|
+
# @name = name.capitalize
|
|
71
|
+
# @health = health
|
|
72
|
+
# end
|
|
73
|
+
|
|
74
|
+
# def to_s = "I'm #{@name} with a health of #{@health} and a score of #{score}"
|
|
75
|
+
|
|
76
|
+
# def drain
|
|
77
|
+
# @health -= 10
|
|
78
|
+
# end
|
|
79
|
+
|
|
80
|
+
# def boost
|
|
81
|
+
# @health += 15
|
|
82
|
+
# end
|
|
83
|
+
|
|
84
|
+
# def score
|
|
85
|
+
# @health + @name.length
|
|
86
|
+
# end
|
|
87
|
+
# end
|
|
88
|
+
|
|
89
|
+
# player_1 = Player.new("finn", 60)
|
|
90
|
+
# player_2 = Player.new("lucy", 90)
|
|
91
|
+
# player_3 = Player.new("jase")
|
|
92
|
+
# player_4 = Player.new("alex", 125)
|
|
93
|
+
|
|
94
|
+
# puts player_1.health
|
|
95
|
+
# puts player_2.health
|
|
96
|
+
# puts player_3.health
|
|
97
|
+
# puts player_4.health
|
|
98
|
+
# player_4.name = "Alexander"
|
|
99
|
+
# puts player_4
|
|
100
|
+
|
|
101
|
+
# # What's your condition
|
|
102
|
+
|
|
103
|
+
# class Player
|
|
104
|
+
# attr_reader :health
|
|
105
|
+
# attr_accessor :name
|
|
106
|
+
|
|
107
|
+
# def initialize(name, health=100)
|
|
108
|
+
# @name = name.capitalize
|
|
109
|
+
# @health = health
|
|
110
|
+
# end
|
|
111
|
+
|
|
112
|
+
# def to_s = "I'm #{@name} with a health of #{@health} and a score of #{score}"
|
|
113
|
+
|
|
114
|
+
# def drain
|
|
115
|
+
# @health -= 10
|
|
116
|
+
# end
|
|
117
|
+
|
|
118
|
+
# def boost
|
|
119
|
+
# @health += 15
|
|
120
|
+
# end
|
|
121
|
+
|
|
122
|
+
# def score
|
|
123
|
+
# @health + @name.length
|
|
124
|
+
# end
|
|
125
|
+
# end
|
|
126
|
+
|
|
127
|
+
# player_1 = Player.new("finn", 60)
|
|
128
|
+
|
|
129
|
+
# number_rolled = rand(1..6)
|
|
130
|
+
|
|
131
|
+
# case number_rolled
|
|
132
|
+
# when 1..2
|
|
133
|
+
# player_1.drain
|
|
134
|
+
# puts "#{player_1.name} got drained 😩"
|
|
135
|
+
# when 3..4
|
|
136
|
+
# puts "#{player_1.name} got skipped"
|
|
137
|
+
# else
|
|
138
|
+
# player_1.boost
|
|
139
|
+
# puts "#{player_1.name} got boosted 😁"
|
|
140
|
+
# end
|
|
141
|
+
|
|
142
|
+
# # player_2 = Player.new("lucy", 90)
|
|
143
|
+
# # player_3 = Player.new("jase")
|
|
144
|
+
# # player_4 = Player.new("alex", 125)
|
|
145
|
+
|
|
146
|
+
# # puts player_1.health
|
|
147
|
+
# # puts player_2.health
|
|
148
|
+
# # puts player_3.health
|
|
149
|
+
# # puts player_4.health
|
|
150
|
+
# # player_4.name = "Alexander"
|
|
151
|
+
# # puts player_4
|
|
152
|
+
|
|
153
|
+
# # Array party
|
|
154
|
+
|
|
155
|
+
# class Player
|
|
156
|
+
# attr_reader :health
|
|
157
|
+
# attr_accessor :name
|
|
158
|
+
|
|
159
|
+
# def initialize(name, health=100)
|
|
160
|
+
# @name = name.capitalize
|
|
161
|
+
# @health = health
|
|
162
|
+
# end
|
|
163
|
+
|
|
164
|
+
# def to_s = "I'm #{@name} with a health of #{@health} and a score of #{score}"
|
|
165
|
+
|
|
166
|
+
# def drain
|
|
167
|
+
# @health -= 10
|
|
168
|
+
# end
|
|
169
|
+
|
|
170
|
+
# def boost
|
|
171
|
+
# @health += 15
|
|
172
|
+
# end
|
|
173
|
+
|
|
174
|
+
# def score
|
|
175
|
+
# @health + @name.length
|
|
176
|
+
# end
|
|
177
|
+
# end
|
|
178
|
+
|
|
179
|
+
# player_1 = Player.new("finn", 60)
|
|
180
|
+
# player_2 = Player.new("lucy", 90)
|
|
181
|
+
# player_3 = Player.new("jase")
|
|
182
|
+
# player_4 = Player.new("alex", 125)
|
|
183
|
+
|
|
184
|
+
# players = [player_1, player_2, player_3, player_4]
|
|
185
|
+
# players.pop
|
|
186
|
+
# player_5 = Player.new("cole", 75)
|
|
187
|
+
# players.push(player_5)
|
|
188
|
+
|
|
189
|
+
# puts "Before playing:"
|
|
190
|
+
# puts players
|
|
191
|
+
|
|
192
|
+
# players.each do |player|
|
|
193
|
+
# number_rolled = rand(1..6)
|
|
194
|
+
# case number_rolled
|
|
195
|
+
# when 1..2
|
|
196
|
+
# player.drain
|
|
197
|
+
# puts "#{player.name} got drained 😩"
|
|
198
|
+
# when 3..4
|
|
199
|
+
# puts "#{player.name} got skipped"
|
|
200
|
+
# else
|
|
201
|
+
# player.boost
|
|
202
|
+
# puts "#{player.name} got boosted 😁"
|
|
203
|
+
# end
|
|
204
|
+
# end
|
|
205
|
+
|
|
206
|
+
# puts "\nAfter playing:"
|
|
207
|
+
# puts players
|
|
208
|
+
|
|
209
|
+
# # Objects Collaborating
|
|
210
|
+
|
|
211
|
+
# class Player
|
|
212
|
+
# attr_reader :health
|
|
213
|
+
# attr_accessor :name
|
|
214
|
+
|
|
215
|
+
# def initialize(name, health=100)
|
|
216
|
+
# @name = name.capitalize
|
|
217
|
+
# @health = health
|
|
218
|
+
# end
|
|
219
|
+
|
|
220
|
+
# def to_s = "I'm #{@name} with a health of #{@health} and a score of #{score}"
|
|
221
|
+
|
|
222
|
+
# def drain
|
|
223
|
+
# @health -= 10
|
|
224
|
+
# end
|
|
225
|
+
|
|
226
|
+
# def boost
|
|
227
|
+
# @health += 15
|
|
228
|
+
# end
|
|
229
|
+
|
|
230
|
+
# def score
|
|
231
|
+
# @health + @name.length
|
|
232
|
+
# end
|
|
233
|
+
# end
|
|
234
|
+
|
|
235
|
+
# class Game
|
|
236
|
+
# attr_reader :title, :players
|
|
237
|
+
|
|
238
|
+
# def initialize(title)
|
|
239
|
+
# @title = title
|
|
240
|
+
# @players = []
|
|
241
|
+
# end
|
|
242
|
+
|
|
243
|
+
# def add_player(player)
|
|
244
|
+
# @players << player
|
|
245
|
+
# end
|
|
246
|
+
|
|
247
|
+
# def roll_die
|
|
248
|
+
# rand(1..6)
|
|
249
|
+
# end
|
|
250
|
+
|
|
251
|
+
# def play
|
|
252
|
+
# puts "\nLet's play #{title}!"
|
|
253
|
+
# puts "\nBefore playing:"
|
|
254
|
+
# puts @players
|
|
255
|
+
|
|
256
|
+
# @players.each do |player|
|
|
257
|
+
# number_rolled = roll_die
|
|
258
|
+
# case number_rolled
|
|
259
|
+
# when 1..2
|
|
260
|
+
# player.drain
|
|
261
|
+
# puts "#{player.name} got drained 😩"
|
|
262
|
+
# when 3..4
|
|
263
|
+
# puts "#{player.name} got skipped"
|
|
264
|
+
# else
|
|
265
|
+
# player.boost
|
|
266
|
+
# puts "#{player.name} got boosted 😁"
|
|
267
|
+
# end
|
|
268
|
+
# end
|
|
269
|
+
|
|
270
|
+
# puts "\nAfter playing:"
|
|
271
|
+
# puts @players
|
|
272
|
+
# end
|
|
273
|
+
# end
|
|
274
|
+
|
|
275
|
+
# player_1 = Player.new("finn", 60)
|
|
276
|
+
# player_2 = Player.new("lucy", 90)
|
|
277
|
+
# player_3 = Player.new("jase")
|
|
278
|
+
# player_4 = Player.new("alex", 125)
|
|
279
|
+
|
|
280
|
+
# game = Game.new("Winner Takes All")
|
|
281
|
+
# game.add_player(player_1)
|
|
282
|
+
# game.add_player(player_2)
|
|
283
|
+
# game.add_player(player_3)
|
|
284
|
+
# game.add_player(player_4)
|
|
285
|
+
# game.play
|
|
286
|
+
|
|
287
|
+
require_relative "../lib/studio_game/game"
|
|
288
|
+
require_relative "../lib/studio_game/player"
|
|
289
|
+
require_relative "../lib/studio_game/clumsy_player"
|
|
290
|
+
require_relative "../lib/studio_game/berserk_player"
|
|
291
|
+
|
|
292
|
+
# player_1 = Player.new("finn", 60)
|
|
293
|
+
# player_2 = Player.new("lucy", 90)
|
|
294
|
+
# player_3 = Player.new("jase")
|
|
295
|
+
# player_4 = Player.new("alex", 125)
|
|
296
|
+
|
|
297
|
+
game = StudioGame::Game.new("Guardians")
|
|
298
|
+
# game.add_player(player_1)
|
|
299
|
+
# game.add_player(player_2)
|
|
300
|
+
# game.add_player(player_3)
|
|
301
|
+
# game.add_player(player_4)
|
|
302
|
+
players_file = File.join(__dir__, "players.csv")
|
|
303
|
+
game.load_players(ARGV.shift || players_file)
|
|
304
|
+
|
|
305
|
+
clumsy_player = StudioGame::ClumsyPlayer.new("klutz", 105, 7)
|
|
306
|
+
game.add_player(clumsy_player)
|
|
307
|
+
berserk_player = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
308
|
+
game.add_player(berserk_player)
|
|
309
|
+
|
|
310
|
+
loop do
|
|
311
|
+
print "\nHow many game rounds? ('quit' to exit) "
|
|
312
|
+
answer = gets.chomp.downcase
|
|
313
|
+
case answer
|
|
314
|
+
when /^\d+$/
|
|
315
|
+
game.play(answer.to_i)
|
|
316
|
+
when "quit", "exit"
|
|
317
|
+
game.print_stats
|
|
318
|
+
break
|
|
319
|
+
else
|
|
320
|
+
puts "You have to enter a number or 'quit' to exit"
|
|
321
|
+
end
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
game.save_high_scores
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative "player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class BerserkPlayer < Player
|
|
5
|
+
def initialize(name, health = 100)
|
|
6
|
+
super(name, health)
|
|
7
|
+
@boost_count = 0
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def berserk?
|
|
11
|
+
@boost_count > 5
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def boost
|
|
15
|
+
super
|
|
16
|
+
@boost_count += 1
|
|
17
|
+
puts "#{@name} is berserk!" if berserk?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def drain
|
|
21
|
+
berserk? ? boost : super
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if __FILE__ == $0
|
|
26
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
27
|
+
6.times { berserker.boost }
|
|
28
|
+
2.times { berserker.drain }
|
|
29
|
+
puts berserker.health
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative "player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
def initialize(name, health = 100, boost_factor = 1)
|
|
6
|
+
super(name, health)
|
|
7
|
+
@boost_factor = boost_factor
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def found_treasure(name, points)
|
|
11
|
+
super(name, points/2.0)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def boost
|
|
15
|
+
@boost_factor.times { super }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
if __FILE__ == $0
|
|
20
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
21
|
+
|
|
22
|
+
clumsy.found_treasure("flute", 50)
|
|
23
|
+
clumsy.found_treasure("flute", 50)
|
|
24
|
+
clumsy.found_treasure("flute", 50)
|
|
25
|
+
clumsy.found_treasure("star", 100)
|
|
26
|
+
|
|
27
|
+
clumsy.found_treasures.each do |name, points|
|
|
28
|
+
puts "#{name}: #{points} points"
|
|
29
|
+
end
|
|
30
|
+
puts "#{clumsy.points} total points"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
require_relative "treasure_trove"
|
|
2
|
+
require_relative "player"
|
|
3
|
+
require_relative "auditable"
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
class Game
|
|
7
|
+
include Auditable
|
|
8
|
+
|
|
9
|
+
attr_reader :title, :players
|
|
10
|
+
|
|
11
|
+
def initialize(title)
|
|
12
|
+
@title = title
|
|
13
|
+
@players = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_player(player)
|
|
17
|
+
@players << player
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def roll_die
|
|
21
|
+
number = rand(1..6)
|
|
22
|
+
# number = [1, 1, 2, 5, 6, 6].sample
|
|
23
|
+
audit(number)
|
|
24
|
+
number
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def play(rounds = 1)
|
|
28
|
+
puts "\nLet's play #{title}!"
|
|
29
|
+
puts "\nThe following treasures can be found:"
|
|
30
|
+
puts TreasureTrove.treasure_items
|
|
31
|
+
puts "\nBefore playing:"
|
|
32
|
+
puts @players
|
|
33
|
+
|
|
34
|
+
1.upto(rounds) do |round|
|
|
35
|
+
puts "\nRound #{round}:"
|
|
36
|
+
@players.each do |player|
|
|
37
|
+
number_rolled = roll_die
|
|
38
|
+
case number_rolled
|
|
39
|
+
when 1..2
|
|
40
|
+
player.drain
|
|
41
|
+
puts "#{player.name} got drained 😩"
|
|
42
|
+
when 3..4
|
|
43
|
+
puts "#{player.name} got skipped"
|
|
44
|
+
else
|
|
45
|
+
player.boost
|
|
46
|
+
puts "#{player.name} got boosted 😁"
|
|
47
|
+
end
|
|
48
|
+
treasure_found = TreasureTrove.random_treasure
|
|
49
|
+
player.found_treasure(treasure_found.name, treasure_found.points)
|
|
50
|
+
puts "#{player.name} found a #{treasure_found.name} worth #{treasure_found.points} points"
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
puts "\nAfter playing:"
|
|
55
|
+
puts @players
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def print_stats
|
|
59
|
+
puts
|
|
60
|
+
puts "#{@title} Game Stats:"
|
|
61
|
+
puts "-" * 30
|
|
62
|
+
puts sorted_players
|
|
63
|
+
@players.each do |player|
|
|
64
|
+
puts "\n#{player.name}'s treasures point totals"
|
|
65
|
+
player.found_treasures.each do |name, points|
|
|
66
|
+
puts "#{name}: #{points}"
|
|
67
|
+
end
|
|
68
|
+
puts "total: #{player.points}"
|
|
69
|
+
end
|
|
70
|
+
puts "\nHigh Scores:"
|
|
71
|
+
sorted_players.each do |player|
|
|
72
|
+
puts high_score_entry(player)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def sorted_players
|
|
77
|
+
@players.sort_by { |player| player.score }.reverse
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def load_players(from_file)
|
|
81
|
+
File.readlines(from_file, chomp: true).each do |line|
|
|
82
|
+
add_player(Player.from_csv(line))
|
|
83
|
+
end
|
|
84
|
+
rescue Errno::ENOENT
|
|
85
|
+
puts "#{from_file} not found."
|
|
86
|
+
exit 1
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def save_high_scores(to_file = "high_scores.txt")
|
|
90
|
+
File.open(to_file, "w") do |file|
|
|
91
|
+
file.puts "#{@title} High Scores:"
|
|
92
|
+
sorted_players.each do |player|
|
|
93
|
+
file.puts high_score_entry(player)
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def high_score_entry(player)
|
|
99
|
+
name = player.name.ljust(20, ".")
|
|
100
|
+
points = player.score.round.to_s.rjust(5)
|
|
101
|
+
"#{name}#{points}"
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require_relative "playable"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
|
|
7
|
+
attr_reader :found_treasures
|
|
8
|
+
attr_accessor :name, :health
|
|
9
|
+
|
|
10
|
+
def initialize(name, health=100)
|
|
11
|
+
@name = name.capitalize
|
|
12
|
+
@health = health
|
|
13
|
+
@found_treasures = Hash.new(0)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s = "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}"
|
|
17
|
+
|
|
18
|
+
def score
|
|
19
|
+
@health + points
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def found_treasure(name, points)
|
|
23
|
+
@found_treasures[name] += points
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def points
|
|
27
|
+
@found_treasures.values.sum
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def self.from_csv(line)
|
|
31
|
+
name, health = line.split(',')
|
|
32
|
+
Player.new(name, Integer(health))
|
|
33
|
+
rescue ArgumentError
|
|
34
|
+
puts "Ignored invalid health value: #{health}"
|
|
35
|
+
Player.new(name, 100)
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
if __FILE__ == $0
|
|
40
|
+
player = Player.new("jase")
|
|
41
|
+
puts player.name
|
|
42
|
+
puts player.health
|
|
43
|
+
player.boost
|
|
44
|
+
puts player.health
|
|
45
|
+
player.drain
|
|
46
|
+
puts player.health
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
module TreasureTrove
|
|
3
|
+
Treasure = Data.define(:name, :points)
|
|
4
|
+
TREASURES = [
|
|
5
|
+
Treasure.new("pie", 10),
|
|
6
|
+
Treasure.new("coin", 25),
|
|
7
|
+
Treasure.new("flute", 50),
|
|
8
|
+
Treasure.new("compass", 65),
|
|
9
|
+
Treasure.new("key", 80),
|
|
10
|
+
Treasure.new("crown", 90),
|
|
11
|
+
Treasure.new("star", 100)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def self.random_treasure
|
|
15
|
+
TREASURES.sample
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.treasure_items
|
|
19
|
+
TREASURES.map { |treasure| "A #{treasure.name} is worth #{treasure.points}"}
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: studio_game_dd2026
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Dany Díaz
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
email: dany_diaz_22@hotmail.com
|
|
13
|
+
executables:
|
|
14
|
+
- studio_game
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- bin/players.csv
|
|
19
|
+
- bin/studio_game
|
|
20
|
+
- lib/studio_game/auditable.rb
|
|
21
|
+
- lib/studio_game/berserk_player.rb
|
|
22
|
+
- lib/studio_game/clumsy_player.rb
|
|
23
|
+
- lib/studio_game/game.rb
|
|
24
|
+
- lib/studio_game/playable.rb
|
|
25
|
+
- lib/studio_game/player.rb
|
|
26
|
+
- lib/studio_game/treasure_trove.rb
|
|
27
|
+
homepage: ''
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata: {}
|
|
31
|
+
rdoc_options: []
|
|
32
|
+
require_paths:
|
|
33
|
+
- lib
|
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
|
+
requirements:
|
|
36
|
+
- - ">="
|
|
37
|
+
- !ruby/object:Gem::Version
|
|
38
|
+
version: 3.2.0
|
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: '0'
|
|
44
|
+
requirements: []
|
|
45
|
+
rubygems_version: 3.6.9
|
|
46
|
+
specification_version: 4
|
|
47
|
+
summary: studio_game
|
|
48
|
+
test_files: []
|