StudioGame 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.
- data/LICENSE +8 -0
 - data/README +1 -0
 - data/bin/players.csv +3 -0
 - data/bin/studio_game +27 -0
 - data/lib/studio_game/auditable.rb +8 -0
 - data/lib/studio_game/berserk_player.rb +38 -0
 - data/lib/studio_game/clumsy_player.rb +30 -0
 - data/lib/studio_game/die.rb +27 -0
 - data/lib/studio_game/game.rb +85 -0
 - data/lib/studio_game/game_turn.rb +26 -0
 - data/lib/studio_game/loaded_die.rb +17 -0
 - data/lib/studio_game/playable.rb +20 -0
 - data/lib/studio_game/player.rb +58 -0
 - data/lib/studio_game/treasure_trove.rb +20 -0
 - data/spec/studio_game/beserk_player_spec.rb +22 -0
 - data/spec/studio_game/clumsy_player_spec.rb +32 -0
 - data/spec/studio_game/game_spec.rb +52 -0
 - data/spec/studio_game/player_spec.rb +116 -0
 - data/spec/studio_game/treasure_trove_spec.rb +50 -0
 - metadata +87 -0
 
    
        data/LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,8 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright (C) 2013 Robert Warner Walsh, Jr.
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
             Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
               THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
    
        data/README
    ADDED
    
    | 
         @@ -0,0 +1 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Example gemset from Pragmatic Studio.
         
     | 
    
        data/bin/players.csv
    ADDED
    
    
    
        data/bin/studio_game
    ADDED
    
    | 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative '../lib/studio_game/clumsy_player'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative '../lib/studio_game/berserk_player'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative '../lib/studio_game/game'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            knuckleheads = StudioGame::Game.new("Knuckleheads")
         
     | 
| 
      
 8 
     | 
    
         
            +
            knuckleheads.load_players(ARGV.shift || File.join(File.dirname(__FILE__),"players.csv"))
         
     | 
| 
      
 9 
     | 
    
         
            +
            knuckleheads.add_player(StudioGame::ClumsyPlayer.new("klutz",104));
         
     | 
| 
      
 10 
     | 
    
         
            +
            knuckleheads.add_player(StudioGame::BerserkPlayer.new("berserker",50));
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
            loop do
         
     | 
| 
      
 13 
     | 
    
         
            +
                puts "\nHow many game rounds? ('quit' to exit)"
         
     | 
| 
      
 14 
     | 
    
         
            +
                rounds = gets.chomp.downcase
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                case rounds
         
     | 
| 
      
 17 
     | 
    
         
            +
                when /^\d+$/
         
     | 
| 
      
 18 
     | 
    
         
            +
                    knuckleheads.play(rounds.to_i)
         
     | 
| 
      
 19 
     | 
    
         
            +
                when 'quit', 'exit'
         
     | 
| 
      
 20 
     | 
    
         
            +
                    knuckleheads.print_stats
         
     | 
| 
      
 21 
     | 
    
         
            +
                    break
         
     | 
| 
      
 22 
     | 
    
         
            +
                else
         
     | 
| 
      
 23 
     | 
    
         
            +
                    puts "Please enter a number or 'quit'"
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
            end
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
            knuckleheads.save_high_scores(ARGV.shift || "high_scores.txt")
         
     | 
| 
         @@ -0,0 +1,38 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative("player")
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                class BerserkPlayer < StudioGame::Player
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                  def initialize(name, health=100)
         
     | 
| 
      
 8 
     | 
    
         
            +
                     @w00tcount = 0
         
     | 
| 
      
 9 
     | 
    
         
            +
                     super(name,health)
         
     | 
| 
      
 10 
     | 
    
         
            +
                  end 
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def berserk?
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @w00tcount > 5
         
     | 
| 
      
 14 
     | 
    
         
            +
                  end
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def w00t
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @w00tcount += 1
         
     | 
| 
      
 18 
     | 
    
         
            +
                    super
         
     | 
| 
      
 19 
     | 
    
         
            +
                    puts "#{@name} is berserk!" if berserk?
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def blam
         
     | 
| 
      
 23 
     | 
    
         
            +
                    if berserk?
         
     | 
| 
      
 24 
     | 
    
         
            +
                       w00t
         
     | 
| 
      
 25 
     | 
    
         
            +
                    else
         
     | 
| 
      
 26 
     | 
    
         
            +
                      super
         
     | 
| 
      
 27 
     | 
    
         
            +
                    end
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                if __FILE__ == $0
         
     | 
| 
      
 32 
     | 
    
         
            +
                  berserker = BerserkPlayer.new("berserker", 50)
         
     | 
| 
      
 33 
     | 
    
         
            +
                  6.times { berserker.w00t }
         
     | 
| 
      
 34 
     | 
    
         
            +
                  2.times { berserker.blam }
         
     | 
| 
      
 35 
     | 
    
         
            +
                  puts berserker.health
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative "player"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                class ClumsyPlayer < Player
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                    def found_treasure(treasure)
         
     | 
| 
      
 8 
     | 
    
         
            +
                        super(Treasure.new(treasure.name, treasure.points/2.0))
         
     | 
