thesweaters_game 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0afe9dfb9d787f6f6f2b8f3409a9072919eb3d59
4
+ data.tar.gz: 4b0ead2bba5255c1b9e6341b090f6135ae04c76f
5
+ SHA512:
6
+ metadata.gz: 0480e69930b99e8d4863abb94004874fc9ad2c2655987d6c394107effe8ad5368fe12f415cbaf34579001d585539d1611c3bd3a90fb786d74dd9c85991bb66fc
7
+ data.tar.gz: 6c2f8d285aa07cfbe280ef195e616fc1c9796162cc9c8c4e9779ba5e6f252b20612b4e1ab9a30ad2ad74d6cccebf12b92a2285bdb940958ae9064523c42df623
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012 The Pragmatic Studio
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
+ - You may not use this Software in other training contexts.
11
+
12
+ - The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,6 @@
1
+ This is an example application used in The Pragmatic Studio's
2
+ Ruby Programming course, as described at
3
+
4
+ http://pragmaticstudio.com
5
+
6
+ This code is Copyright 2012 The Pragmatic Studio. See the LICENSE file.
@@ -0,0 +1,6 @@
1
+ Knuckleheads's High Scores:
2
+ Berserker........... 279495
3
+ Theo................ 270860
4
+ Simon............... 259755
5
+ Alvin............... 251390
6
+ Klutz............... 153147.5
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,40 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
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
+ knuckleheads = BretsGame::Game.new("Knuckleheads")
9
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
10
+ knuckleheads.load_players(ARGV.shift || default_player_file)
11
+ klutz = BretsGame::ClumsyPlayer.new("klutz",105,3)
12
+ knuckleheads.add_player(klutz)
13
+ berserker = BretsGame::BerserkPlayer.new("berserker", 50)
14
+ knuckleheads.add_player(berserker)
15
+
16
+ loop do
17
+ puts "\nHow many game rounds? (Enter 'quit' to exit)"
18
+ answer = gets.chomp.downcase
19
+ case answer
20
+ when /^\d+$/
21
+ knuckleheads.play(answer.to_i)
22
+ when 'quit','exit'
23
+ knuckleheads.print_stats
24
+ break
25
+ else
26
+ puts "Please enter a number or 'quit'"
27
+ end
28
+ end
29
+
30
+ knuckleheads.save_high_scores
31
+
32
+
33
+ # current_time = Time.new
34
+ # formatted_time = current_time.strftime("%A %m/%d/%Y at %I:%M%p")
35
+ # puts "The game started on #{formatted_time}"
36
+
37
+
38
+
39
+
40
+
@@ -0,0 +1,7 @@
1
+ module BretsGame
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{self.number} (#{self.class})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ require_relative 'player'
2
+
3
+ module BretsGame
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
+ if berserk?
22
+ w00t
23
+ else
24
+ super
25
+ end
26
+
27
+ # or use the ternary operator:
28
+ # berserk? ? w00t : super
29
+ end
30
+ end
31
+ end
32
+
33
+ if __FILE__ == $0
34
+ berserker = BerserkPlayer.new("berserker", 50)
35
+ 6.times { berserker.w00t }
36
+ 2.times { berserker.blam }
37
+ puts berserker.health
38
+ end
39
+
@@ -0,0 +1,44 @@
1
+ require_relative 'player'
2
+
3
+ module BretsGame
4
+
5
+ class ClumsyPlayer < Player
6
+ attr_reader :boost_factor
7
+
8
+
9
+ def initialize(name, health=100, boost_factor=1)
10
+ super(name, health)
11
+ @boost_factor = boost_factor
12
+ end
13
+
14
+ def w00t
15
+ @boost_factor.times { super }
16
+ end
17
+
18
+
19
+
20
+ def found_treasure(treasure)
21
+ damaged_treasure = Treasure.new(treasure.name, treasure.points/ 2.0)
22
+ super(damaged_treasure)
23
+ end
24
+ end
25
+ end
26
+
27
+
28
+ if __FILE__ == $0
29
+ clumsy = ClumsyPlayer.new("klutz")
30
+
31
+ hammer = Treasure.new(:hammer, 50)
32
+ clumsy.found_treasure(hammer)
33
+ clumsy.found_treasure(hammer)
34
+ clumsy.found_treasure(hammer)
35
+
36
+ crowbar = Treasure.new(:crowbar, 400)
37
+ clumsy.found_treasure(crowbar)
38
+
39
+ clumsy.each_found_treasure do |treasure|
40
+ puts "#{treasure.points} total #{treasure.name} points"
41
+ end
42
+ puts "#{clumsy.points} grand total points"
43
+ end
44
+
@@ -0,0 +1,18 @@
1
+ require_relative 'auditable'
2
+
3
+ module BretsGame
4
+ class Die
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ @number = rand(1..6)
11
+ audit
12
+ @number
13
+ end
14
+ end
15
+ end
16
+
17
+
18
+
@@ -0,0 +1,129 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game_turn'
4
+ require_relative 'treasure_trove'
5
+
6
+
7
+ module BretsGame
8
+ class Game
9
+
10
+ attr_reader :title
11
+
12
+ def initialize(title)
13
+ @title = title
14
+ @players = []
15
+ end
16
+
17
+ def add_player(player)
18
+ @players << player
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
+
27
+ def print_name_and_health(player)
28
+ puts "#{player.name} (#{player.health})"
29
+ end
30
+
31
+ def total_points
32
+ @players.reduce(0) do |sum, player|
33
+ sum + player.points
34
+ end
35
+ end
36
+
37
+
38
+ def load_players(from_file)
39
+ File.readlines(from_file).each do |line|
40
+ add_player(Player.from_csv(line))
41
+ end
42
+ end
43
+
44
+ def save_high_scores(to_file = "high_scores.txt")
45
+ File.open(to_file, "w") do |file|
46
+ file.puts "#{@title}'s High Scores:"
47
+ @players.sort.each do |player|
48
+ file.puts high_score_entry(player)
49
+ end
50
+ end
51
+ end
52
+
53
+
54
+
55
+
56
+
57
+
58
+ def print_stats
59
+ strong_players, wimpy_players = @players.partition {|player| player.strong?}
60
+
61
+ puts "\n#{@title.upcase} STATISTICS:"
62
+
63
+
64
+
65
+ puts "\n#{strong_players.count} STRONG PLAYERS:"
66
+ strong_players.each do |player|
67
+ print_name_and_health(player)
68
+ end
69
+ puts "\n"
70
+
71
+ puts "#{wimpy_players.count} WIMPY PLAYERS:"
72
+ wimpy_players.each do |player|
73
+ print_name_and_health(player)
74
+ end
75
+ puts "\n"
76
+
77
+ @players.sort.each do |player|
78
+ puts "#{player.name} point totals:"
79
+ player.each_found_treasure do |treasure|
80
+ puts "#{treasure.points} total #{treasure.name} points"
81
+ end
82
+ puts "#{player.points} grand total points"
83
+ puts "\n"
84
+ end
85
+
86
+ puts "\n#{@title.upcase} HIGH SCORES:"
87
+
88
+ @players.sort.each do |player|
89
+ puts high_score_entry(player)
90
+ end
91
+
92
+ puts "\n#{total_points} total points from treasures found!"
93
+ end
94
+
95
+ #Inside the print_stats method of the Game class, iterate through each player in the game. For each player, call the each_found_treasure method with a block that takes a treasure as a block parameter. Inside the block, print out the treasure's name and points.
96
+
97
+ def play(rounds)
98
+ puts "There are #{@players.size} players in #{@title}!"
99
+ puts "\n"
100
+ @players.each do |player|
101
+ puts player
102
+ end
103
+
104
+
105
+ treasures = TreasureTrove::TREASURES
106
+
107
+ puts "\nThere are #{treasures.size} treasures to be found in the caves:"
108
+ treasures.each do |treasure|
109
+ puts "A #{treasure.name} is worth #{treasure.points} points"
110
+ end
111
+
112
+
113
+ puts "\n"
114
+ 1.upto(rounds) do |round|
115
+ puts "Round #{round}:"
116
+ puts "\n"
117
+ @players.each do |player|
118
+ GameTurn.take_turn(player)
119
+ puts player
120
+ puts "\n"
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+
127
+
128
+
129
+
@@ -0,0 +1,23 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'treasure_trove'
4
+ require_relative 'loaded_die'
5
+
6
+ module BretsGame
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
+ treasure = TreasureTrove.random
19
+ player.found_treasure(treasure)
20
+ end
21
+ end
22
+ end
23
+
@@ -0,0 +1,16 @@
1
+ require_relative 'auditable'
2
+
3
+ module BretsGame
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,20 @@
1
+ module BretsGame
2
+ module Playable
3
+ def w00t
4
+ self.health = self.health += 15
5
+ puts "#{name} got w00ted!"
6
+ end
7
+
8
+ def blam
9
+ self.health = self.health -= 10
10
+ puts "#{name} got blammed!"
11
+ end
12
+
13
+ def strong?
14
+ health > 100
15
+ end
16
+ end
17
+ end
18
+
19
+
20
+
@@ -0,0 +1,66 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module BretsGame
5
+ class Player
6
+ include Playable
7
+ attr_accessor :health
8
+ attr_accessor :name
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 found_treasure(treasure)
21
+
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
+
26
+ end
27
+
28
+ def self.from_csv(string)
29
+ name, health = string.split(',')
30
+ Player.new(name, Integer(health))
31
+ end
32
+
33
+ def each_found_treasure
34
+ @found_treasures.each do |name,points|
35
+ yield Treasure.new(name,points)
36
+ end
37
+ end
38
+
39
+
40
+ def points
41
+ @found_treasures.values.reduce(0, :+)
42
+ end
43
+
44
+ def <=>(other)
45
+ other.score <=>score
46
+ end
47
+
48
+
49
+ def score
50
+ @health + points
51
+ end
52
+ end
53
+ end
54
+
55
+ if __FILE__ == $0
56
+
57
+ player1 = Player.new("Bret",100)
58
+ puts player1.name
59
+ player1.blam
60
+ player1.w00t
61
+ puts player1.score
62
+ puts player1
63
+
64
+
65
+ end
66
+
@@ -0,0 +1,37 @@
1
+ module BretsGame
2
+ Treasure = Struct.new(:name,:points)
3
+ module TreasureTrove
4
+
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
+
15
+ def self.random
16
+ TREASURES.sample
17
+ end
18
+ end
19
+ end
20
+
21
+
22
+ if __FILE__ == $0
23
+ puts TreasureTrove::TREASURES
24
+ treasure = TreasureTrove.random
25
+ puts "Bret found a #{treasure.name} worth #{treasure.points} points!"
26
+ end
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
@@ -0,0 +1,40 @@
1
+ require 'studio_game/berserk_player'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module BretsGame
5
+ describe BerserkPlayer do
6
+
7
+ before do
8
+ $stdout = StringIO.new
9
+
10
+ @initial_health = 50
11
+ @player = BerserkPlayer.new("berserker", @initial_health)
12
+ end
13
+
14
+ it "does not go berserk when w00ted up to 5 times" do
15
+ 1.upto(5) { @player.w00t }
16
+
17
+ @player.berserk?.should be_falsey
18
+
19
+ # or if using Rspec 3.0:
20
+ # @player.berserk?.should be_falsey
21
+ end
22
+
23
+ it "goes berserk when w00ted more than 5 times" do
24
+ 1.upto(6) { @player.w00t }
25
+
26
+ @player.berserk?.should be_truthy
27
+
28
+ # or if using Rspec 3.0:
29
+ # @player.berserk?.should be_truthy
30
+ end
31
+
32
+ it "gets w00ted instead of blammed when it's gone berserk" do
33
+ 1.upto(6) { @player.w00t }
34
+ 1.upto(2) { @player.blam }
35
+
36
+ @player.health.should == @initial_health + (8 * 15)
37
+ end
38
+
39
+ end
40
+ end
@@ -0,0 +1,54 @@
1
+ require 'studio_game/clumsy_player'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module BretsGame
5
+
6
+ describe ClumsyPlayer do
7
+ before do
8
+ $stdout = StringIO.new
9
+ @player = ClumsyPlayer.new("klutz")
10
+ end
11
+
12
+ it "only gets half the point value for each treasure" do
13
+ @player.points.should == 0
14
+
15
+ hammer = Treasure.new(:hammer, 50)
16
+ @player.found_treasure(hammer)
17
+ @player.found_treasure(hammer)
18
+ @player.found_treasure(hammer)
19
+
20
+ @player.points.should == 75
21
+
22
+ crowbar = Treasure.new(:crowbar, 400)
23
+ @player.found_treasure(crowbar)
24
+
25
+ @player.points.should == 275
26
+
27
+ yielded = []
28
+ @player.each_found_treasure do |treasure|
29
+ yielded << treasure
30
+ end
31
+
32
+ yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
33
+ end
34
+
35
+
36
+ context "with a boost factor" do
37
+ before do
38
+ @initial_health = 100
39
+ @boost_factor = 5
40
+ @player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
41
+ end
42
+
43
+ it "has a boost factor" do
44
+ @player.boost_factor.should == 5
45
+ end
46
+
47
+ it "gets boost factor number of w00ts when w00ted" do
48
+ @player.w00t
49
+
50
+ @player.health.should == @initial_health + (15 * @boost_factor)
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,102 @@
1
+ require 'studio_game/game'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module BretsGame
5
+
6
+ describe Game do
7
+
8
+ before do
9
+ $stdout = StringIO.new
10
+ @game = Game.new("Knuckleheads")
11
+
12
+ @initial_health = 100
13
+ @player = Player.new("moe", @initial_health)
14
+
15
+ @game.add_player(@player)
16
+ end
17
+
18
+
19
+
20
+ it "w00ts a player when a high number is rolled(6)" do
21
+ Die.any_instance.stub(:roll).and_return(6)
22
+
23
+ @game.play(2)
24
+
25
+ @player.health.should == @initial_health + (15 * 2)
26
+ end
27
+
28
+ it "w00ts a player when a high number is rolled(5)" do
29
+ Die.any_instance.stub(:roll).and_return(5)
30
+
31
+ @game.play(2)
32
+
33
+ @player.health.should == @initial_health + (15 * 2)
34
+ end
35
+
36
+ it "skips a player when a medium number is rolled(4)" do
37
+ Die.any_instance.stub(:roll).and_return(4)
38
+
39
+ @game.play(2)
40
+
41
+ @player.health.should == @initial_health
42
+ end
43
+
44
+
45
+ it "skips a player when a medium number is rolled(3)" do
46
+ Die.any_instance.stub(:roll).and_return(3)
47
+
48
+ @game.play(2)
49
+
50
+ @player.health.should == @initial_health
51
+ end
52
+
53
+ it "blams a player when a medium number is rolled(2)" do
54
+ Die.any_instance.stub(:roll).and_return(2)
55
+
56
+ @game.play(2)
57
+
58
+ @player.health.should == @initial_health - (10 * 2)
59
+ end
60
+
61
+ it "blams a player when a medium number is rolled(1)" do
62
+ Die.any_instance.stub(:roll).and_return(1)
63
+
64
+ @game.play(2)
65
+
66
+ @player.health.should == @initial_health - (10 * 2)
67
+ end
68
+
69
+
70
+ it "assigns a treasure for points during a player's turn" do
71
+ game = Game.new("Knuckleheads")
72
+ player = Player.new("moe")
73
+
74
+ game.add_player(player)
75
+
76
+ game.play(1)
77
+
78
+ player.points.should_not be_zero
79
+
80
+ # or use alternate expectation syntax:
81
+ # expect(player.points).not_to be_zero
82
+ end
83
+
84
+
85
+ it "computes total points as the sum of all player points" do
86
+ game = Game.new("Knuckleheads")
87
+
88
+ player1 = Player.new("moe")
89
+ player2 = Player.new("larry")
90
+
91
+ game.add_player(player1)
92
+ game.add_player(player2)
93
+
94
+ player1.found_treasure(Treasure.new(:hammer, 50))
95
+ player1.found_treasure(Treasure.new(:hammer, 50))
96
+ player2.found_treasure(Treasure.new(:crowbar, 400))
97
+
98
+ game.total_points.should == 500
99
+ end
100
+ end
101
+ end
102
+
@@ -0,0 +1,127 @@
1
+ require 'studio_game/player'
2
+ require 'studio_game/spec_helper'
3
+ require 'studio_game/treasure_trove'
4
+
5
+ module BretsGame
6
+
7
+ describe Player do
8
+
9
+ before do
10
+ $stdout = StringIO.new
11
+ @initial_health = 150
12
+ @player = Player.new("bret", @initial_health)
13
+ end
14
+
15
+ it "has a capitalized name" do
16
+ @player.name.should == "Bret"
17
+ end
18
+
19
+ it "has an initial health" do
20
+ @player.health.should == 150
21
+ end
22
+
23
+ it "has a string representation" do
24
+ @player.found_treasure(Treasure.new(:hammer, 50))
25
+ @player.found_treasure(Treasure.new(:hammer, 50))
26
+
27
+ @player.to_s.should == "I'm Bret with health = 150, points = 100, and score = 250."
28
+ end
29
+
30
+ it "computes a score as the sum of its health and points" do
31
+ @player.found_treasure(Treasure.new(:hammer, 50))
32
+ @player.found_treasure(Treasure.new(:hammer, 50))
33
+
34
+ @player.score.should == 250
35
+ end
36
+
37
+ it "can be created from a CSV string" do
38
+ player = Player.from_csv("larry,150")
39
+
40
+ player.name.should == "Larry"
41
+ player.health.should == 150
42
+ end
43
+
44
+ it "yields each found treasure and its total points" do
45
+ @player.found_treasure(Treasure.new(:skillet, 100))
46
+ @player.found_treasure(Treasure.new(:skillet, 100))
47
+ @player.found_treasure(Treasure.new(:hammer, 50))
48
+ @player.found_treasure(Treasure.new(:bottle, 5))
49
+ @player.found_treasure(Treasure.new(:bottle, 5))
50
+ @player.found_treasure(Treasure.new(:bottle, 5))
51
+ @player.found_treasure(Treasure.new(:bottle, 5))
52
+ @player.found_treasure(Treasure.new(:bottle, 5))
53
+
54
+ yielded = []
55
+ @player.each_found_treasure do |treasure|
56
+ yielded << treasure
57
+ end
58
+
59
+ yielded.should == [
60
+ Treasure.new(:skillet, 200),
61
+ Treasure.new(:hammer, 50),
62
+ Treasure.new(:bottle, 25)
63
+ ]
64
+ end
65
+
66
+ it "increases health by 15 when w00ted" do
67
+ @player.w00t
68
+ @player.health.should == @initial_health + 15
69
+ end
70
+
71
+ it "decreases health by 10 when blammed" do
72
+ @player.blam
73
+ @player.health.should == @initial_health - 10
74
+ end
75
+
76
+ it "computes points as the sum of all treasure points" do
77
+ @player.points.should == 0
78
+
79
+ @player.found_treasure(Treasure.new(:hammer, 50))
80
+
81
+ @player.points.should == 50
82
+
83
+ @player.found_treasure(Treasure.new(:crowbar, 400))
84
+
85
+ @player.points.should == 450
86
+
87
+ @player.found_treasure(Treasure.new(:hammer, 50))
88
+
89
+ @player.points.should == 500
90
+ end
91
+
92
+ context "with a health greater than 100" do
93
+ before do
94
+ @player = Player.new("bret",150)
95
+ end
96
+
97
+ it "is strong" do
98
+ @player.should be_strong
99
+ end
100
+ end
101
+
102
+ context "with a health less than 100" do
103
+ before do
104
+ @player = Player.new("bret",9)
105
+ end
106
+
107
+ it "is weak" do
108
+ @player.should_not be_strong
109
+ end
110
+
111
+ context "in a collection of players" do
112
+ before do
113
+ @player1 = Player.new("moe", 100)
114
+ @player2 = Player.new("larry", 200)
115
+ @player3 = Player.new("curly", 300)
116
+
117
+ @players = [@player1, @player2, @player3]
118
+ end
119
+
120
+ it "is sorted by decreasing score" do
121
+ @players.sort.should == [@player3, @player2, @player1]
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
127
+
@@ -0,0 +1,11 @@
1
+ #This enables both the use of the traditional should syntax, as well as the newer expect syntax.
2
+ module BretsGame
3
+ RSpec.configure do |config|
4
+ config.expect_with :rspec do |c|
5
+ c.syntax = [:should, :expect]
6
+ end
7
+ config.mock_with :rspec do |c|
8
+ c.syntax = [:should, :expect]
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,63 @@
1
+ require 'studio_game/treasure_trove'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module BretsGame
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
+
51
+ end
52
+
53
+ it "returns a random treasure" do
54
+ treasure = TreasureTrove.random
55
+
56
+ TreasureTrove::TREASURES.should include(treasure)
57
+
58
+ # or use alternate expectation syntax:
59
+ # expect(TreasureTrove::TREASURES).to include(treasure)
60
+ end
61
+ end
62
+ end
63
+
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thesweaters_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Bret Doucette
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-12 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 is an example application used in The Pragmatic Studio's \nRuby
28
+ Programming course, as described at\n\n http://pragmaticstudio.com\n\nThis code
29
+ is Copyright 2012 The Pragmatic Studio. See the LICENSE file."
30
+ email: sweater@sweatersaga.com
31
+ executables:
32
+ - studio_game
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - bin/high_scores.txt
39
+ - bin/players.csv
40
+ - bin/studio_game
41
+ - lib/studio_game/auditable.rb
42
+ - lib/studio_game/berserk_player.rb
43
+ - lib/studio_game/clumsy_player.rb
44
+ - lib/studio_game/die.rb
45
+ - lib/studio_game/game.rb
46
+ - lib/studio_game/game_turn.rb
47
+ - lib/studio_game/loaded_die.rb
48
+ - lib/studio_game/playable.rb
49
+ - lib/studio_game/player.rb
50
+ - lib/studio_game/treasure_trove.rb
51
+ - spec/studio_game/berserk_player.spec
52
+ - spec/studio_game/clumsy_player_spec.spec
53
+ - spec/studio_game/game_spec.spec
54
+ - spec/studio_game/player_spec.spec
55
+ - spec/studio_game/spec_helper.rb
56
+ - spec/studio_game/treasure_trove_spec.spec
57
+ homepage: http://www.sweatersaga.com
58
+ licenses:
59
+ - MIT
60
+ metadata: {}
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '1.9'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.4.5
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: A random games based on the roll of a die
81
+ test_files:
82
+ - spec/studio_game/berserk_player.spec
83
+ - spec/studio_game/clumsy_player_spec.spec
84
+ - spec/studio_game/game_spec.spec
85
+ - spec/studio_game/player_spec.spec
86
+ - spec/studio_game/spec_helper.rb
87
+ - spec/studio_game/treasure_trove_spec.spec