studio_game_mw 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: 1097f882a004330d6491ba45592e920d165d8a29
4
+ data.tar.gz: 0508347628f716856b1d6c096ea10dbc2fb43690
5
+ SHA512:
6
+ metadata.gz: 5bbc1b64187b6908218ca53323ab22c383534fa8817d9a77890dc86f46d11350c253fad6af32f9e64d2a6127537be3e1327f6a84288d905e58fb28efb49618fa
7
+ data.tar.gz: 719588e606038ccf5906c5de727c9c90d89a0b54a1e87d3050d88f503522f15fb2d6530f0dfcdbeb36b8165ea44c0d842af3dff4202e3246e144421a5a84d640
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,7 @@
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.
7
+
@@ -0,0 +1,6 @@
1
+ Knuckleheads High Scores:
2
+ Aaron............... 1320
3
+ Theo................ 620
4
+ Berserker........... 595
5
+ Klutz............... 435.0
6
+ Mark................ 405
data/bin/players.csv ADDED
@@ -0,0 +1,3 @@
1
+ Aaron,100
2
+ Mark,60
3
+ Theo,125
data/bin/studio_game ADDED
@@ -0,0 +1,39 @@
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
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
9
+ puts knuckleheads.title
10
+ default_file_name = File.join(File.dirname(__FILE__), 'players.csv')
11
+ knuckleheads.load_players(ARGV.shift || default_file_name)
12
+
13
+ klutz = StudioGame::ClumsyPlayer.new("klutz", 105, 5)
14
+ knuckleheads.add_player(klutz)
15
+
16
+ berserker = StudioGame::BerserkPlayer.new("berserker", 50)
17
+ knuckleheads.add_player(berserker)
18
+
19
+ loop do
20
+ puts "How many rounds? ('quit' to exit)"
21
+ answer = gets.chomp.downcase
22
+ case answer
23
+ when /^\d+$/
24
+ puts "Enjoy your #{answer} rounds of play....."
25
+ knuckleheads.play(answer.to_i)
26
+ knuckleheads.print_stats
27
+ when 'quit','exit'
28
+ knuckleheads.print_stats
29
+ break
30
+ when 'q','x'
31
+ knuckleheads.print_stats
32
+ break
33
+ else
34
+ puts "Enter a number or 'quit' to exit"
35
+ end
36
+
37
+ knuckleheads.save_high_scores
38
+
39
+ end
@@ -0,0 +1,9 @@
1
+ module StudioGame
2
+ module Auditable
3
+
4
+ def audit
5
+ puts "Rolled a #{self.number} (#{self.class})"
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'player'
2
+ module StudioGame
3
+ class BerserkPlayer < Player
4
+
5
+ def initialize(name, health=100)
6
+ super(name, health)
7
+ @w00t_count = 0
8
+ @initial_health = health
9
+ end
10
+
11
+ def w00t
12
+ super
13
+ @w00t_count += 1
14
+ puts "#{@name} is berserk!" if berserk?
15
+ end
16
+
17
+ def blam
18
+ berserk? ? w00t : super
19
+ end
20
+
21
+ def berserk?
22
+ @w00t_count > 5
23
+ end
24
+ end
25
+
26
+ if __FILE__ == $0
27
+ berserker = BerserkPlayer.new("berserk",50)
28
+
29
+ 6.times {berserker.w00t}
30
+ puts "this is my health: #{berserker.health}"
31
+ puts berserker.berserk?
32
+ 2.times {berserker.blam}
33
+
34
+ puts berserker.health
35
+ end
36
+ end
@@ -0,0 +1,42 @@
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
+ # @found_treasures[treasure.name] += (treasure.points/2.0)
20
+ # puts "#{@name} found a #{treasure.name} worth #{treasure.points} points"
21
+ end
22
+
23
+ end
24
+
25
+ if __FILE__ == $0
26
+ clumsy = ClumsyPlayer.new("klutz", 100,10)
27
+
28
+ hammer = Treasure.new(:hammer, 50)
29
+ clumsy.found_treasure(hammer)
30
+ clumsy.found_treasure(hammer)
31
+ clumsy.found_treasure(hammer)
32
+ clumsy.w00t
33
+ puts "#{clumsy.boost_factor}"
34
+ crowbar = Treasure.new(:crowbar, 400)
35
+ clumsy.found_treasure(crowbar)
36
+
37
+ clumsy.each_found_treasure do |treasure|
38
+ puts "#{treasure.points} total #{treasure.name} points"
39
+ end
40
+ puts "#{clumsy.points} grand total points"
41
+ end
42
+ end
@@ -0,0 +1,18 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class Die
5
+ include Auditable
6
+ attr_reader :number
7
+
8
+ def initialize
9
+ roll
10
+ end
11
+
12
+ def roll
13
+ @number = rand(1..6)
14
+ audit
15
+ @number
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,115 @@
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
+ attr_reader :title
10
+ attr_reader :players
11
+ def initialize(title)
12
+ @title = title
13
+ @players =[]
14
+ end
15
+
16
+ def load_players(from_file)
17
+ puts "Loading players ..........."
18
+ CSV.foreach(from_file) do |row|
19
+ add_player(Player.new(row[0],row[1].to_i))
20
+ end
21
+ end
22
+
23
+ def high_score_entry(player)
24
+ "#{player.name.ljust(20,'.')} #{player.score}"
25
+ end
26
+
27
+ def save_high_scores(save_file="high_scores.txt")
28
+ File.open(save_file, "w") do |file|
29
+ file.puts "#{@title} High Scores:"
30
+ sorted_players = @players.sort {|a,b| b.score <=> a.score}
31
+ sorted_players.each do |p|
32
+ file.puts high_score_entry(p)
33
+ end
34
+ end
35
+ end
36
+
37
+ def total_points
38
+ @players.reduce(0) { |sum, p| sum + p.points }
39
+ end
40
+
41
+ def print_name_and_health(p)
42
+ puts "#{p.name} (#{p.health})"
43
+ end
44
+
45
+ def add_player(player)
46
+ @players << player
47
+ end
48
+
49
+ def print_stats
50
+ strong_players, wimpy_players = @players.partition{|p| p.strong?}
51
+ puts "\n#{@title} Statistics:"
52
+ puts "\n#{strong_players.length} strong players:"
53
+ strong_players.each do |p|
54
+ print_name_and_health(p)
55
+ end
56
+
57
+ puts "\n#{wimpy_players.length} wimpy players:"
58
+ wimpy_players.each do |p|
59
+ print_name_and_health(p)
60
+ end
61
+
62
+ puts "\n#{@title} High Scores:"
63
+ sorted_players = @players.sort {|a,b| b.score <=> a.score}
64
+ sorted_players.each do |p|
65
+ puts high_score_entry(p)
66
+ end
67
+
68
+ @players.each do |p|
69
+ puts "\n#{p.name}'s point totals:"
70
+ p.each_found_treasure do |treasure|
71
+ puts "#{treasure.points} total #{treasure.name} points"
72
+ end
73
+ puts "#{p.score} grand total points"
74
+ end
75
+
76
+ puts "#{total_points} total points from treasures found"
77
+
78
+ end
79
+
80
+ def play(rounds)
81
+ puts "There are #{@players.size} players in #{@title}: "
82
+
83
+ @players.each do |p|
84
+ puts p
85
+ end
86
+
87
+ treasures = TreasureTrove::TREASURES
88
+ puts "\nThere are #{treasures.length} treasures to be found:"
89
+ treasures.each do |treasure|
90
+ puts "A #{treasure.name} is worth #{treasure.points} points"
91
+ end
92
+
93
+ 1.upto(rounds) do |r|
94
+ if block_given?
95
+ break if yield
96
+ end
97
+ puts "\nRound Number: #{r}"
98
+ @players.each do |p|
99
+ GameTurn.take_turn(p)
100
+ puts p
101
+ end
102
+ end
103
+ end
104
+ end
105
+
106
+ if __FILE__ ==$PROGRAM_NAME
107
+ game = Game.new("Kerplunk")
108
+ player1 = Player.new("mouse")
109
+ player2 = Player.new("cat")
110
+ game.add_player(player1)
111
+ game.add_player(player2)
112
+ puts game.players
113
+ game.play(2)
114
+ end
115
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'die'
2
+ require_relative 'player'
3
+ require_relative 'treasure_trove'
4
+ require_relative 'loaded_die'
5
+
6
+ module StudioGame
7
+ module GameTurn
8
+
9
+ def self.take_turn(p)
10
+ dice = LoadedDie.new
11
+ case dice.roll
12
+ when 1..2
13
+ p.blam
14
+ when 3..4
15
+ puts "#{p.name} was skipped."
16
+ else
17
+ p.w00t
18
+ end
19
+
20
+ treasure = TreasureTrove.random
21
+ p.found_treasure(treasure)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require_relative 'auditable'
2
+ module StudioGame
3
+ class LoadedDie
4
+ include Auditable
5
+ attr_reader :number
6
+
7
+ def roll
8
+ numbers = [1,1,2,5,6,6]
9
+ @number = numbers.sample
10
+ audit
11
+ @number
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,19 @@
1
+ module StudioGame
2
+ module Playable
3
+
4
+ def blam
5
+ self.health -= 10
6
+ puts "Oops! #{name} just got blammed"
7
+ end
8
+
9
+ def w00t
10
+ self.health += 15
11
+ puts "#{name} got w00ted!"
12
+ end
13
+
14
+ def strong?
15
+ health > 100
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,61 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Player
6
+ attr_accessor :health
7
+ attr_accessor :name
8
+ include Playable
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 self.from_csv (line)
17
+ name, health = line.split(',')
18
+ Player.new(name, Integer(health))
19
+ end
20
+
21
+ def each_found_treasure
22
+ @found_treasures.each do |name, points|
23
+ treasure = Treasure.new(name, points)
24
+ yield(treasure)
25
+ end
26
+ end
27
+
28
+ def found_treasure(treasure)
29
+ @found_treasures[treasure.name] += treasure.points
30
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points"
31
+ # puts "\n#{@name}'s treasures: #{@found_treasures}'"
32
+ end
33
+
34
+ def points
35
+ @found_treasures.values.reduce(0, :+)
36
+ end
37
+
38
+ def to_s
39
+ "I'm #{@name} with a health = #{@health}, points = #{points}, and score = #{score}"
40
+ end
41
+
42
+ def score
43
+ @health+points
44
+ end
45
+
46
+ def name=(new_name)
47
+ @name = new_name.capitalize
48
+ end
49
+ end
50
+
51
+ if __FILE__ == $PROGRAM_NAME
52
+ player = Player.new("moe",100)
53
+ puts player.points
54
+ puts player.name
55
+ puts player.health
56
+ player.w00t
57
+ puts player.health
58
+ player.blam
59
+ puts player.health
60
+ end
61
+ end
@@ -0,0 +1,19 @@
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
+
18
+ end
19
+ end
@@ -0,0 +1,28 @@
1
+ require 'studio_game/berserk_player'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module StudioGame
5
+ describe BerserkPlayer do
6
+ before do
7
+ $stdout = StringIO.new
8
+ @player = BerserkPlayer.new("berserker",50)
9
+ end
10
+
11
+ it "does not go berserk when w00ted up to 5 times" do
12
+ 1.upto(5) {@player.w00t}
13
+ @player.berserk?.should be false
14
+ end
15
+
16
+ it "goes berserk when w00ted more than 5 times" do
17
+ 6.times {@player.w00t}
18
+ @player.berserk?.should be true
19
+ end
20
+
21
+ it "gets w00ted instead of blammed when it goes berserk" do
22
+ 6.times {@player.w00t}
23
+ 2.times {@player.blam}
24
+ @player.health.should == 170
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,50 @@
1
+ require 'studio_game/clumsy_player'
2
+ require 'studio_game/spec_helper'
3
+
4
+ module StudioGame
5
+ describe ClumsyPlayer do
6
+ before do
7
+ $stdout = StringIO.new
8
+ @player = ClumsyPlayer.new("klutz")
9
+ end
10
+
11
+ it "only gets half the point value for each treasure" do
12
+ @player.points.should == 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
+ @player.points.should == 75
20
+
21
+ crowbar = Treasure.new(:crowbar, 400)
22
+ @player.found_treasure(crowbar)
23
+
24
+ @player.points.should == 275
25
+
26
+ yielded = []
27
+ @player.each_found_treasure do |treasure|
28
+ yielded << treasure
29
+ end
30
+
31
+ yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
32
+ end
33
+
34
+ context "with a boost factor" do
35
+ before do
36
+ @initial_health = 100
37
+ @boost_factor = 5
38
+ @p = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
39
+ end
40
+ it "has a boost factor" do
41
+ @p.boost_factor.should == 5
42
+ end
43
+ it "gets a boost factor when w00ted" do
44
+ @p.w00t
45
+ @p.health.should == @initial_health + (15 * @boost_factor)
46
+ end
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,69 @@
1
+ require 'studio_game/spec_helper'
2
+ require 'studio_game/game'
3
+
4
+ module StudioGame
5
+ describe Game do
6
+ before do
7
+ $stdout = StringIO.new
8
+ @game = Game.new("Knuckleheads")
9
+ @initial_health = 100
10
+ @player = Player.new("moe", @initial_health)
11
+ @game.add_player(@player)
12
+
13
+ end
14
+
15
+ context "When a high number is rolled" do
16
+ it "adds 15 to the players health" do
17
+ LoadedDie.any_instance.stub(:roll).and_return(5)
18
+ @game.play(2)
19
+ @player.health.should == @initial_health + (15 * 2)
20
+ end
21
+ end
22
+
23
+ context "When a medium number is rolled" do
24
+ it "does not change the players health" do
25
+ LoadedDie.any_instance.stub(:roll).and_return(3)
26
+ @game.play(2)
27
+ @player.health.should == @initial_health
28
+ end
29
+ end
30
+
31
+ context "When a low number is rolled" do
32
+ it "subtracts 15 from the players health" do
33
+ LoadedDie.any_instance.stub(:roll).and_return(1)
34
+ @game.play(2)
35
+ @player.health.should == @initial_health - (10 * 2)
36
+ end
37
+ end
38
+
39
+ it "assigns a treasure for points during a player's turn" do
40
+ game = Game.new("Knuckleheads")
41
+ player = Player.new("moe")
42
+
43
+ game.add_player(player)
44
+
45
+ game.play(1)
46
+
47
+ player.points.should_not be_zero
48
+
49
+ # or use alternate expectation syntax:
50
+ # expect(player.points).not_to be_zero
51
+ end
52
+
53
+ it "computes total points as the sum of all player points" do
54
+ game = Game.new("Knuckleheads")
55
+
56
+ player1 = Player.new("jack")
57
+ player2 = Player.new("jill")
58
+
59
+ game.add_player(player1)
60
+ game.add_player(player2)
61
+
62
+ player1.found_treasure(Treasure.new(:hammer, 50))
63
+ player1.found_treasure(Treasure.new(:hammer, 50))
64
+ player2.found_treasure(Treasure.new(:crowbar, 400))
65
+
66
+ game.total_points.should == 500
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,111 @@
1
+ require 'studio_game/spec_helper'
2
+ require 'studio_game/player'
3
+ require 'studio_game/treasure_trove'
4
+
5
+ module StudioGame
6
+ describe Player do
7
+ before do
8
+ $stdout = StringIO.new
9
+ @initial_health = 150
10
+ @p = Player.new("larry", @initial_health)
11
+ end
12
+
13
+ it "has a capitalized title" do
14
+ @p.name.should == "Larry"
15
+ end
16
+
17
+ it "has an initial health" do
18
+ @p.health.should == 150
19
+ end
20
+
21
+ it "has a string representation" do
22
+ @p.found_treasure(Treasure.new(:hammer, 50))
23
+ @p.found_treasure(Treasure.new(:hammer, 50))
24
+
25
+ @p.to_s.should == "I'm Larry with a health = 150, points = 100, and score = 250"
26
+ end
27
+
28
+ it "computes a score as the sum of its health and points" do
29
+ @p.found_treasure(Treasure.new(:hammer, 50))
30
+ @p.found_treasure(Treasure.new(:hammer, 50))
31
+ @p.score.should == 250
32
+ end
33
+
34
+ it "increases health by 15 when w00ted" do
35
+ @p.w00t
36
+ @p.health.should == @initial_health + 15
37
+ end
38
+
39
+ it "decreases health by 10 when blammed" do
40
+ @p.blam
41
+ @p.health.should == @initial_health - 10
42
+ end
43
+
44
+ it "computes points as the sum of all treasure points" do
45
+ @p.points.should == 0
46
+
47
+ @p.found_treasure(Treasure.new(:hammer, 50))
48
+
49
+ @p.points.should == 50
50
+
51
+ @p.found_treasure(Treasure.new(:crowbar, 400))
52
+
53
+ @p.points.should == 450
54
+
55
+ @p.found_treasure(Treasure.new(:hammer, 50))
56
+
57
+ @p.points.should == 500
58
+ end
59
+
60
+ context "With a health greater than 100" do
61
+ before do
62
+ @initial_health = 150
63
+ @p = Player.new("jimmy", @initial_health)
64
+ end
65
+
66
+ it "is strong" do
67
+ @p.should be_strong
68
+ end
69
+ end
70
+
71
+ context "With a health of 100 or less" do
72
+ before do
73
+ @initial_health = 100
74
+ @p = Player.new("jimmy", @initial_health)
75
+ end
76
+
77
+ it "is wimpy" do
78
+ @p.should_not be_strong
79
+ end
80
+ end
81
+
82
+ it "yields each found treasure and its total points" do
83
+ @p.found_treasure(Treasure.new(:skillet, 100))
84
+ @p.found_treasure(Treasure.new(:skillet, 100))
85
+ @p.found_treasure(Treasure.new(:hammer, 50))
86
+ @p.found_treasure(Treasure.new(:bottle, 5))
87
+ @p.found_treasure(Treasure.new(:bottle, 5))
88
+ @p.found_treasure(Treasure.new(:bottle, 5))
89
+ @p.found_treasure(Treasure.new(:bottle, 5))
90
+ @p.found_treasure(Treasure.new(:bottle, 5))
91
+
92
+ yielded = []
93
+ @p.each_found_treasure do |treasure|
94
+ yielded << treasure
95
+ end
96
+
97
+ yielded.should == [
98
+ Treasure.new(:skillet, 200),
99
+ Treasure.new(:hammer, 50),
100
+ Treasure.new(:bottle, 25)
101
+ ]
102
+ end
103
+
104
+ it "can create a player from a csv string" do
105
+ player = Player.from_csv("tim,100")
106
+ player.name.should == "Tim"
107
+ player.health.should == 100
108
+ end
109
+
110
+ end
111
+ end
@@ -0,0 +1,8 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |c|
3
+ c.syntax = [:should, :expect]
4
+ end
5
+ config.mock_with :rspec do |c|
6
+ c.syntax = [:should, :expect]
7
+ end
8
+ end
@@ -0,0 +1,61 @@
1
+ require 'studio_game/treasure_trove'
2
+ require 'studio_game/spec_helper'
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
+ @treasure.name.should == :hammer
11
+ end
12
+
13
+ it "has a points attribute" do
14
+ @treasure.points.should == 50
15
+ end
16
+ end
17
+
18
+ describe TreasureTrove do
19
+
20
+ it "has six treasures" do
21
+ TreasureTrove::TREASURES.length.should == 6
22
+ # TreasureTrove::TREASURES.size.should == 6
23
+ end
24
+
25
+ it "has a pie worth 5 points" do
26
+ TreasureTrove::TREASURES[0].should == Treasure.new(:pie,5)
27
+ TreasureTrove::TREASURES[0].name.should == :pie
28
+ # TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
29
+ end
30
+
31
+ it "has a bottle worth 25 points" do
32
+ TreasureTrove::TREASURES[1].should == Treasure.new(:bottle,25)
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
+ # TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
39
+ end
40
+
41
+ it "has a skillet worth 100 points" do
42
+ TreasureTrove::TREASURES[3].should == Treasure.new(:skillet,100)
43
+ # TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
44
+ end
45
+
46
+ it "has a broomstick worth 200 points" do
47
+ TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick,200)
48
+ # TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
49
+ end
50
+
51
+ it "has a crowbar worth 400 points" do
52
+ TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar,400)
53
+ # TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
54
+ end
55
+
56
+ it "returns a random treasure" do
57
+ treasure = TreasureTrove.random
58
+ TreasureTrove::TREASURES.should include(treasure)
59
+ end
60
+ end
61
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_mw
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Walsh
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-12-07 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.\n\t\n"
30
+ email: michael.tom.walsh@gmail.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.rb
52
+ - spec/studio_game/clumsy_player_spec.rb
53
+ - spec/studio_game/game_spec.rb
54
+ - spec/studio_game/player_spec.rb
55
+ - spec/studio_game/spec_helper.rb
56
+ - spec/studio_game/treasure_trove_spec.rb
57
+ homepage: https://au.linkedin.com/in/Monkee45
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.2.3
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: newbie game play
81
+ test_files:
82
+ - spec/studio_game/berserk_player_spec.rb
83
+ - spec/studio_game/clumsy_player_spec.rb
84
+ - spec/studio_game/game_spec.rb
85
+ - spec/studio_game/player_spec.rb
86
+ - spec/studio_game/spec_helper.rb
87
+ - spec/studio_game/treasure_trove_spec.rb