| 
      
 9 
     | 
    
         
            +
                    end
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                if __FILE__ == $0
         
     | 
| 
      
 15 
     | 
    
         
            +
                  clumsy = ClumsyPlayer.new("klutz")  
         
     | 
| 
      
 16 
     | 
    
         
            +
                  
         
     | 
| 
      
 17 
     | 
    
         
            +
                  hammer = Treasure.new(:hammer, 50)
         
     | 
| 
      
 18 
     | 
    
         
            +
                  clumsy.found_treasure(hammer)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  clumsy.found_treasure(hammer)
         
     | 
| 
      
 20 
     | 
    
         
            +
                  clumsy.found_treasure(hammer)
         
     | 
| 
      
 21 
     | 
    
         
            +
                  
         
     | 
| 
      
 22 
     | 
    
         
            +
                  crowbar = Treasure.new(:crowbar, 400)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  clumsy.found_treasure(crowbar)
         
     | 
| 
      
 24 
     | 
    
         
            +
                  
         
     | 
| 
      
 25 
     | 
    
         
            +
                  clumsy.each_found_treasure do |treasure|
         
     | 
| 
      
 26 
     | 
    
         
            +
                    puts "#{treasure.points} total #{treasure.name} points"
         
     | 
| 
      
 27 
     | 
    
         
            +
                  end
         
     | 
| 
      
 28 
     | 
    
         
            +
                  puts "#{clumsy.points} grand total points"
         
     | 
| 
      
 29 
     | 
    
         
            +
                end
         
     | 
| 
      
 30 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative "auditable"
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
                class Die 
         
     | 
| 
      
 6 
     | 
    
         
            +
                  include Auditable
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                  attr_reader :number
         
     | 
| 
      
 9 
     | 
    
         
            +
                  
         
     | 
| 
      
 10 
     | 
    
         
            +
                  def initialize
         
     | 
| 
      
 11 
     | 
    
         
            +
                    roll
         
     | 
| 
      
 12 
     | 
    
         
            +
                  end
         
     | 
| 
      
 13 
     | 
    
         
            +
                  
         
     | 
| 
      
 14 
     | 
    
         
            +
                  def roll
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @number = rand(1..6)
         
     | 
| 
      
 16 
     | 
    
         
            +
                    audit
         
     | 
| 
      
 17 
     | 
    
         
            +
                    @number
         
     | 
| 
      
 18 
     | 
    
         
            +
                  end
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                if __FILE__ == $0
         
     | 
| 
      
 22 
     | 
    
         
            +
                  die = Die.new
         
     | 
| 
      
 23 
     | 
    
         
            +
                  puts die.roll
         
     | 
| 
      
 24 
     | 
    
         
            +
                  puts die.roll
         
     | 
| 
      
 25 
     | 
    
         
            +
                  puts die.roll
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,85 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'player'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'die'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'game_turn'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative 'treasure_trove'
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                class Game
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                  attr_accessor :title
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def initialize(title)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @title = title
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @players = []
         
     | 
| 
      
 15 
     | 
    
         
            +
                  end
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
                  def add_player(a_player)
         
     | 
| 
      
 18 
     | 
    
         
            +
                    @players.push(a_player)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  def play(round)
         
     | 
| 
      
 22 
     | 
    
         
            +
                    puts "There are #{@players.size} players in #{@title}: "
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    @players.each do |player|
         
     | 
| 
      
 25 
     | 
    
         
            +
                      puts player
         
     | 
| 
      
 26 
     | 
    
         
            +
                    end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                    treasures = TreasureTrove::TREASURES
         
     | 
| 
      
 29 
     | 
    
         
            +
                    puts "\nThere are #{treasures.size} treasures to be found:"
         
     | 
| 
      
 30 
     | 
    
         
            +
                    treasures.each { |t| puts "A #{t[:name]} is worth #{t[:points]}" }
         
     | 
| 
      
 31 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
                    round.times do |n|
         
     | 
| 
      
 34 
     | 
    
         
            +
                        puts "Round #{n+1}:"
         
     | 
| 
      
 35 
     | 
    
         
            +
                        @players.each do |player|
         
     | 
| 
      
 36 
     | 
    
         
            +
                            GameTurn.take_turn(player)
         
     | 
| 
      
 37 
     | 
    
         
            +
                            puts player
         
     | 
| 
      
 38 
     | 
    
         
            +
                        end
         
     | 
| 
      
 39 
     | 
    
         
            +
                        puts
         
     | 
| 
      
 40 
     | 
    
         
            +
                    end
         
     | 
| 
      
 41 
     | 
    
         
            +
                  end
         
     | 
| 
      
 42 
     | 
    
         
            +
                  
         
     | 
| 
      
 43 
     | 
    
         
            +
                  def print_high_score(file=STDOUT)
         
     | 
| 
      
 44 
     | 
    
         
            +
                    file.puts "\n#{@title} High Scores:"
         
     | 
| 
      
 45 
     | 
    
         
            +
                    @players.sort.each do |p|
         
     | 
| 
      
 46 
     | 
    
         
            +
                        fn = p.name.ljust(20, ".")
         
     | 
| 
      
 47 
     | 
    
         
            +
                        file.puts "#{fn} #{p.score}" 
         
     | 
