one_of_many_studio_game_gems 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
+ SHA1:
3
+ metadata.gz: 6004d17297b74a821a5b130e2c6fae00959f3371
4
+ data.tar.gz: f7dd10efcbf5b6593076d57e00bf937c76e1b84a
5
+ SHA512:
6
+ metadata.gz: b94e8f49d2fe3712e877e0c2b5cf0107d1f398e3d6ebfdb421f4bb62834473ad9079b7721ca9e4e1d77594d808cb8df219a9546bf085d82a362ca284336d1eb0
7
+ data.tar.gz: 4f328fde7aa359a2764c69943a2e247137f9d8e56bd17ed025026256b716303d942cbbd9041d21e2900c8fad850a0a783a203f332752f10a7c7389db5603640a
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) <2014> <Markus Olsen>
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
11
+ all 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
19
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1 @@
1
+ This gem contains practice code created along with the Pragmatic Studios tutorial.
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,52 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/studio_game/player'
4
+ require_relative '../lib/studio_game/game'
5
+ require_relative '../lib/studio_game/clumsy_player'
6
+ require_relative '../lib/studio_game/berserk_player'
7
+
8
+
9
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
10
+ player1 = StudioGame::Player.new("moe")
11
+ player2 = StudioGame::Player.new("larry", 60)
12
+ player3 = StudioGame::Player.new("curly", 125)
13
+
14
+ knuckleheads = StudioGame::Game.new("knuckleheads")
15
+ knuckleheads.load_players(ARGV.shift || default_player_file)
16
+ # knuckleheads.add_player(player1)
17
+ # knuckleheads.add_player(player2)
18
+ # knuckleheads.add_player(player3)
19
+ klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
20
+ knuckleheads.add_player(klutz)
21
+ berserker = StudioGame::BerserkPlayer.new("berserker", 50)
22
+ knuckleheads.add_player(berserker)
23
+
24
+ loop do
25
+ puts "\nHow many game rounds? ('quit' to exit)"
26
+ answer = gets.chomp.downcase
27
+ case answer
28
+ when /^\d+$/
29
+ knuckleheads.play(answer.to_i)
30
+ when "quit", "exit"
31
+ knuckleheads.print_stats
32
+ knuckleheads.save_high_scores
33
+ break
34
+ else
35
+ puts "Please enter a number or 'quit'"
36
+ end
37
+ end
38
+
39
+
40
+
41
+ # knuckleheads.play(10) do
42
+ # knuckleheads.total_points >= 2000
43
+ # end
44
+ # knuckleheads.print_stats
45
+
46
+
47
+
48
+
49
+
50
+
51
+
52
+
@@ -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,31 @@
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
+ 6.times { berserker.w00t }
28
+ 2.times { berserker.blam }
29
+ puts berserker.health
30
+ end
31
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+ attr_reader :boost_factor
6
+
7
+ def initialize(name, health=100, boost_factor=1)
8
+ super(name, health)
9
+ @boost_factor = boost_factor
10
+ end
11
+
12
+ def w00t
13
+ @boost_factor.times { super }
14
+ end
15
+
16
+ def found_treasure(treasure)
17
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
18
+ super(damaged_treasure)
19
+ end
20
+ end
21
+
22
+
23
+ if __FILE__ == $0
24
+ clumsy = ClumsyPlayer.new("klutz")
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
+ end
39
+ 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 = rand(1..6)
15
+ audit
16
+ @number
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,112 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game_turn'
4
+ require_relative 'treasure_trove'
5
+ require 'csv'
6
+
7
+ module StudioGame
8
+ class Game
9
+
10
+ attr_accessor :title
11
+
12
+ def initialize(title)
13
+ @title = title.capitalize
14
+ @players = []
15
+ end
16
+
17
+ def add_player(player)
18
+ @players << player
19
+ end
20
+
21
+ def load_players(from_file)
22
+ CSV.foreach(from_file) do |row|
23
+ player = Player.new(row[0], row[1].to_i)
24
+ add_player(player)
25
+ end
26
+ # File.readlines(from_file).each do |line|
27
+ # add_player(Player.from_csv(line))
28
+ # end
29
+ end
30
+
31
+ def save_high_scores(to_file = "high_scores.txt")
32
+ File.open(to_file, 'w') do |file|
33
+ file.puts "#{@title} High Scores:"
34
+ @players.sort.each do |player|
35
+ file.puts high_score_entry(player)
36
+ end
37
+ end
38
+ end
39
+
40
+ def high_score_entry(player)
41
+ formatted_name = player.name.ljust(20, '.')
42
+ "#{formatted_name} #{player.score}"
43
+ end
44
+
45
+ def play(rounds)
46
+ puts "\nThere are #{@players.size} players in #{@title}:"
47
+ @players.each { |player| puts player }
48
+
49
+ treasures = TreasureTrove::TREASURES
50
+
51
+ puts "\nThere are #{treasures.size} treasures to be found:"
52
+
53
+ treasures.each do |treasure|
54
+ puts "A #{treasure.name} is worth #{treasure.points} points"
55
+ end
56
+
57
+ 1.upto(rounds) do |round|
58
+ if block_given?
59
+ break if yield
60
+ end
61
+ puts "\nRound #{round}:"
62
+ @players.each do |player|
63
+ GameTurn.take_turn(player)
64
+ puts 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
+ puts "\n#{strong_players.size} strong players:"
77
+
78
+ strong_players.each do |player|
79
+ print_name_and_health(player)
80
+ end
81
+
82
+ puts "\n#{wimpy_players.size} wimpy players:"
83
+ wimpy_players.each do |player|
84
+ print_name_and_health(player)
85
+ end
86
+
87
+ puts "\n#{@title} High Scores:"
88
+ @players.sort.each do |player|
89
+ puts high_score_entry(player)
90
+ end
91
+
92
+ @players.sort.each do |player|
93
+ puts "\n#{player.name}'s point totals:"
94
+
95
+ player.each_found_treasure do |treasure|
96
+ puts "#{treasure.points} total #{treasure.name} points"
97
+ end
98
+
99
+ puts "#{player.points} grand total points"
100
+ end
101
+
102
+ puts "\n#{total_points} total points from treasures found"
103
+
104
+ end
105
+
106
+ def total_points
107
+ @players.reduce(0) do |sum, player|
108
+ sum + player.points
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'treasure_trove'
4
+ require_relative 'loaded_die'
5
+
6
+ module StudioGame
7
+ module GameTurn
8
+ def self.take_turn(player)
9
+ die = Die.new
10
+ case die.roll
11
+ when 1..2
12
+ player.blam
13
+ when 3..4
14
+ puts "#{player.name} was skipped"
15
+ else
16
+ player.w00t
17
+ end
18
+
19
+ treasure = TreasureTrove.random
20
+
21
+ player.found_treasure(treasure)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,11 @@
1
+ def n_times(number)
2
+ 1.upto(number) do |count|
3
+ yield count
4
+ end
5
+ end
6
+
7
+ n_times(8) do |n|
8
+ puts "#{n} situps"
9
+ puts "#{n} pushups"
10
+ puts "#{n} chinups"
11
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class LoadedDie
5
+ include Auditable
6
+ attr_reader :number
7
+
8
+ def roll
9
+ numbers = [1, 1, 2, 5, 6, 6]
10
+ @number = numbers.sample
11
+ audit
12
+ @number
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module StudioGame
2
+ module Playable
3
+ def blam
4
+ self.health -= 10
5
+ puts "#{self.name} got blammed!"
6
+ end
7
+
8
+ def w00t
9
+ self.health += 15
10
+ puts "#{self.name} got w00ted!"
11
+ end
12
+
13
+ def strong?
14
+ self.health > 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,68 @@
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 to_s
17
+ "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
18
+ end
19
+
20
+ def score
21
+ @health + points
22
+ end
23
+
24
+ def name=(new_name)
25
+ @name = new_name.capitalize
26
+ end
27
+
28
+ def <=>(other)
29
+ other.score <=> score
30
+ end
31
+
32
+ def found_treasure(treasure)
33
+ @found_treasures[treasure.name] += treasure.points
34
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
35
+ end
36
+
37
+ def points
38
+ @found_treasures.values.reduce(0, :+)
39
+ end
40
+
41
+ def each_found_treasure
42
+ @found_treasures.each do |name, points|
43
+ yield Treasure.new(name, points)
44
+ end
45
+ end
46
+
47
+ # def self.from_csv(string)
48
+ # name, health = string.split(',')
49
+ # Player.new(name, Integer(health))
50
+ # end
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
64
+
65
+
66
+
67
+
68
+
@@ -0,0 +1,22 @@
1
+ module StudioGame
2
+
3
+ Treasure = Struct.new(:name, :points)
4
+
5
+ module TreasureTrove
6
+
7
+ TREASURES = [
8
+
9
+ Treasure.new(:pie, 5),
10
+ Treasure.new(:bottle, 25),
11
+ Treasure.new(:hammer, 50),
12
+ Treasure.new(:skillet, 100),
13
+ Treasure.new(:broomstick, 200),
14
+ Treasure.new(:crowbar, 400)
15
+
16
+ ]
17
+
18
+ def self.random
19
+ TREASURES.sample
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,38 @@
1
+ require 'studio_game/berserk_player'
2
+
3
+ module StudioGame
4
+ describe BerserkPlayer do
5
+ before do
6
+ $stdout = StringIO.new
7
+ end
8
+ before do
9
+ @initial_health = 50
10
+ @player = BerserkPlayer.new("berserker", @initial_health)
11
+ end
12
+
13
+ it "does not go berserk when w00ted up to 5 times" do
14
+ 1.upto(5) { @player.w00t }
15
+
16
+ @player.berserk?.should be_false
17
+
18
+ # or if using Rspec 3.0:
19
+ # @player.berserk?.should be_falsey
20
+ end
21
+
22
+ it "goes berserk when w00ted more than 5 times" do
23
+ 1.upto(6) { @player.w00t }
24
+
25
+ @player.berserk?.should be_true
26
+
27
+ # or if using Rspec 3.0:
28
+ # @player.berserk?.should be_truthy
29
+ end
30
+
31
+ it "gets w00ted instead of blammed when it's gone berserk" do
32
+ 1.upto(6) { @player.w00t }
33
+ 1.upto(2) { @player.blam }
34
+
35
+ @player.health.should == @initial_health + (8 * 15)
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,50 @@
1
+ require 'studio_game/clumsy_player'
2
+
3
+ module StudioGame
4
+ describe ClumsyPlayer do
5
+ before do
6
+ @player = ClumsyPlayer.new("klutz")
7
+ end
8
+
9
+ it "only gets half the point value for each treasure" do
10
+ @player.points.should == 0
11
+
12
+ hammer = Treasure.new(:hammer, 50)
13
+ @player.found_treasure(hammer)
14
+ @player.found_treasure(hammer)
15
+ @player.found_treasure(hammer)
16
+
17
+ @player.points.should == 75
18
+
19
+ crowbar = Treasure.new(:crowbar, 400)
20
+ @player.found_treasure(crowbar)
21
+
22
+ @player.points.should == 275
23
+
24
+ yielded = []
25
+ @player.each_found_treasure do |treasure|
26
+ yielded << treasure
27
+ end
28
+
29
+ yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
30
+ end
31
+
32
+ context "with a boost factor" do
33
+ before do
34
+ @initial_health = 100
35
+ @boost_factor = 5
36
+ @player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
37
+ end
38
+
39
+ it "has a boost factor" do
40
+ @player.boost_factor.should == 5
41
+ end
42
+
43
+ it "gets boost factor number of w00ts when w00ted" do
44
+ @player.w00t
45
+
46
+ @player.health.should == @initial_health + (15 * @boost_factor)
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,72 @@
1
+ require 'studio_game/game'
2
+
3
+ module StudioGame
4
+ describe Game do
5
+
6
+ before do
7
+ $stdout = StringIO.new
8
+ end
9
+
10
+ before do
11
+ @game = Game.new("Knuckleheads")
12
+ @initial_health = 100
13
+ @player = Player.new("moe", @initial_health)
14
+ @game.add_player(@player)
15
+ end
16
+
17
+ it "has a title" do
18
+ @game.title.should == "Knuckleheads"
19
+ end
20
+
21
+ it "w00ts the player if a high number is rolled" do
22
+ Die.any_instance.stub(:roll).and_return(5)
23
+
24
+ @game.play(2)
25
+
26
+ @player.health.should == @initial_health + (15 * 2)
27
+ end
28
+
29
+ it "remains the same if a medium number is rolled" do
30
+ Die.any_instance.stub(:roll).and_return(3)
31
+
32
+ @game.play(2)
33
+
34
+ @player.health.should == @initial_health
35
+ end
36
+
37
+ it "blams the player if a low number is rolled" do
38
+ Die.any_instance.stub(:roll).and_return(1)
39
+
40
+ @game.play(2)
41
+
42
+ @player.health.should == @initial_health - (10 * 2)
43
+ end
44
+
45
+ it "assigns a treasure for points during a player's turn" do
46
+ game = Game.new("Knuckleheads")
47
+ player = Player.new("moe")
48
+
49
+ game.add_player(player)
50
+
51
+ game.play(1)
52
+
53
+ player.points.should_not be_zero
54
+ end
55
+
56
+ it "computes total points as the sum of all player points" do
57
+ game = Game.new("Knuckleheads")
58
+
59
+ player1 = Player.new("moe")
60
+ player2 = Player.new("larry")
61
+
62
+ game.add_player(player1)
63
+ game.add_player(player2)
64
+
65
+ player1.found_treasure(Treasure.new(:hammer, 50))
66
+ player1.found_treasure(Treasure.new(:hammer, 50))
67
+ player2.found_treasure(Treasure.new(:crowbar, 400))
68
+
69
+ game.total_points.should == 500
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,148 @@
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
+ end
9
+
10
+ before do
11
+ @initial_health = 150
12
+ @player = Player.new("larry", @initial_health)
13
+ end
14
+
15
+ # it "can be created from a CSV string" do
16
+ # player = Player.from_csv("larry,150")
17
+
18
+ # player.name.should == "Larry"
19
+ # player.health.should == 150
20
+ # end
21
+
22
+ it "has a capitalized name" do
23
+ @player.name.should == "Larry"
24
+ end
25
+
26
+ it "has an initial health" do
27
+ @player.health.should == 150
28
+ end
29
+
30
+ it "has a string representation" do
31
+ @player.found_treasure(Treasure.new(:hammer, 50))
32
+ @player.found_treasure(Treasure.new(:hammer, 50))
33
+
34
+ @player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
35
+ end
36
+
37
+ it "computes a score as the sum of its health and points" do
38
+ @player.found_treasure(Treasure.new(:hammer, 50))
39
+ @player.found_treasure(Treasure.new(:hammer, 50))
40
+
41
+ @player.score.should == 250
42
+ end
43
+
44
+ it "increases health by 15 when w00ted" do
45
+ @player.w00t
46
+
47
+ @player.health.should == (@initial_health + 15)
48
+ end
49
+
50
+ it "decreases health by 10 when blammed" do
51
+ @player.blam
52
+
53
+ @player.health.should == @initial_health - 10
54
+ end
55
+
56
+ it "computes points as the sum of all treasure points" do
57
+ @player.points.should == 0
58
+
59
+ @player.found_treasure(Treasure.new(:hammer, 50))
60
+
61
+ @player.points.should == 50
62
+
63
+ @player.found_treasure(Treasure.new(:crowbar, 400))
64
+
65
+ @player.points.should == 450
66
+
67
+ @player.found_treasure(Treasure.new(:hammer, 50))
68
+
69
+ @player.points.should == 500
70
+ end
71
+
72
+ context "created with a default health" do
73
+ before do
74
+ @player = Player.new("larry")
75
+ end
76
+
77
+ it "has a health of 100" do
78
+ @player.health.should == 100
79
+ end
80
+ end
81
+
82
+ context "with a health greater than 100" do
83
+ before do
84
+ @player = Player.new("larry", 150)
85
+ end
86
+
87
+ it "is strong" do
88
+ @player.should be_strong
89
+ end
90
+ end
91
+
92
+ context "with a health of 100 or less" do
93
+ before do
94
+ @player = Player.new("larry", 100)
95
+ end
96
+
97
+ it "is wimpy" do
98
+ @player.should_not be_strong
99
+ end
100
+ end
101
+
102
+ context "in a collection of players" do
103
+ before do
104
+ @player1 = Player.new("moe", 100)
105
+ @player2 = Player.new("larry", 200)
106
+ @player3 = Player.new("curly", 300)
107
+
108
+ @players = [@player1, @player2, @player3]
109
+ end
110
+
111
+ it "is sorted by decreasing score" do
112
+ @players.sort.should == [@player3, @player2, @player1]
113
+ end
114
+
115
+ it "yields each found treasure and its total points" do
116
+ @player.found_treasure(Treasure.new(:skillet, 100))
117
+ @player.found_treasure(Treasure.new(:skillet, 100))
118
+ @player.found_treasure(Treasure.new(:hammer, 50))
119
+ @player.found_treasure(Treasure.new(:bottle, 5))
120
+ @player.found_treasure(Treasure.new(:bottle, 5))
121
+ @player.found_treasure(Treasure.new(:bottle, 5))
122
+ @player.found_treasure(Treasure.new(:bottle, 5))
123
+ @player.found_treasure(Treasure.new(:bottle, 5))
124
+
125
+ yielded = []
126
+ @player.each_found_treasure do |treasure|
127
+ yielded << treasure
128
+ end
129
+
130
+ yielded.should == [
131
+ Treasure.new(:skillet, 200),
132
+ Treasure.new(:hammer, 50),
133
+ Treasure.new(:bottle, 25)
134
+ ]
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ # With the new expectation syntax:
141
+
142
+ # @player.health.should == 150
143
+
144
+ # is same as
145
+
146
+ # expect(@player.health).to eq(150)
147
+
148
+
@@ -0,0 +1,56 @@
1
+ require 'studio_game/treasure_trove'
2
+
3
+ module StudioGame
4
+ describe Treasure do
5
+
6
+ before do
7
+ @treasure = Treasure.new(:hammer, 50)
8
+ end
9
+
10
+ it "has a name attribute" do
11
+ @treasure.name.should == :hammer
12
+ end
13
+
14
+ it "has a points attribute" do
15
+ @treasure.points.should == 50
16
+ end
17
+
18
+ end
19
+
20
+ describe TreasureTrove do
21
+
22
+ it "has six treasures" do
23
+ TreasureTrove::TREASURES.size.should == 6
24
+ end
25
+
26
+ it "has a pie worth 5 points" do
27
+ TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
28
+ end
29
+
30
+ it "has a bottle worth 25 points" do
31
+ TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
32
+ end
33
+
34
+ it "has a hammer worth 50 points" do
35
+ TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
36
+ end
37
+
38
+ it "has a skillet worth 100 points" do
39
+ TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
40
+ end
41
+
42
+ it "has a broomstick worth 200 points" do
43
+ TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
44
+ end
45
+
46
+ it "has a crowbar worth 400 points" do
47
+ TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
48
+ end
49
+
50
+ it "returns a random treasure" do
51
+ treasure = TreasureTrove.random
52
+
53
+ TreasureTrove::TREASURES.should include(treasure)
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: one_of_many_studio_game_gems
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Markus Olsen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 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: This gem contains practice code created along with the Pragmatic Studios
28
+ tutorial.
29
+ email: molsen13@gmail.com
30
+ executables:
31
+ - studio_game
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - LICENSE
36
+ - README
37
+ - bin/players.csv
38
+ - bin/studio_game
39
+ - lib/studio_game/auditable.rb
40
+ - lib/studio_game/berserk_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/iterators.rb
46
+ - lib/studio_game/loaded_die.rb
47
+ - lib/studio_game/playable.rb
48
+ - lib/studio_game/player.rb
49
+ - lib/studio_game/treasure_trove.rb
50
+ - spec/studio_game/berserk_player_spec.rb
51
+ - spec/studio_game/clumsy_player_spec.rb
52
+ - spec/studio_game/game_spec.rb
53
+ - spec/studio_game/player_spec.rb
54
+ - spec/studio_game/treasure_trove_spec.rb
55
+ homepage: http://pragmaticstudio.com
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '1.9'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.2.2
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: practice code for pragmatic studio
79
+ test_files:
80
+ - spec/studio_game/berserk_player_spec.rb
81
+ - spec/studio_game/clumsy_player_spec.rb
82
+ - spec/studio_game/game_spec.rb
83
+ - spec/studio_game/player_spec.rb
84
+ - spec/studio_game/treasure_trove_spec.rb