je_studio_game 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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3cf1c042ee56eedcfdec3fa83383bff7c8aeb245eb2287509d692ee1436bfd29
4
+ data.tar.gz: c952b5088d974b8fe18e77754c0a5ddf506cbccfeed8bbf124f6e08429b8ded0
5
+ SHA512:
6
+ metadata.gz: 51f608afb8f5430e29cd0a80e559579b34691e577db724a162ac19ca4a22ef766016a789d79bf0cacffb70206f16b601a705279dd394ae4150f94160972b2838
7
+ data.tar.gz: c4d424bd10e761f17bcbd07a7a2a08a6c1980948b2506cd9dcfaf12e9361574bcb4bfdf812e7178220b7569c2a1c0cb1107648516f52b93ecf75d4b45fd4902e
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2021 Jonathan Eccles
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,3 @@
1
+ The [Pragmatic Studios](https://pragmaticstudio.com) game created in their Learn Ruby course.
2
+
3
+ Players can be **blammed**, **w00ted** and find treasure each turn. There are even special types of player that behave differently.
data/bin/chipmunks.csv ADDED
@@ -0,0 +1,3 @@
1
+ alvin,70
2
+ simon,50
3
+ theodore,45
data/bin/players.csv ADDED
@@ -0,0 +1,3 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
data/bin/studio_game ADDED
@@ -0,0 +1,54 @@
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/berserk_player'
6
+
7
+ # player1 = Player.new("moe")
8
+ # player2 = Player.new("larry", 60)
9
+ # player3 = Player.new("curly", 125)
10
+ # player4 = Player.new("alvin", 70)
11
+ # player5 = Player.new("simon", 50)
12
+ # player6 = Player.new("theodore", 45)
13
+
14
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
15
+ # knuckleheads.add_player(player1)
16
+ # knuckleheads.add_player(player2)
17
+ # knuckleheads.add_player(player3)
18
+ # knuckleheads.add_player(player5)
19
+ klutz = StudioGame::ClumsyPlayer.new('klutz', 105, 10)
20
+ berserker = StudioGame::BerserkPlayer.new('berserker', 50)
21
+ knuckleheads.add_player(klutz)
22
+ knuckleheads.add_player(berserker)
23
+
24
+
25
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
26
+ knuckleheads.load_players(ARGV.shift || default_player_file)
27
+ # knuckleheads.load_players(ARGV.shift || 'players.csv')
28
+
29
+ loop do
30
+ puts("\nHow many rounds? ('quit' to end)")
31
+ answer = gets.chomp.downcase
32
+ case answer
33
+ when /^\d+$/
34
+ knuckleheads.play(answer.to_i)
35
+ when 'quit', 'exit', 'q', 'x'
36
+ knuckleheads.print_stats
37
+ break
38
+ else
39
+ puts "Enter number of rounds or 'quit' only"
40
+ end
41
+ end
42
+
43
+ knuckleheads.save_high_scores("#{knuckleheads.title.downcase}_high_scores.txt")
44
+
45
+ # knuckleheads.play(10) do
46
+ # knuckleheads.total_points >= 3000
47
+ # end
48
+ #
49
+ # chipmunks = Game.new("Chipmunks")
50
+ # chipmunks.add_player(player4)
51
+ # chipmunks.add_player(player5)
52
+ # chipmunks.add_player(player6)
53
+ # chipmunks.add_player(player1)
54
+ # chipmunks.play(5)
@@ -0,0 +1,7 @@
1
+ module StudioGame
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{self.number} (#{self.class})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class BerserkPlayer < Player
5
+ def initialize(name, health = 100)
6
+ super(name, health)
7
+ @w00t_count = 0
8
+ end
9
+
10
+ def berserk?
11
+ @w00t_count > 5
12
+ end
13
+
14
+ def w00t
15
+ super
16
+ @w00t_count += 1
17
+ puts "#{@name} is berserk!" if berserk?
18
+ end
19
+
20
+ def blam
21
+ berserk? ? w00t : super
22
+ end
23
+ end
24
+
25
+ if __FILE__ == $0
26
+ berserker = BerserkPlayer.new("berserker", 50)
27
+ berserker.blam
28
+ 6.times { berserker.w00t }
29
+ 2.times { berserker.blam }
30
+ puts berserker.health
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+
6
+ attr_reader :boost_factor
7
+
8
+ def initialize(name, health = 100, boost_factor = 1)
9
+ super(name, health)
10
+ @boost_factor = boost_factor
11
+ end
12
+
13
+ def w00t
14
+ @boost_factor.times { super }
15
+ end
16
+
17
+ def found_treasure(treasure)
18
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
19
+ super(damaged_treasure)
20
+ end
21
+ end
22
+
23
+ if __FILE__ == $0
24
+ clumsy = ClumsyPlayer.new("klutz", 100, 3)
25
+
26
+ hammer = Treasure.new(:hammer, 50)
27
+ clumsy.found_treasure(hammer)
28
+ clumsy.found_treasure(hammer)
29
+ clumsy.found_treasure(hammer)
30
+
31
+ crowbar = Treasure.new(:crowbar, 400)
32
+ clumsy.found_treasure(crowbar)
33
+
34
+ clumsy.each_found_treasure do |treasure|
35
+ puts "#{treasure.points} total #{treasure.name} points"
36
+ end
37
+ puts "#{clumsy.points} grand total points"
38
+
39
+ puts "#{clumsy.health} health"
40
+ clumsy.w00t
41
+ puts "#{clumsy.health} w00t boosted health!"
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class Die
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def initialize
10
+ roll
11
+ end
12
+
13
+ def roll
14
+ @number = Random.rand(1..6)
15
+ audit
16
+ @number
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,90 @@
1
+ require 'csv'
2
+ require_relative 'player'
3
+ require_relative 'game_turn'
4
+ require_relative 'treasure_trove'
5
+
6
+ module StudioGame
7
+ class Game
8
+ attr_reader :title
9
+
10
+ def initialize(title)
11
+ @title = title
12
+ @players = []
13
+ end
14
+
15
+ def high_score_entry(player)
16
+ "#{player.name.ljust(20, '.')} #{player.score}"
17
+ end
18
+
19
+ def load_players(filename)
20
+ CSV.foreach(filename) do |line|
21
+ add_player(Player.from_csv(line))
22
+ end
23
+ # File.readlines(filename).each do |line|
24
+ # add_player(Player.from_csv(line))
25
+ # end
26
+ end
27
+
28
+ def save_high_scores(to_file = "high_scores.txt")
29
+ File.open(to_file, "w") do |file|
30
+ file.puts "#{@title} High Scores:"
31
+ @players.sort.each { |sp| file.puts high_score_entry(sp)}
32
+ end
33
+ end
34
+
35
+ def add_player(player)
36
+ @players << player
37
+ end
38
+
39
+ def total_points
40
+ @players.reduce(0) { |sum, p| sum + p.points }
41
+ end
42
+
43
+ def play(rounds)
44
+ puts "\nThere are #{@players.size} players in #{@title}:"
45
+ puts @players
46
+
47
+ treasures = TreasureTrove::TREASURES
48
+ puts "\nThere are #{treasures.size} treasures to be found:"
49
+ treasures.each { |treasure| puts "A #{treasure.name} is worth #{treasure.points} points" }
50
+
51
+ 1.upto(rounds) do |round|
52
+ if block_given?
53
+ break if yield
54
+ end
55
+
56
+ puts "\nRound: #{round}:"
57
+ @players.each do |player|
58
+ GameTurn.take_turn(player)
59
+ puts player
60
+ end
61
+ end
62
+ print_stats
63
+ end
64
+
65
+ def print_stats
66
+ strong, wimpy = @players.partition { |p| p.strong? }
67
+
68
+ puts "\n#{@title} Statistics:"
69
+
70
+ puts "\n#{strong.size} strong player#{strong.size == 1 ? '' : 's'}:"
71
+ strong.each { |s| s.print_name_and_health }
72
+
73
+ puts "\n#{wimpy.size} wimpy player#{wimpy.size == 1 ? '' : 's'}:"
74
+ wimpy.each { |w| w.print_name_and_health }
75
+
76
+ puts "\n#{@title} High Scores:"
77
+ @players.sort.each { |sp| puts high_score_entry(sp)}
78
+
79
+ @players.sort.each do |player|
80
+ puts "\n#{player.name}\`s point totals:"
81
+ player.each_found_treasure do |treasure|
82
+ puts "#{treasure.points} total #{treasure.name} points"
83
+ end
84
+ puts "#{player.points} grand total points"
85
+ end
86
+
87
+ puts "\n#{total_points} total points from treasures found"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'die'
2
+
3
+ module StudioGame
4
+ module GameTurn
5
+ def self.take_turn(player)
6
+ die = Die.new
7
+ number_rolled = die.roll
8
+ case number_rolled
9
+ when 1..2
10
+ player.blam
11
+ when 5..6
12
+ player.w00t
13
+ else
14
+ puts "#{player.name} was skipped."
15
+ end
16
+
17
+ player.found_treasure(TreasureTrove.random)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class LoadedDie
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ numbers = [1, 1, 2, 5, 6, 6]
11
+ @number = numbers.sample
12
+ audit
13
+ @number
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module StudioGame
2
+ module Playable
3
+ def blam
4
+ self.health -= 10
5
+ puts "#{name} got blammed!"
6
+ end
7
+
8
+ def w00t
9
+ self.health += 15
10
+ puts "#{name} got w00ted!"
11
+ end
12
+
13
+ def strong?
14
+ health > 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,64 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Player
6
+ include Playable
7
+
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 name=(new_name)
17
+ @name = new_name.capitalize
18
+ end
19
+
20
+ def self.from_csv(csv_line)
21
+ # name, health = csv_line.split(',')
22
+ Player.new(csv_line[0], Integer(csv_line[1]))
23
+ end
24
+
25
+ def to_s
26
+ "I'm #{@name} with health = #{@health}, points = #{points} and a score of #{score}."
27
+ end
28
+
29
+ def <=>(player)
30
+ player.score <=> self.score
31
+ end
32
+
33
+ def print_name_and_health
34
+ puts "#{@name} (#{@health})"
35
+ end
36
+
37
+ def score
38
+ @health + points
39
+ end
40
+
41
+ def found_treasure(treasure)
42
+ @found_treasures[treasure.name] += treasure.points
43
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
44
+ puts "#{@name}\'s treasures: #{@found_treasures}"
45
+ end
46
+
47
+ def each_found_treasure
48
+ @found_treasures.each do |name, points|
49
+ yield Treasure.new(name, points)
50
+ end
51
+ end
52
+
53
+ def points
54
+ @found_treasures.values.reduce(0, :+)
55
+ end
56
+ end
57
+
58
+
59
+ if __FILE__ == $0
60
+ player1 = Player.new("moe")
61
+ puts player1
62
+ puts player1.health
63
+ end
64
+ end
@@ -0,0 +1,18 @@
1
+ module StudioGame
2
+ Treasure = Struct.new(:name, :points)
3
+
4
+ module TreasureTrove
5
+ TREASURES = [
6
+ Treasure.new(:pie, 5),
7
+ Treasure.new(:bottle, 25),
8
+ Treasure.new(:hammer, 50),
9
+ Treasure.new(:skillet, 100),
10
+ Treasure.new(:broomstick, 200),
11
+ Treasure.new(:crowbar, 400),
12
+ ]
13
+
14
+ def self.random
15
+ TREASURES.sample
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,30 @@
1
+ require 'studio_game/berserk_player'
2
+
3
+ module StudioGame
4
+ describe BerserkPlayer do
5
+ before do
6
+ $stdout = StringIO.new
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
+ expect(@player.berserk?).to be_falsey
15
+ end
16
+
17
+ it "goes berserk when w00ted more than 5 times" do
18
+ 1.upto(6) { @player.w00t }
19
+
20
+ expect(@player.berserk?).to be_truthy
21
+ end
22
+
23
+ it "gets w00ted instead of blammed when it's gone berserk" do
24
+ 1.upto(6) { @player.w00t }
25
+ 1.upto(2) { @player.blam }
26
+
27
+ expect(@player.health).to eq(@initial_health + (8 * 15))
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,52 @@
1
+ require 'studio_game/clumsy_player'
2
+
3
+ module StudioGame
4
+ describe ClumsyPlayer do
5
+ before do
6
+ $stdout = StringIO.new
7
+ @player = ClumsyPlayer.new("klutz")
8
+ end
9
+
10
+ it "only gets half the point value for each treasure" do
11
+ aggregate_failures "clumsy with treasure" do
12
+ expect(@player.points).to eq(0)
13
+
14
+ hammer = Treasure.new(:hammer, 50)
15
+ @player.found_treasure(hammer)
16
+ @player.found_treasure(hammer)
17
+ @player.found_treasure(hammer)
18
+
19
+ expect(@player.points).to eq(75)
20
+
21
+ crowbar = Treasure.new(:crowbar, 400)
22
+ @player.found_treasure(crowbar)
23
+
24
+ expect(@player.points).to eq(275)
25
+
26
+ yielded = []
27
+ @player.each_found_treasure do |treasure|
28
+ yielded << treasure
29
+ end
30
+
31
+ expect(yielded).to eq([Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)])
32
+ end
33
+ end
34
+
35
+ context "with a boost factor" do
36
+ before do
37
+ @initial_health = 100
38
+ @boost_factor = 5
39
+ @player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
40
+ end
41
+
42
+ it "has a boost factor" do
43
+ expect(@player.boost_factor).to eq(@boost_factor)
44
+ end
45
+
46
+ it "gets boost factor number of w00ts when w00ted" do
47
+ @player.w00t
48
+ expect(@player.health).to eq(@initial_health + @boost_factor * 15)
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,54 @@
1
+ require 'studio_game/game'
2
+
3
+ module StudioGame
4
+ describe Game do
5
+ before do
6
+ $stdout = StringIO.new
7
+ @game = Game.new("Knuckleheads")
8
+
9
+ @initial_health = 100
10
+ @player = Player.new("moe", @initial_health)
11
+
12
+ @game.add_player(@player)
13
+ end
14
+
15
+ it "w00ts the player if a high number is rolled" do
16
+ allow_any_instance_of(Die).to receive(:roll).and_return(5)
17
+
18
+ expect{ @game.play(2) }.to change(@player, :health).by(15 * 2)
19
+ end
20
+
21
+ it "skips the player if a medium number is rolled" do
22
+ allow_any_instance_of(Die).to receive(:roll).and_return(3)
23
+
24
+ expect{ @game.play(2) }.to change(@player, :health).by(0)
25
+ end
26
+
27
+ it "blams the player if a low number is rolled" do
28
+ allow_any_instance_of(Die).to receive(:roll).and_return(1)
29
+
30
+ expect{ @game.play(2) }.to change(@player, :health).by(-10 * 2)
31
+ end
32
+
33
+ it "assigns a treasure for points during a player's turn" do
34
+ @game.play(1)
35
+ expect(@player.points).to_not be_zero
36
+ end
37
+
38
+ it "computes total points as the sum of all player points" do
39
+ game = Game.new("Knuckleheads")
40
+
41
+ player1 = Player.new("moe")
42
+ player2 = Player.new("larry")
43
+
44
+ game.add_player(player1)
45
+ game.add_player(player2)
46
+
47
+ player1.found_treasure(Treasure.new(:hammer, 50))
48
+ player1.found_treasure(Treasure.new(:hammer, 50))
49
+ player2.found_treasure(Treasure.new(:crowbar, 400))
50
+
51
+ expect(game.total_points).to eq(500)
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,132 @@
1
+ require 'studio_game/player'
2
+ require 'studio_game/treasure_trove'
3
+
4
+ module StudioGame
5
+ describe Player do
6
+ before do
7
+ $stdout = StringIO.new
8
+ @initial_health = 150
9
+ @name = "larry"
10
+ @player = Player.new(@name, @initial_health)
11
+ end
12
+
13
+ it "has a capitalized name" do
14
+ expect(@player.name).to eq(@name.capitalize)
15
+ end
16
+
17
+ it "has an initial health" do
18
+ expect(@player.health).to eq(@initial_health)
19
+ end
20
+
21
+ it "has a string representation" do
22
+ @player.found_treasure(Treasure.new(:hammer, 50))
23
+ @player.found_treasure(Treasure.new(:hammer, 50))
24
+ expect(@player.to_s).to eq("I'm Larry with health = 150, points = 100 and a score of 250.")
25
+ end
26
+
27
+ it "computes a score as the sum of its health and points" do
28
+ @player.found_treasure(Treasure.new(:hammer, 50))
29
+ @player.found_treasure(Treasure.new(:hammer, 50))
30
+ expect(@player.score).to eq(@initial_health + 100)
31
+ end
32
+
33
+ it "increases health by 15 when w00ted" do
34
+ expect{ @player.w00t }.to change(@player, :health).by(15)
35
+ end
36
+
37
+ it "decreases health by 10 when blammed"do
38
+ expect{ @player.blam }.to change(@player, :health).by(-10)
39
+ end
40
+
41
+ it "computes points as the sum of all treasure points" do
42
+ aggregate_failures "treasure hunter" do
43
+ expect(@player.points).to eq(0)
44
+
45
+ @player.found_treasure(Treasure.new(:hammer, 50))
46
+ expect(@player.points).to eq(50)
47
+
48
+ @player.found_treasure(Treasure.new(:crowbar, 400))
49
+ expect(@player.points).to eq(450)
50
+
51
+ @player.found_treasure(Treasure.new(:hammer, 50))
52
+ expect(@player.points).to eq(500)
53
+ end
54
+ end
55
+
56
+ it "yields each found treasure and its total points" do
57
+ @player.found_treasure(Treasure.new(:skillet, 100))
58
+ @player.found_treasure(Treasure.new(:skillet, 100))
59
+ @player.found_treasure(Treasure.new(:hammer, 50))
60
+ @player.found_treasure(Treasure.new(:bottle, 5))
61
+ @player.found_treasure(Treasure.new(:bottle, 5))
62
+ @player.found_treasure(Treasure.new(:bottle, 5))
63
+ @player.found_treasure(Treasure.new(:bottle, 5))
64
+ @player.found_treasure(Treasure.new(:bottle, 5))
65
+
66
+ yielded = []
67
+ @player.each_found_treasure do |treasure|
68
+ yielded << treasure
69
+ end
70
+
71
+ expect(yielded).to eq([
72
+ Treasure.new(:skillet, 200),
73
+ Treasure.new(:hammer, 50),
74
+ Treasure.new(:bottle, 25)
75
+ ])
76
+ end
77
+
78
+ it "can be created from a CSV string" do
79
+ # player = Player.from_csv("jon, 200")
80
+ player = Player.from_csv(["jon", "200"])
81
+
82
+ expect(player.name).to eq("Jon")
83
+ expect(player.health).to eq(200)
84
+ end
85
+
86
+ context "created with a default health" do
87
+ before do
88
+ @player = Player.new(@name)
89
+ end
90
+
91
+ it "has a default health of 100" do
92
+ expect(@player.health).to eq(100)
93
+ end
94
+ end
95
+
96
+ context "with a health greater than 100" do
97
+ before do
98
+ @initial_health = 150
99
+ @player = Player.new(@name, @initial_health)
100
+ end
101
+
102
+ it "is strong" do
103
+ expect(@player).to be_strong
104
+ end
105
+ end
106
+
107
+ context "with a health no more than 100" do
108
+ before do
109
+ @initial_health = 100
110
+ @player = Player.new(@name, @initial_health)
111
+ end
112
+
113
+ it "is strong" do
114
+ expect(@player).to_not be_strong
115
+ end
116
+ end
117
+
118
+ context "in a collection of players" do
119
+ before do
120
+ @player1 = Player.new("moe", 100)
121
+ @player2 = Player.new("larry", 200)
122
+ @player3 = Player.new("curly", 300)
123
+
124
+ @players = [@player1, @player2, @player3]
125
+ end
126
+
127
+ it "is sorted by decreasing score" do
128
+ expect(@players.sort).to eq([@player3, @player2, @player1])
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,53 @@
1
+ require 'studio_game/treasure_trove'
2
+
3
+ module StudioGame
4
+ describe Treasure do
5
+ before do
6
+ @treasure = Treasure.new(:hammer, 50)
7
+ end
8
+
9
+ it "has a name attribute" do
10
+ expect(@treasure.name).to eq(:hammer)
11
+ end
12
+
13
+ it "has a points attribute" do
14
+ expect(@treasure.points).to eq(50)
15
+ end
16
+ end
17
+
18
+ describe TreasureTrove do
19
+ it "has six treasures" do
20
+ expect(TreasureTrove::TREASURES.size).to eq(6)
21
+ end
22
+
23
+ it "has a pie worth 5 points" do
24
+ expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
25
+ end
26
+
27
+ it "has a bottle worth 25 points" do
28
+ expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
29
+ end
30
+
31
+ it "has a hammer worth 50 points" do
32
+ expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
33
+ end
34
+
35
+ it "has a skillet worth 100 points" do
36
+ expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
37
+ end
38
+
39
+ it "has a broomstick worth 200 points" do
40
+ expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
41
+ end
42
+
43
+ it "has a crowbar worth 400 points" do
44
+ expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400))
45
+ end
46
+
47
+ it "returns a random treasure" do
48
+ treasure = TreasureTrove.random
49
+
50
+ expect(TreasureTrove::TREASURES).to include(treasure)
51
+ end
52
+ end
53
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: je_studio_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Eccles
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-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: '3.10'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 3.10.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '3.10'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 3.10.0
33
+ description: "The [Pragmatic Studios](https://pragmaticstudio.com) game created in
34
+ their Learn Ruby course. \n\nPlayers can be **blammed**, **w00ted** and find treasure
35
+ each turn. There are even special types of player that behave differently."
36
+ email: getjon@me.com
37
+ executables:
38
+ - studio_game
39
+ extensions: []
40
+ extra_rdoc_files: []
41
+ files:
42
+ - LICENSE.txt
43
+ - README.md
44
+ - bin/chipmunks.csv
45
+ - bin/players.csv
46
+ - bin/studio_game
47
+ - lib/studio_game/auditable.rb
48
+ - lib/studio_game/berserk_player.rb
49
+ - lib/studio_game/clumsy_player.rb
50
+ - lib/studio_game/die.rb
51
+ - lib/studio_game/game.rb
52
+ - lib/studio_game/game_turn.rb
53
+ - lib/studio_game/loaded_die.rb
54
+ - lib/studio_game/playable.rb
55
+ - lib/studio_game/player.rb
56
+ - lib/studio_game/treasure_trove.rb
57
+ - spec/studio_game/berserk_player_spec.rb
58
+ - spec/studio_game/clumsy_player_spec.rb
59
+ - spec/studio_game/game_spec.rb
60
+ - spec/studio_game/player_spec.rb
61
+ - spec/studio_game/treasure_trove_spec.rb
62
+ homepage: https://pragmaticstudio.com/courses/ruby
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '1.9'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubygems_version: 3.1.4
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Pragmatic Studio Ruby course game
85
+ test_files:
86
+ - spec/studio_game/clumsy_player_spec.rb
87
+ - spec/studio_game/treasure_trove_spec.rb
88
+ - spec/studio_game/berserk_player_spec.rb
89
+ - spec/studio_game/player_spec.rb
90
+ - spec/studio_game/game_spec.rb