| 
      
 48 
     | 
    
         
            +
                    end
         
     | 
| 
      
 49 
     | 
    
         
            +
                  end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
                  def print_stats
         
     | 
| 
      
 53 
     | 
    
         
            +
                    puts "\n#{@title} Statistics:"
         
     | 
| 
      
 54 
     | 
    
         
            +
                    strongs, weaks = @players.partition { |p| p.strong? }
         
     | 
| 
      
 55 
     | 
    
         
            +
                    puts "\n#{strongs.size} strong players:"
         
     | 
| 
      
 56 
     | 
    
         
            +
                    strongs.each {|p| puts "#{p.name} (#{p.health})" }
         
     | 
| 
      
 57 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 58 
     | 
    
         
            +
                    puts "#{weaks.size} weak players:"
         
     | 
| 
      
 59 
     | 
    
         
            +
                    weaks.each {|p| puts "#{p.name} (#{p.health})" }
         
     | 
| 
      
 60 
     | 
    
         
            +
                    puts
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
                    print_high_score
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
                    @players.each do |p|
         
     | 
| 
      
 65 
     | 
    
         
            +
                        puts "\n#{p.name}'s point totals:"
         
     | 
| 
      
 66 
     | 
    
         
            +
                        p.each_found_treasure { |t| puts "#{t.points} total #{t.name} points" }
         
     | 
| 
      
 67 
     | 
    
         
            +
                        puts "#{p.points} grand total points"
         
     | 
| 
      
 68 
     | 
    
         
            +
                    end
         
     | 
| 
      
 69 
     | 
    
         
            +
                  end
         
     | 
| 
      
 70 
     | 
    
         
            +
             
     | 
| 
      
 71 
     | 
    
         
            +
                  def load_players(filename)
         
     | 
| 
      
 72 
     | 
    
         
            +
                    File.readlines(filename).each do |line| 
         
     | 
| 
      
 73 
     | 
    
         
            +
                        name, health = line.split(",")
         
     | 
| 
      
 74 
     | 
    
         
            +
                        player = Player.new(name,Integer(health))
         
     | 
| 
      
 75 
     | 
    
         
            +
                        add_player(player)
         
     | 
| 
      
 76 
     | 
    
         
            +
                    end
         
     | 
| 
      
 77 
     | 
    
         
            +
                  end
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
                  def save_high_scores(filename="high_scores.txt")
         
     | 
| 
      
 80 
     | 
    
         
            +
                    File.open(filename,"w") do |file|
         
     | 
| 
      
 81 
     | 
    
         
            +
                        print_high_score(file)
         
     | 
| 
      
 82 
     | 
    
         
            +
                    end
         
     | 
| 
      
 83 
     | 
    
         
            +
                  end
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
      
 85 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,26 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative "die"
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative "loaded_die"
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative "player"
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative "treasure_trove"
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 7 
     | 
    
         
            +
             
     | 
| 
      
 8 
     | 
    
         
            +
                module GameTurn
         
     | 
| 
      
 9 
     | 
    
         
            +
                    def self.take_turn(player)
         
     | 
| 
      
 10 
     | 
    
         
            +
                      die = Die.new
         
     | 
| 
      
 11 
     | 
    
         
            +
                      case die.roll
         
     | 
| 
      
 12 
     | 
    
         
            +
                      when 1..2
         
     | 
| 
      
 13 
     | 
    
         
            +
                        player.blam
         
     | 
| 
      
 14 
     | 
    
         
            +
                      when 3..4
         
     | 
| 
      
 15 
     | 
    
         
            +
                        puts "#{player.name} was skipped."
         
     | 
| 
      
 16 
     | 
    
         
            +
                      else
         
     | 
| 
      
 17 
     | 
    
         
            +
                        player.w00t
         
     | 
| 
      
 18 
     | 
    
         
            +
                      end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                      treasure = TreasureTrove.random
         
     | 
| 
      
 21 
     | 
    
         
            +
                      player.found_treasure(treasure)
         
     | 
| 
      
 22 
     | 
    
         
            +
                      puts "#{player.name} found a #{treasure[:name]} worth #{treasure[:points]}."
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
                    end
         
     | 
| 
      
 25 
     | 
    
         
            +
                end
         
     | 
| 
      
 26 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,58 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative("treasure_trove")
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative("playable")
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                class Player
         
     | 
| 
      
 7 
     | 
    
         
            +
                  include  Playable
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                  attr_accessor :name
         
     | 
| 
      
 10 
     | 
    
         
            +
                  attr_reader :health
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                  def initialize(name, health=100)
         
     | 
| 
      
 13 
     | 
    
         
            +
                    @name = name.capitalize
         
     | 
| 
      
 14 
     | 
    
         
            +
                    @health = health
         
     | 
| 
      
 15 
     | 
    
         
            +
                    @found_treasures = Hash.new(0);
         
     | 
| 
      
 16 
     | 
    
         
            +
                  end
         
     | 
| 
      
 17 
     | 
    
         
            +
                  
         
     | 
| 
      
 18 
     | 
    
         
            +
                  def to_s
         
     | 
| 
      
 19 
     | 
    
         
            +
                    "I'm #{@name} with a health = #{@health}, points = #{points}, and score = #{score}."
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                  def score
         
     | 
| 
      
 23 
     | 
    
         
            +
                    @health + points
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
                  
         
     | 
| 
      
 26 
     | 
    
         
            +
             
     | 
| 
      
 27 
     | 
    
         
            +
                  def <=>(other)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    other.score <=> score
         
     | 
| 
      
 29 
     | 
    
         
            +
                  end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
                  def found_treasure(treasure)
         
     | 
| 
      
 32 
     | 
    
         
            +
                    @found_treasures[treasure.name] += treasure.points
         
     | 
| 
      
 33 
     | 
    
         
            +
                    puts "#{name} found a #{treasure.name} worth #{treasure.points}."
         
     | 
| 
      
 34 
     | 
    
         
            +
                    puts "#{name}'s treasures: #{@found_treasures}"
         
     | 
| 
      
 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 
     | 
    
         
            +
                end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                if __FILE__ == $0
         
     | 
| 
      
 50 
     | 
    
         
            +
                  player = Player.new("moe")
         
     | 
| 
      
 51 
     | 
    
         
            +
                  puts player.name
         
     | 
| 
      
 52 
     | 
    
         
            +
                  puts player.health
         
     | 
| 
      
 53 
     | 
    
         
            +
                  player.w00t
         
     | 
| 
      
 54 
     | 
    
         
            +
                  puts player.health
         
     | 
| 
      
 55 
     | 
    
         
            +
                  player.blam
         
     | 
| 
      
 56 
     | 
    
         
            +
                  puts player.health
         
     | 
| 
      
 57 
     | 
    
         
            +
                end
         
     | 
| 
      
 58 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,20 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                Treasure = Struct.new(:name,:points)
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
                module TreasureTrove
         
     | 
| 
      
 7 
     | 
    
         
            +
                    TREASURES = [
         
     | 
| 
      
 8 
     | 
    
         
            +
                        Treasure.new(:pie,5),
         
     | 
| 
      
 9 
     | 
    
         
            +
                        Treasure.new(:bottle,25),
         
     | 
| 
      
 10 
     | 
    
         
            +
                        Treasure.new(:hammer,50),
         
     | 
| 
      
 11 
     | 
    
         
            +
                        Treasure.new(:skillet,100),
         
     | 
| 
      
 12 
     | 
    
         
            +
                        Treasure.new(:broomstick,200),
         
     | 
| 
      
 13 
     | 
    
         
            +
                        Treasure.new(:crowbar,400)
         
     | 
| 
      
 14 
     | 
    
         
            +
                    ]
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                    def self::random
         
     | 
| 
      
 17 
     | 
    
         
            +
                        TREASURES.sample
         
     | 
| 
      
 18 
     | 
    
         
            +
                    end
         
     | 
| 
      
 19 
     | 
    
         
            +
                end
         
     | 
| 
      
 20 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,22 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            require 'studio_game/berserk_player'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe StudioGame::BerserkPlayer do
         
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @initial_health = 50 
         
     | 
| 
      
 7 
     | 
    
         
            +
                @player = StudioGame::BerserkPlayer.new("berserker", @initial_health)
         
     | 
| 
      
 8 
     | 
    
         
            +
              end
         
     | 
| 
      
 9 
     | 
    
         
            +
              it "does not go berserk when w00ted up to 5 times" do
         
     | 
| 
      
 10 
     | 
    
         
            +
                1.upto(5) { @player.w00t }
         
     | 
| 
      
 11 
     | 
    
         
            +
                @player.berserk?.should be_false
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
              it "goes berserk when w00ted more than 5 times" do
         
     | 
| 
      
 14 
     | 
    
         
            +
                1.upto(6) { @player.w00t }
         
     | 
| 
      
 15 
     | 
    
         
            +
                @player.berserk?.should be_true
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
              it "gets w00ted instead of blammed when it's gone berserk" do  
         
     | 
| 
      
 18 
     | 
    
         
            +
                1.upto(6) { @player.w00t }
         
     | 
| 
      
 19 
     | 
    
         
            +
                1.upto(2) { @player.blam }
         
     | 
| 
      
 20 
     | 
    
         
            +
                @player.health.should == @initial_health + (8 * 15)
         
     | 
| 
      
 21 
     | 
    
         
            +
              end
         
     | 
| 
      
 22 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,32 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'studio_game/clumsy_player'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe StudioGame::ClumsyPlayer do
         
     | 
| 
      
 4 
     | 
    
         
            +
              before do
         
     | 
| 
      
 5 
     | 
    
         
            +
                @player = StudioGame::ClumsyPlayer.new("klutz")
         
     | 
| 
      
 6 
     | 
    
         
            +
              end
         
     | 
| 
      
 7 
     | 
    
         
            +
              
         
     | 
| 
      
 8 
     | 
    
         
            +
              it "only gets half the point value for each treasure" do
         
     | 
| 
      
 9 
     | 
    
         
            +
                @player.points.should == 0
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                hammer = StudioGame::Treasure.new(:hammer, 50)
         
     | 
| 
      
 12 
     | 
    
         
            +
                @player.found_treasure(hammer)
         
     | 
| 
      
 13 
     | 
    
         
            +
                @player.found_treasure(hammer)
         
     | 
| 
      
 14 
     | 
    
         
            +
                @player.found_treasure(hammer)
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                @player.points.should == 75
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                crowbar = StudioGame::Treasure.new(:crowbar, 400)
         
     | 
| 
      
 19 
     | 
    
         
            +
                @player.found_treasure(crowbar)
         
     | 
| 
      
 20 
     | 
    
         
            +
                
         
     | 
| 
      
 21 
     | 
    
         
            +
                @player.points.should == 275    
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
                yielded = []
         
     | 
| 
      
 24 
     | 
    
         
            +
                @player.each_found_treasure do |treasure|
         
     | 
| 
      
 25 
     | 
    
         
            +
                  yielded << treasure
         
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                yielded.should == [StudioGame::Treasure.new(:hammer, 75), StudioGame::Treasure.new(:crowbar, 200)]    
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            end
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
         @@ -0,0 +1,52 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'studio_game/game'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            describe StudioGame::Game do
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @game = StudioGame::Game.new("Knuckleheads")
         
     | 
| 
      
 7 
     | 
    
         
            +
                
         
     | 
| 
      
 8 
     | 
    
         
            +
                @initial_health = 100
         
     | 
| 
      
 9 
     | 
    
         
            +
                @player = StudioGame::Player.new("moe", @initial_health)
         
     | 
| 
      
 10 
     | 
    
         
            +
                
         
     | 
| 
      
 11 
     | 
    
         
            +
                @game.add_player(@player)
         
     | 
| 
      
 12 
     | 
    
         
            +
              end
         
     | 
| 
      
 13 
     | 
    
         
            +
              
         
     | 
| 
      
 14 
     | 
    
         
            +
              it "has a title" do
         
     | 
| 
      
 15 
     | 
    
         
            +
                @game.title.should == "Knuckleheads"
         
     | 
| 
      
 16 
     | 
    
         
            +
              end
         
     | 
| 
      
 17 
     | 
    
         
            +
              
         
     | 
| 
      
 18 
     | 
    
         
            +
              it "w00ts the player if a high number is rolled" do
         
     | 
| 
      
 19 
     | 
    
         
            +
                StudioGame::Die.any_instance.stub(:roll).and_return(5)
         
     | 
| 
      
 20 
     | 
    
         
            +
                    
         
     | 
| 
      
 21 
     | 
    
         
            +
                @game.play(2)
         
     | 
| 
      
 22 
     | 
    
         
            +
                
         
     | 
| 
      
 23 
     | 
    
         
            +
                @player.health.should == @initial_health + 15*2
         
     | 
| 
      
 24 
     | 
    
         
            +
              end
         
     | 
| 
      
 25 
     | 
    
         
            +
              
         
     | 
| 
      
 26 
     | 
    
         
            +
              it "skips the player if a medium number is rolled" do
         
     | 
| 
      
 27 
     | 
    
         
            +
                StudioGame::Die.any_instance.stub(:roll).and_return(3)
         
     | 
| 
      
 28 
     | 
    
         
            +
                    
         
     | 
| 
      
 29 
     | 
    
         
            +
                @game.play(2)
         
     | 
| 
      
 30 
     | 
    
         
            +
                
         
     | 
| 
      
 31 
     | 
    
         
            +
                @player.health.should == @initial_health
         
     | 
| 
      
 32 
     | 
    
         
            +
              end
         
     | 
| 
      
 33 
     | 
    
         
            +
              
         
     | 
| 
      
 34 
     | 
    
         
            +
              it "blams the player if a low number is rolled" do
         
     | 
| 
      
 35 
     | 
    
         
            +
                StudioGame::Die.any_instance.stub(:roll).and_return(1)
         
     | 
| 
      
 36 
     | 
    
         
            +
                    
         
     | 
| 
      
 37 
     | 
    
         
            +
                @game.play(2)
         
     | 
| 
      
 38 
     | 
    
         
            +
                
         
     | 
| 
      
 39 
     | 
    
         
            +
                @player.health.should == @initial_health - 10*2
         
     | 
| 
      
 40 
     | 
    
         
            +
              end
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
              it "assigns a treasure for points during a player's turn" do
         
     | 
| 
      
 43 
     | 
    
         
            +
                game = StudioGame::Game.new("Knuckleheads")
         
     | 
| 
      
 44 
     | 
    
         
            +
                player = StudioGame::Player.new("moe")
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
                game.add_player(player)
         
     | 
| 
      
 47 
     | 
    
         
            +
                game.play(1)
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
                player.points.should_not be_zero
         
     | 
| 
      
 50 
     | 
    
         
            +
              end
         
     | 
| 
      
 51 
     | 
    
         
            +
                
         
     | 
| 
      
 52 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,116 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'studio_game/player'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'studio_game/treasure_trove'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            describe StudioGame::Player do
         
     | 
| 
      
 5 
     | 
    
         
            +
             
     | 
| 
      
 6 
     | 
    
         
            +
              before do
         
     | 
| 
      
 7 
     | 
    
         
            +
                @initial_health = 150
         
     | 
| 
      
 8 
     | 
    
         
            +
                @player = StudioGame::Player.new("larry", @initial_health)
         
     | 
| 
      
 9 
     | 
    
         
            +
              end
         
     | 
| 
      
 10 
     | 
    
         
            +
              
         
     | 
| 
      
 11 
     | 
    
         
            +
              it "has a capitalized name" do
         
     | 
| 
      
 12 
     | 
    
         
            +
                @player.name.should == "Larry"
         
     | 
| 
      
 13 
     | 
    
         
            +
              end
         
     | 
| 
      
 14 
     | 
    
         
            +
              
         
     | 
| 
      
 15 
     | 
    
         
            +
              it "has an initial health" do  
         
     | 
| 
      
 16 
     | 
    
         
            +
                @player.health.should == 150
         
     | 
| 
      
 17 
     | 
    
         
            +
              end
         
     | 
| 
      
 18 
     | 
    
         
            +
              
         
     | 
| 
      
 19 
     | 
    
         
            +
              it "increases health by 15 when w00ted" do
         
     | 
| 
      
 20 
     | 
    
         
            +
                @player.w00t
         
     | 
| 
      
 21 
     | 
    
         
            +
                
         
     | 
| 
      
 22 
     | 
    
         
            +
                @player.health.should == @initial_health + 15
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              it "decreases health by 10 when blammed" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                @player.blam
         
     | 
| 
      
 27 
     | 
    
         
            +
                
         
     | 
| 
      
 28 
     | 
    
         
            +
                @player.health.should == @initial_health - 10
         
     | 
| 
      
 29 
     | 
    
         
            +
              end
         
     | 
| 
      
 30 
     | 
    
         
            +
              
         
     | 
| 
      
 31 
     | 
    
         
            +
              context "created with a default health" do
         
     | 
| 
      
 32 
     | 
    
         
            +
                before do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  @player = StudioGame::Player.new("larry")
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
                
         
     | 
| 
      
 36 
     | 
    
         
            +
                it "has a health of 100" do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  @player.health.should == 100
         
     | 
| 
      
 38 
     | 
    
         
            +
                end
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
              
         
     | 
| 
      
 41 
     | 
    
         
            +
              context "with a health greater than 100" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                before do
         
     | 
| 
      
 43 
     | 
    
         
            +
                  @player = StudioGame::Player.new("larry", 150)
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
              
         
     | 
| 
      
 46 
     | 
    
         
            +
                it "is strong" do
         
     | 
| 
      
 47 
     | 
    
         
            +
                  @player.should be_strong
         
     | 
| 
      
 48 
     | 
    
         
            +
                end
         
     | 
| 
      
 49 
     | 
    
         
            +
              end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
              context "with a health of 100 or less" do
         
     | 
| 
      
 52 
     | 
    
         
            +
                before do
         
     | 
| 
      
 53 
     | 
    
         
            +
                  @player = StudioGame::Player.new("larry", 100)
         
     | 
| 
      
 54 
     | 
    
         
            +
                end
         
     | 
| 
      
 55 
     | 
    
         
            +
              
         
     | 
| 
      
 56 
     | 
    
         
            +
                it "is wimpy" do
         
     | 
| 
      
 57 
     | 
    
         
            +
                  @player.should_not be_strong
         
     | 
| 
      
 58 
     | 
    
         
            +
                end
         
     | 
| 
      
 59 
     | 
    
         
            +
              end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
              context "in a collection of players"do
         
     | 
| 
      
 62 
     | 
    
         
            +
                before do
         
     | 
| 
      
 63 
     | 
    
         
            +
                    @player1 = StudioGame::Player.new("moe", 100)
         
     | 
| 
      
 64 
     | 
    
         
            +
                    @player2 = StudioGame::Player.new("larry", 200)
         
     | 
| 
      
 65 
     | 
    
         
            +
                    @player3 = StudioGame::Player.new("curly", 300)
         
     | 
| 
      
 66 
     | 
    
         
            +
                    @players = [@player1, @player2, @player3]
         
     | 
| 
      
 67 
     | 
    
         
            +
                end
         
     | 
| 
      
 68 
     | 
    
         
            +
                it "is sorted by decreasing score" do
         
     | 
| 
      
 69 
     | 
    
         
            +
                    @players.sort.should == [@player3, @player2, @player1]
         
     | 
| 
      
 70 
     | 
    
         
            +
                end
         
     | 
| 
      
 71 
     | 
    
         
            +
              end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
              it "computes points as the sum of all treasure points" do
         
     | 
| 
      
 74 
     | 
    
         
            +
                @player.points.should == 0
         
     | 
| 
      
 75 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer,50))
         
     | 
| 
      
 76 
     | 
    
         
            +
                @player.points.should == 50
         
     | 
| 
      
 77 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:crowbar,400))
         
     | 
| 
      
 78 
     | 
    
         
            +
                @player.points.should == 450
         
     | 
| 
      
 79 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer,50))
         
     | 
| 
      
 80 
     | 
    
         
            +
                @player.points.should == 500
         
     | 
| 
      
 81 
     | 
    
         
            +
              end
         
     | 
| 
      
 82 
     | 
    
         
            +
             
     | 
| 
      
 83 
     | 
    
         
            +
              it "computes a score as the sum of its health and points" do
         
     | 
| 
      
 84 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer,50))
         
     | 
| 
      
 85 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer,50))
         
     | 
| 
      
 86 
     | 
    
         
            +
                @player.score.should == 250
         
     | 
| 
      
 87 
     | 
    
         
            +
              end
         
     | 
| 
      
 88 
     | 
    
         
            +
             
     | 
| 
      
 89 
     | 
    
         
            +
              it "has a string representation" do
         
     | 
| 
      
 90 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
         
     | 
| 
      
 91 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
         
     | 
| 
      
 92 
     | 
    
         
            +
                @player.to_s.should == "I'm Larry with a health = 150, points = 100, and score = 250."
         
     | 
| 
      
 93 
     | 
    
         
            +
              end
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
              it "yields each found treasure and its total points" do
         
     | 
| 
      
 96 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:skillet,100))
         
     | 
| 
      
 97 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:skillet,100))
         
     | 
| 
      
 98 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:hammer,50))
         
     | 
| 
      
 99 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:bottle,5))
         
     | 
| 
      
 100 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:bottle,5))
         
     | 
| 
      
 101 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:bottle,5))
         
     | 
| 
      
 102 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:bottle,5))
         
     | 
| 
      
 103 
     | 
    
         
            +
                @player.found_treasure(StudioGame::Treasure.new(:bottle,5))
         
     | 
| 
      
 104 
     | 
    
         
            +
                yielded = []
         
     | 
| 
      
 105 
     | 
    
         
            +
                @player.each_found_treasure do |treasure|
         
     | 
| 
      
 106 
     | 
    
         
            +
                    yielded << treasure
         
     | 
| 
      
 107 
     | 
    
         
            +
                end
         
     | 
| 
      
 108 
     | 
    
         
            +
                yielded.should == [
         
     | 
| 
      
 109 
     | 
    
         
            +
                    StudioGame::Treasure.new(:skillet,200),
         
     | 
| 
      
 110 
     | 
    
         
            +
                    StudioGame::Treasure.new(:hammer,50),
         
     | 
| 
      
 111 
     | 
    
         
            +
                    StudioGame::Treasure.new(:bottle,25)
         
     | 
| 
      
 112 
     | 
    
         
            +
                ]
         
     | 
| 
      
 113 
     | 
    
         
            +
              end
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,50 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'studio_game/treasure_trove'
         
     | 
| 
      
 2 
     | 
    
         
            +
               
         
     | 
| 
      
 3 
     | 
    
         
            +
            describe StudioGame::Treasure do
         
     | 
| 
      
 4 
     | 
    
         
            +
              
         
     | 
| 
      
 5 
     | 
    
         
            +
              before do
         
     | 
| 
      
 6 
     | 
    
         
            +
                @treasure = StudioGame::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 
     | 
    
         
            +
              
         
     | 
| 
      
 17 
     | 
    
         
            +
            end
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
            describe StudioGame::TreasureTrove do
         
     | 
| 
      
 20 
     | 
    
         
            +
              
         
     | 
| 
      
 21 
     | 
    
         
            +
              it "has six treasures" do
         
     | 
| 
      
 22 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES.size.should == 6
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
              
         
     | 
| 
      
 25 
     | 
    
         
            +
              it "has a pie worth 5 points" do
         
     | 
| 
      
 26 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES[0].should == StudioGame::Treasure.new(:pie, 5)
         
     | 
| 
      
 27 
     | 
    
         
            +
              end
         
     | 
| 
      
 28 
     | 
    
         
            +
              
         
     | 
| 
      
 29 
     | 
    
         
            +
              it "has a bottle worth 25 points" do
         
     | 
| 
      
 30 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES[1].should == StudioGame::Treasure.new(:bottle, 25)
         
     | 
| 
      
 31 
     | 
    
         
            +
              end
         
     | 
| 
      
 32 
     | 
    
         
            +
              
         
     | 
| 
      
 33 
     | 
    
         
            +
              it "has a hammer worth 50 points" do
         
     | 
| 
      
 34 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES[2].should == StudioGame::Treasure.new(:hammer, 50)
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
      
 36 
     | 
    
         
            +
              
         
     | 
| 
      
 37 
     | 
    
         
            +
              it "has a skillet worth 100 points" do
         
     | 
| 
      
 38 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES[3].should == StudioGame::Treasure.new(:skillet, 100)
         
     | 
| 
      
 39 
     | 
    
         
            +
              end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              it "has a broomstick worth 200 points" do
         
     | 
| 
      
 42 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES[4].should == StudioGame::Treasure.new(:broomstick, 200)
         
     | 
| 
      
 43 
     | 
    
         
            +
              end
         
     | 
| 
      
 44 
     | 
    
         
            +
              
         
     | 
| 
      
 45 
     | 
    
         
            +
              it "has a crowbar worth 400 points" do
         
     | 
| 
      
 46 
     | 
    
         
            +
                StudioGame::TreasureTrove::TREASURES[5].should == StudioGame::Treasure.new(:crowbar, 400)
         
     | 
| 
      
 47 
     | 
    
         
            +
              end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            end
         
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,87 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: StudioGame
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version
         
     | 
| 
      
 4 
     | 
    
         
            +
              version: 1.0.0
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: 
         
     | 
| 
      
 6 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 7 
     | 
    
         
            +
            authors:
         
     | 
| 
      
 8 
     | 
    
         
            +
            - Robert Warner Walsh, Jr.
         
     | 
| 
      
 9 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 10 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 11 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 12 
     | 
    
         
            +
            date: 2013-06-09 00:00:00.000000000 Z
         
     | 
| 
      
 13 
     | 
    
         
            +
            dependencies:
         
     | 
| 
      
 14 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency
         
     | 
| 
      
 15 
     | 
    
         
            +
              name: rspec
         
     | 
| 
      
 16 
     | 
    
         
            +
              requirement: !ruby/object:Gem::Requirement
         
     | 
| 
      
 17 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 18 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 19 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 20 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 21 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 22 
     | 
    
         
            +
              type: :development
         
     | 
| 
      
 23 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 24 
     | 
    
         
            +
              version_requirements: !ruby/object:Gem::Requirement
         
     | 
| 
      
 25 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 26 
     | 
    
         
            +
                requirements:
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ! '>='
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version
         
     | 
| 
      
 29 
     | 
    
         
            +
                    version: '0'
         
     | 
| 
      
 30 
     | 
    
         
            +
            description: ! 'Example gemset from Pragmatic Studio.
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
            '
         
     | 
| 
      
 33 
     | 
    
         
            +
            email: robert.warner.walsh+studiogame@gmail.com
         
     | 
| 
      
 34 
     | 
    
         
            +
            executables:
         
     | 
| 
      
 35 
     | 
    
         
            +
            - studio_game
         
     | 
| 
      
 36 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 37 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 38 
     | 
    
         
            +
            files:
         
     | 
| 
      
 39 
     | 
    
         
            +
            - bin/studio_game
         
     | 
| 
      
 40 
     | 
    
         
            +
            - bin/players.csv
         
     | 
| 
      
 41 
     | 
    
         
            +
            - lib/studio_game/game.rb
         
     | 
| 
      
 42 
     | 
    
         
            +
            - lib/studio_game/playable.rb
         
     | 
| 
      
 43 
     | 
    
         
            +
            - lib/studio_game/auditable.rb
         
     | 
| 
      
 44 
     | 
    
         
            +
            - lib/studio_game/die.rb
         
     | 
| 
      
 45 
     | 
    
         
            +
            - lib/studio_game/clumsy_player.rb
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/studio_game/loaded_die.rb
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib/studio_game/player.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
            - lib/studio_game/berserk_player.rb
         
     | 
| 
      
 49 
     | 
    
         
            +
            - lib/studio_game/treasure_trove.rb
         
     | 
| 
      
 50 
     | 
    
         
            +
            - lib/studio_game/game_turn.rb
         
     | 
| 
      
 51 
     | 
    
         
            +
            - spec/studio_game/beserk_player_spec.rb
         
     | 
| 
      
 52 
     | 
    
         
            +
            - spec/studio_game/clumsy_player_spec.rb
         
     | 
| 
      
 53 
     | 
    
         
            +
            - spec/studio_game/treasure_trove_spec.rb
         
     | 
| 
      
 54 
     | 
    
         
            +
            - spec/studio_game/player_spec.rb
         
     | 
| 
      
 55 
     | 
    
         
            +
            - spec/studio_game/game_spec.rb
         
     | 
| 
      
 56 
     | 
    
         
            +
            - LICENSE
         
     | 
| 
      
 57 
     | 
    
         
            +
            - README
         
     | 
| 
      
 58 
     | 
    
         
            +
            homepage: http://robertwalsh.net
         
     | 
| 
      
 59 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 60 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 61 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 62 
     | 
    
         
            +
            require_paths:
         
     | 
| 
      
 63 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 64 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 65 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 66 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 67 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 68 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 69 
     | 
    
         
            +
                  version: '1.9'
         
     | 
| 
      
 70 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement
         
     | 
| 
      
 71 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 72 
     | 
    
         
            +
              requirements:
         
     | 
| 
      
 73 
     | 
    
         
            +
              - - ! '>='
         
     | 
| 
      
 74 
     | 
    
         
            +
                - !ruby/object:Gem::Version
         
     | 
| 
      
 75 
     | 
    
         
            +
                  version: '0'
         
     | 
| 
      
 76 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 77 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 78 
     | 
    
         
            +
            rubygems_version: 1.8.24
         
     | 
| 
      
 79 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 80 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 81 
     | 
    
         
            +
            summary: Example game from Pragmatic Studio
         
     | 
| 
      
 82 
     | 
    
         
            +
            test_files:
         
     | 
| 
      
 83 
     | 
    
         
            +
            - spec/studio_game/beserk_player_spec.rb
         
     | 
| 
      
 84 
     | 
    
         
            +
            - spec/studio_game/clumsy_player_spec.rb
         
     | 
| 
      
 85 
     | 
    
         
            +
            - spec/studio_game/treasure_trove_spec.rb
         
     | 
| 
      
 86 
     | 
    
         
            +
            - spec/studio_game/player_spec.rb
         
     | 
| 
      
 87 
     | 
    
         
            +
            - spec/studio_game/game_spec.rb
         
     |