studio_game_2021 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 +7 -0
 - data/LICENSE +7 -0
 - data/README +136 -0
 - data/bin/avatar_players.csv +7 -0
 - data/bin/players.csv +6 -0
 - data/bin/studio_game +29 -0
 - data/lib/studio_game/auditable.rb +7 -0
 - data/lib/studio_game/berserk_player.rb +33 -0
 - data/lib/studio_game/clumsy_player.rb +27 -0
 - data/lib/studio_game/die.rb +24 -0
 - data/lib/studio_game/formatting.rb +11 -0
 - data/lib/studio_game/game.rb +63 -0
 - data/lib/studio_game/game_stats.rb +47 -0
 - data/lib/studio_game/game_turn.rb +23 -0
 - data/lib/studio_game/handle_csv.rb +19 -0
 - data/lib/studio_game/loaded_die.rb +17 -0
 - data/lib/studio_game/playable.rb +19 -0
 - data/lib/studio_game/player.rb +72 -0
 - data/lib/studio_game/printable.rb +44 -0
 - data/lib/studio_game/treasure.rb +16 -0
 - data/lib/studio_game/treasure_trove.rb +25 -0
 - data/spec/studio_game/berserk_player_spec.rb +32 -0
 - data/spec/studio_game/clumsy_player_spec.rb +33 -0
 - data/spec/studio_game/game_spec.rb +168 -0
 - data/spec/studio_game/player_spec.rb +165 -0
 - data/spec/studio_game/treasure_spec.rb +28 -0
 - data/spec/studio_game/treasure_trove_spec.rb +44 -0
 - metadata +231 -0
 
    
        checksums.yaml
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            ---
         
     | 
| 
      
 2 
     | 
    
         
            +
            SHA256:
         
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: 818452ec448a8fa2b9e3b038a0f0d31dce944323eda4d0b8f0db1c3f60abd8d3
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: ab618b24bea3a53049418104a82a032b2200fc2b68db9ad3fd51ee0b79a78e2a
         
     | 
| 
      
 5 
     | 
    
         
            +
            SHA512:
         
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: ee98d43574e61ad0a19c2f72dba44e7cbc53e70e7fb0db6b407927bbb479c396a7f6543daab0b8c9e65ffde76fd98cd8bbd7a4f4c2453434bca569b6ee8722b7
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: 32d007d8d9b8cfb66b58251ce4ec9626075cb8e45143aca251ffdc3be6ae010a4ddad6cc7d1a50f48b4c3df3c841f02da0bfdff0e37a2057a0fb0c74cb0c2e40
         
     | 
    
        data/LICENSE
    ADDED
    
    | 
         @@ -0,0 +1,7 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            Copyright 2021 Becca Williams (Essentialist Dev)
         
     | 
| 
      
 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.
         
     | 
    
        data/README
    ADDED
    
    | 
         @@ -0,0 +1,136 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
             
     | 
| 
      
 2 
     | 
    
         
            +
            <!-- TABLE OF CONTENTS -->
         
     | 
| 
      
 3 
     | 
    
         
            +
            <details open="open">
         
     | 
| 
      
 4 
     | 
    
         
            +
            <summary>Table of Contents</summary>
         
     | 
| 
      
 5 
     | 
    
         
            +
            <ol>
         
     | 
| 
      
 6 
     | 
    
         
            +
            <li>
         
     | 
| 
      
 7 
     | 
    
         
            +
            <a href="#about-the-project">About The Project</a>
         
     | 
| 
      
 8 
     | 
    
         
            +
            <ul>
         
     | 
| 
      
 9 
     | 
    
         
            +
            <li><a href="#built-with">Built With</a></li>
         
     | 
| 
      
 10 
     | 
    
         
            +
            </ul>
         
     | 
| 
      
 11 
     | 
    
         
            +
            </li>
         
     | 
| 
      
 12 
     | 
    
         
            +
            <li>
         
     | 
| 
      
 13 
     | 
    
         
            +
            <a href="#getting-started">Getting Started</a>
         
     | 
| 
      
 14 
     | 
    
         
            +
            <ul>
         
     | 
| 
      
 15 
     | 
    
         
            +
            <li><a href="#prerequisites">Prerequisites</a></li>
         
     | 
| 
      
 16 
     | 
    
         
            +
            <li><a href="#installation">Installation</a></li>
         
     | 
| 
      
 17 
     | 
    
         
            +
            </ul>
         
     | 
| 
      
 18 
     | 
    
         
            +
            </li>
         
     | 
| 
      
 19 
     | 
    
         
            +
            <li><a href="#usage">Usage</a></li>
         
     | 
| 
      
 20 
     | 
    
         
            +
            <li><a href="#roadmap">Roadmap</a></li>
         
     | 
| 
      
 21 
     | 
    
         
            +
            <li><a href="#contributing">Contributing</a></li>
         
     | 
| 
      
 22 
     | 
    
         
            +
            <li><a href="#license">License</a></li>
         
     | 
| 
      
 23 
     | 
    
         
            +
            <li><a href="#contact">Contact</a></li>
         
     | 
| 
      
 24 
     | 
    
         
            +
            <li><a href="#acknowledgements">Acknowledgements</a></li>
         
     | 
| 
      
 25 
     | 
    
         
            +
            </ol>
         
     | 
| 
      
 26 
     | 
    
         
            +
            </details>
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
            <!-- ABOUT THE PROJECT -->
         
     | 
| 
      
 29 
     | 
    
         
            +
            ## About The Project
         
     | 
| 
      
 30 
     | 
    
         
            +
             
     | 
| 
      
 31 
     | 
    
         
            +
            [![Product Name Screen Shot][Screenshot of gameplay and test list]](https://www.dropbox.com/s/mu1rrbx2mqowjkn/studio-game.png?dl=0)
         
     | 
| 
      
 32 
     | 
    
         
            +
             
     | 
| 
      
 33 
     | 
    
         
            +
            This game is a project built following the [Pragmatic Studio Ruby Course](https://online.pragmaticstudio.com/courses/ruby/). I absolutely adored going through this course, because it was unlike other courses in that the main focus wasn't syntax, but how to build a principle-driven, object-oriented program that contains many of the skills we'd need to build real-world projects. The instructors purposefully created exercises to let us build a program using the skills they demonstrated by building a different program. This wasn't a copy and paste kind of course. This game was actually my second run-through, where I test-drove everything from the start based on the objectives only.
         
     | 
| 
      
 34 
     | 
    
         
            +
             
     | 
| 
      
 35 
     | 
    
         
            +
            Skills I valued developing further with this project:
         
     | 
| 
      
 36 
     | 
    
         
            +
            - Test-driven development (50+ tests).
         
     | 
| 
      
 37 
     | 
    
         
            +
            - Using inheritance to model "is-a" relationships. For example, a clumsy player *is a* kind of player.
         
     | 
| 
      
 38 
     | 
    
         
            +
            - Using mixins (modules) to reuse behaviours that are common between classes, but should not be modeled with an inheritance relationship. A good tip was to look for 'able' behaviors in a class to extract, like 'playable', 'printable', 'taxable' etc.
         
     | 
| 
      
 39 
     | 
    
         
            +
            - Using a file block which lets you add in class usage examples that are only run when you run the class file specifically.
         
     | 
| 
      
 40 
     | 
    
         
            +
            - Overriding default methods (like sort, and renaming things so that they keep a specific format)
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
      
 42 
     | 
    
         
            +
            Things I struggled with:
         
     | 
| 
      
 43 
     | 
    
         
            +
            - Testing behaviour that uses blocks. I had a lightbulb moment when I realised I should test the behaviour performed inside the block on a single item. Testing the output of an entire block is like testing Ruby syntax works. Alternatively, test the before and after state of something that changes as a result of using a block. Cooool.
         
     | 
| 
      
 44 
     | 
    
         
            +
            - Puts. It felt wrong to use puts to show the output in the console. I'd like to learn how to seperate the view logic for a command-line project later.
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
            Things I did to make it my own:
         
     | 
| 
      
 47 
     | 
    
         
            +
            - Wrote a lot more tests for my second run-through.
         
     | 
| 
      
 48 
     | 
    
         
            +
            - Noticed and extracted further 'able' behaviours into modules (like printing stats, formatting output and handling csv files).
         
     | 
| 
      
 49 
     | 
    
         
            +
             
     | 
| 
      
 50 
     | 
    
         
            +
             
     | 
| 
      
 51 
     | 
    
         
            +
            ### Built With
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
            * [Ruby (language)](https://www.ruby-lang.org/en/)
         
     | 
| 
      
 54 
     | 
    
         
            +
            * [RSpec (framework)](https://rspec.info/)
         
     | 
| 
      
 55 
     | 
    
         
            +
            * [Vim (text-editor)](https://www.vim.org/)
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
             
     | 
| 
      
 59 
     | 
    
         
            +
            <!-- GETTING STARTED -->
         
     | 
| 
      
 60 
     | 
    
         
            +
            ## Getting Started
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
            To get a local copy up and running follow these steps:
         
     | 
| 
      
 63 
     | 
    
         
            +
             
     | 
| 
      
 64 
     | 
    
         
            +
            ### Prerequisites
         
     | 
| 
      
 65 
     | 
    
         
            +
             
     | 
| 
      
 66 
     | 
    
         
            +
            This is an example of how to list things you need to use the software and how to install them.
         
     | 
| 
      
 67 
     | 
    
         
            +
            * gem
         
     | 
| 
      
 68 
     | 
    
         
            +
            ```sh
         
     | 
| 
      
 69 
     | 
    
         
            +
            npm install npm@latest -g
         
     | 
| 
      
 70 
     | 
    
         
            +
            ```
         
     | 
| 
      
 71 
     | 
    
         
            +
             
     | 
| 
      
 72 
     | 
    
         
            +
            ### Installation
         
     | 
| 
      
 73 
     | 
    
         
            +
             
     | 
| 
      
 74 
     | 
    
         
            +
            1. Install the gem
         
     | 
| 
      
 75 
     | 
    
         
            +
            ```sh
         
     | 
| 
      
 76 
     | 
    
         
            +
            gem install studio_game_2021
         
     | 
| 
      
 77 
     | 
    
         
            +
            ```
         
     | 
| 
      
 78 
     | 
    
         
            +
             
     | 
| 
      
 79 
     | 
    
         
            +
            <!-- USAGE EXAMPLES -->
         
     | 
| 
      
 80 
     | 
    
         
            +
            ## Usage
         
     | 
| 
      
 81 
     | 
    
         
            +
            To play a game from the command-line, open a new command project and run the command-line script like so:
         
     | 
| 
      
 82 
     | 
    
         
            +
            ```sh
         
     | 
| 
      
 83 
     | 
    
         
            +
            studio_game
         
     | 
| 
      
 84 
     | 
    
         
            +
            ```
         
     | 
| 
      
 85 
     | 
    
         
            +
             
     | 
| 
      
 86 
     | 
    
         
            +
            Or, if you'd like to use the game as a library, here's an example of how to use it in `irb`. You can also check the bottom of each class or module file for further usage instructions
         
     | 
| 
      
 87 
     | 
    
         
            +
             
     | 
| 
      
 88 
     | 
    
         
            +
            ```
         
     | 
| 
      
 89 
     | 
    
         
            +
            >> require 'studio_game/game'
         
     | 
| 
      
 90 
     | 
    
         
            +
            => true
         
     | 
| 
      
 91 
     | 
    
         
            +
             
     | 
| 
      
 92 
     | 
    
         
            +
            >> game = StudioGame::Game.new("Knuckleheads")
         
     | 
| 
      
 93 
     | 
    
         
            +
            => #<StudioGame::Game:0x007fdea10252d8 @title="Knuckleheads", @players=[]>
         
     | 
| 
      
 94 
     | 
    
         
            +
             
     | 
| 
      
 95 
     | 
    
         
            +
            >> player = StudioGame::Player.new("Moe", 90)
         
     | 
| 
      
 96 
     | 
    
         
            +
            => I'm Moe with health = 90, points = 0, and score = 90.
         
     | 
| 
      
 97 
     | 
    
         
            +
             
     | 
| 
      
 98 
     | 
    
         
            +
            >> game.add_player(player)
         
     | 
| 
      
 99 
     | 
    
         
            +
            => [I'm Moe with health = 90, points = 0, and score = 90.]
         
     | 
| 
      
 100 
     | 
    
         
            +
             
     | 
| 
      
 101 
     | 
    
         
            +
            >> game.play(1)
         
     | 
| 
      
 102 
     | 
    
         
            +
            ```
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
             
     | 
| 
      
 105 
     | 
    
         
            +
            <!-- ROADMAP -->
         
     | 
| 
      
 106 
     | 
    
         
            +
            ## Roadmap
         
     | 
| 
      
 107 
     | 
    
         
            +
             
     | 
| 
      
 108 
     | 
    
         
            +
            I plan to customize this game further now that I have a solid foundation to explore from. It'll be fun to let the players interact with each other more, like swapping treasures, and maybe add some kind of board game with it's own features. That's my next focus.
         
     | 
| 
      
 109 
     | 
    
         
            +
             
     | 
| 
      
 110 
     | 
    
         
            +
             
     | 
| 
      
 111 
     | 
    
         
            +
            ## Contributing
         
     | 
| 
      
 112 
     | 
    
         
            +
             
     | 
| 
      
 113 
     | 
    
         
            +
            Feel free to fork this project and play around with it. Open to feedback-related pr requests.
         
     | 
| 
      
 114 
     | 
    
         
            +
             
     | 
| 
      
 115 
     | 
    
         
            +
             
     | 
| 
      
 116 
     | 
    
         
            +
              <!-- LICENSE -->
         
     | 
| 
      
 117 
     | 
    
         
            +
            ## License
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
              Distributed under the MIT License. See `LICENSE` for more information.
         
     | 
| 
      
 120 
     | 
    
         
            +
             
     | 
| 
      
 121 
     | 
    
         
            +
             
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
              <!-- CONTACT -->
         
     | 
| 
      
 124 
     | 
    
         
            +
            ## Contact
         
     | 
| 
      
 125 
     | 
    
         
            +
             
     | 
| 
      
 126 
     | 
    
         
            +
              Becca - [@becca9941](https://twitter.com/Becca9941) - becca@essentialistdev.com
         
     | 
| 
      
 127 
     | 
    
         
            +
             
     | 
| 
      
 128 
     | 
    
         
            +
              Project Link: [https://gitlab.com/EssentialistDev/studio-game](https://gitlab.com/EssentialistDev/studio-game)
         
     | 
| 
      
 129 
     | 
    
         
            +
             
     | 
| 
      
 130 
     | 
    
         
            +
             
     | 
| 
      
 131 
     | 
    
         
            +
             
     | 
| 
      
 132 
     | 
    
         
            +
              <!-- ACKNOWLEDGEMENTS -->
         
     | 
| 
      
 133 
     | 
    
         
            +
            ## Acknowledgements
         
     | 
| 
      
 134 
     | 
    
         
            +
             
     | 
| 
      
 135 
     | 
    
         
            +
            - [Pragmatic Studio](https://online.pragmaticstudio.com/courses/ruby/) for empowering me with awesome new development skills.
         
     | 
| 
      
 136 
     | 
    
         
            +
            - [Best-README-Template](https://github.com/Becca9941/Best-README-Template) for helping me write a README for this project.
         
     | 
    
        data/bin/players.csv
    ADDED
    
    
    
        data/bin/studio_game
    ADDED
    
    | 
         @@ -0,0 +1,29 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            #!/usr/bin/env ruby
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative '../lib/studio_game/game'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative '../lib/studio_game/clumsy_player'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative '../lib/studio_game/berserk_player'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            default_player_file = File.join(File.dirname(__FILE__), "players.csv")
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            studio_game = StudioGame::Game.new("studio_game")
         
     | 
| 
      
 10 
     | 
    
         
            +
            studio_game.load_players(ARGV.shift || default_player_file)
         
     | 
| 
      
 11 
     | 
    
         
            +
            studio_game.add_player(StudioGame::ClumsyPlayer.new("klutz"))
         
     | 
| 
      
 12 
     | 
    
         
            +
            studio_game.add_player(StudioGame::BerserkPlayer.new("berserker"))
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            loop do
         
     | 
| 
      
 15 
     | 
    
         
            +
              puts "\nHow many rounds to play? ('quit' to exit)"
         
     | 
| 
      
 16 
     | 
    
         
            +
             
     | 
| 
      
 17 
     | 
    
         
            +
              answer = gets.chomp.downcase
         
     | 
| 
      
 18 
     | 
    
         
            +
             
     | 
| 
      
 19 
     | 
    
         
            +
              case answer
         
     | 
| 
      
 20 
     | 
    
         
            +
              when /^\d+$/
         
     | 
| 
      
 21 
     | 
    
         
            +
                studio_game.play(answer.to_i)
         
     | 
| 
      
 22 
     | 
    
         
            +
              when 'quit', 'q', 'exit', 'e'
         
     | 
| 
      
 23 
     | 
    
         
            +
                studio_game.print_stats
         
     | 
| 
      
 24 
     | 
    
         
            +
                studio_game.save_high_scores
         
     | 
| 
      
 25 
     | 
    
         
            +
                break
         
     | 
| 
      
 26 
     | 
    
         
            +
              else
         
     | 
| 
      
 27 
     | 
    
         
            +
                "Please enter a number or 'quit'"
         
     | 
| 
      
 28 
     | 
    
         
            +
              end
         
     | 
| 
      
 29 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,33 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'player'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 4 
     | 
    
         
            +
              class BerserkPlayer < Player
         
     | 
| 
      
 5 
     | 
    
         
            +
                def initialize(name, health = 100)
         
     | 
| 
      
 6 
     | 
    
         
            +
                  super(name, health)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  @w00t_count = 0
         
     | 
| 
      
 8 
     | 
    
         
            +
                end
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                def berserk?
         
     | 
| 
      
 11 
     | 
    
         
            +
                  @w00t_count > 5
         
     | 
| 
      
 12 
     | 
    
         
            +
                end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                def w00t
         
     | 
| 
      
 15 
     | 
    
         
            +
                  super
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @w00t_count += 1
         
     | 
| 
      
 17 
     | 
    
         
            +
                  puts "#{@name} is berserk!" if berserk?
         
     | 
| 
      
 18 
     | 
    
         
            +
                end
         
     | 
| 
      
 19 
     | 
    
         
            +
             
     | 
| 
      
 20 
     | 
    
         
            +
                def blam
         
     | 
| 
      
 21 
     | 
    
         
            +
                  berserk? ? w00t : super
         
     | 
| 
      
 22 
     | 
    
         
            +
                end
         
     | 
| 
      
 23 
     | 
    
         
            +
              end
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
            if __FILE__==$0
         
     | 
| 
      
 27 
     | 
    
         
            +
              berserker = BerserkPlayer.new("berserker", 100)
         
     | 
| 
      
 28 
     | 
    
         
            +
             
     | 
| 
      
 29 
     | 
    
         
            +
              6.times { berserker.w00t }
         
     | 
| 
      
 30 
     | 
    
         
            +
              2.times { berserker.blam }
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
              puts berserker.health
         
     | 
| 
      
 33 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,27 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'player'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'treasure_trove'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 5 
     | 
    
         
            +
              class ClumsyPlayer < Player
         
     | 
| 
      
 6 
     | 
    
         
            +
                def find_treasure(treasure = TreasureTrove.random_treasure)
         
     | 
| 
      
 7 
     | 
    
         
            +
                  damaged_treasure = Treasure.new(treasure.name, treasure.points / 2)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  super(damaged_treasure)
         
     | 
| 
      
 9 
     | 
    
         
            +
                end
         
     | 
| 
      
 10 
     | 
    
         
            +
              end
         
     | 
| 
      
 11 
     | 
    
         
            +
            end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
            if __FILE__ == $0
         
     | 
| 
      
 14 
     | 
    
         
            +
              clumsy = ClumsyPlayer.new("klutz")
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              hammer = Treasure.new("hammer", 100)
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
              puts clumsy.find_treasure(hammer)
         
     | 
| 
      
 19 
     | 
    
         
            +
              puts clumsy.find_treasure(hammer)
         
     | 
| 
      
 20 
     | 
    
         
            +
              puts clumsy.find_treasure(hammer)
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
              crowbar = Treasure.new("crowbar", 400)
         
     | 
| 
      
 23 
     | 
    
         
            +
             
     | 
| 
      
 24 
     | 
    
         
            +
              puts clumsy.find_treasure(crowbar)
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              puts clumsy.found_treasures
         
     | 
| 
      
 27 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,24 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'auditable'
         
     | 
| 
      
 2 
     | 
    
         
            +
             
     | 
| 
      
 3 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 4 
     | 
    
         
            +
              class Die
         
     | 
| 
      
 5 
     | 
    
         
            +
                include Auditable
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                attr_reader :number
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
                def initialize
         
     | 
| 
      
 10 
     | 
    
         
            +
                  roll
         
     | 
| 
      
 11 
     | 
    
         
            +
                end
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                def roll
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @number = rand(1..6)
         
     | 
| 
      
 15 
     | 
    
         
            +
                  audit
         
     | 
| 
      
 16 
     | 
    
         
            +
                  @number
         
     | 
| 
      
 17 
     | 
    
         
            +
                end
         
     | 
| 
      
 18 
     | 
    
         
            +
              end
         
     | 
| 
      
 19 
     | 
    
         
            +
            end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
            if __FILE__==$0
         
     | 
| 
      
 22 
     | 
    
         
            +
              die = Die.new
         
     | 
| 
      
 23 
     | 
    
         
            +
              die.number
         
     | 
| 
      
 24 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,63 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'player'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'game_turn'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'treasure_trove'
         
     | 
| 
      
 4 
     | 
    
         
            +
            require_relative 'formatting'
         
     | 
| 
      
 5 
     | 
    
         
            +
            require_relative 'handle_csv'
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 8 
     | 
    
         
            +
              class Game
         
     | 
| 
      
 9 
     | 
    
         
            +
                include Printable
         
     | 
| 
      
 10 
     | 
    
         
            +
                include HandleCSV
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                attr_reader :title, :players
         
     | 
| 
      
 13 
     | 
    
         
            +
                def initialize(title = "Game", players = [])
         
     | 
| 
      
 14 
     | 
    
         
            +
                  @title = title.capitalize
         
     | 
| 
      
 15 
     | 
    
         
            +
                  @players = players
         
     | 
| 
      
 16 
     | 
    
         
            +
                end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                def title=(new_title)
         
     | 
| 
      
 19 
     | 
    
         
            +
                  @title = new_title.capitalize
         
     | 
| 
      
 20 
     | 
    
         
            +
                end
         
     | 
| 
      
 21 
     | 
    
         
            +
             
     | 
| 
      
 22 
     | 
    
         
            +
                def add_player(player)
         
     | 
| 
      
 23 
     | 
    
         
            +
                  @players << player
         
     | 
| 
      
 24 
     | 
    
         
            +
                end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                def remove_player(player)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  @players.delete(player)
         
     | 
| 
      
 28 
     | 
    
         
            +
                end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                def play(rounds = 1)
         
     | 
| 
      
 31 
     | 
    
         
            +
                  print_player_information
         
     | 
| 
      
 32 
     | 
    
         
            +
                  print_treasure_trove
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  1.upto(rounds) do |round|
         
     | 
| 
      
 35 
     | 
    
         
            +
                    if block_given?
         
     | 
| 
      
 36 
     | 
    
         
            +
                      break if yield
         
     | 
| 
      
 37 
     | 
    
         
            +
                    end
         
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                    puts "\nROUND #{round}:"
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                    @players.each do |player|
         
     | 
| 
      
 42 
     | 
    
         
            +
                      GameTurn.take_turn(player)
         
     | 
| 
      
 43 
     | 
    
         
            +
                    end
         
     | 
| 
      
 44 
     | 
    
         
            +
                  end
         
     | 
| 
      
 45 
     | 
    
         
            +
                end
         
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
      
 48 
     | 
    
         
            +
             
     | 
| 
      
 49 
     | 
    
         
            +
            if __FILE__==$0
         
     | 
| 
      
 50 
     | 
    
         
            +
              game = Game.new
         
     | 
| 
      
 51 
     | 
    
         
            +
             
     | 
| 
      
 52 
     | 
    
         
            +
              # players
         
     | 
| 
      
 53 
     | 
    
         
            +
              larry = Player.new("larry")
         
     | 
| 
      
 54 
     | 
    
         
            +
              curly = Player.new("curly")
         
     | 
| 
      
 55 
     | 
    
         
            +
              moe = Player.new("moe")
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
              game.add_player(larry)
         
     | 
| 
      
 58 
     | 
    
         
            +
              game.add_player(curly)
         
     | 
| 
      
 59 
     | 
    
         
            +
              game.add_player(moe)
         
     | 
| 
      
 60 
     | 
    
         
            +
              game.remove_player(curly)
         
     | 
| 
      
 61 
     | 
    
         
            +
             
     | 
| 
      
 62 
     | 
    
         
            +
              game.play
         
     | 
| 
      
 63 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,47 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 2 
     | 
    
         
            +
              module GameStats
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
                def print_stats
         
     | 
| 
      
 5 
     | 
    
         
            +
                  puts format_section_title("game stats")
         
     | 
| 
      
 6 
     | 
    
         
            +
                  print_strength_stats
         
     | 
| 
      
 7 
     | 
    
         
            +
                  print_treasure_stats
         
     | 
| 
      
 8 
     | 
    
         
            +
                  puts total_points
         
     | 
| 
      
 9 
     | 
    
         
            +
                  print_high_scores
         
     | 
| 
      
 10 
     | 
    
         
            +
                end
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                def print_strength_stats
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
                  strong_players, wimpy_players = players.partition { |player| player.strong? }
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
                  puts "\nThere are #{strong_players.size} strong players:"
         
     | 
| 
      
 17 
     | 
    
         
            +
                  strong_players.each do |player|
         
     | 
| 
      
 18 
     | 
    
         
            +
                    puts player.print_health_status
         
     | 
| 
      
 19 
     | 
    
         
            +
                  end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                  puts "\nThere are #{wimpy_players.size} wimpy players:"
         
     | 
| 
      
 22 
     | 
    
         
            +
                  wimpy_players.each do |player|
         
     | 
| 
      
 23 
     | 
    
         
            +
                    puts player.print_health_status
         
     | 
| 
      
 24 
     | 
    
         
            +
                  end
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
                end
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                def print_treasure_stats
         
     | 
| 
      
 29 
     | 
    
         
            +
                  players.each do |player|
         
     | 
| 
      
 30 
     | 
    
         
            +
                    player.print_treasures
         
     | 
| 
      
 31 
     | 
    
         
            +
                  end
         
     | 
| 
      
 32 
     | 
    
         
            +
                end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                def total_points
         
     | 
| 
      
 35 
     | 
    
         
            +
                  players.reduce(0) { |sum, player| sum += player.points }
         
     | 
| 
      
 36 
     | 
    
         
            +
                end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
             
     | 
| 
      
 39 
     | 
    
         
            +
                def print_high_scores
         
     | 
| 
      
 40 
     | 
    
         
            +
                  puts "\n#{title} High Scores:"
         
     | 
| 
      
 41 
     | 
    
         
            +
                  players.sort.each do |player|
         
     | 
| 
      
 42 
     | 
    
         
            +
                    puts player.print_score
         
     | 
| 
      
 43 
     | 
    
         
            +
                  end
         
     | 
| 
      
 44 
     | 
    
         
            +
                end
         
     | 
| 
      
 45 
     | 
    
         
            +
             
     | 
| 
      
 46 
     | 
    
         
            +
              end
         
     | 
| 
      
 47 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,23 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require_relative 'player'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require_relative 'die'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require_relative 'loaded_die'
         
     | 
| 
      
 4 
     | 
    
         
            +
             
     | 
| 
      
 5 
     | 
    
         
            +
            module StudioGame
         
     | 
| 
      
 6 
     | 
    
         
            +
              module GameTurn
         
     | 
| 
      
 7 
     | 
    
         
            +
                def self.take_turn(player)
         
     | 
| 
      
 8 
     | 
    
         
            +
                  die = Die.new
         
     | 
| 
      
 9 
     | 
    
         
            +
                  #die = LoadedDie.new
         
     | 
| 
      
 10 
     | 
    
         
            +
             
     | 
| 
      
 11 
     | 
    
         
            +
                  puts player.find_treasure
         
     | 
| 
      
 12 
     | 
    
         
            +
             
     | 
| 
      
 13 
     | 
    
         
            +
                  case die.roll
         
     | 
| 
      
 14 
     | 
    
         
            +
                  when 1..2
         
     | 
| 
      
 15 
     | 
    
         
            +
                    player.w00t
         
     | 
| 
      
 16 
     | 
    
         
            +
                  when 3..4
         
     | 
| 
      
 17 
     | 
    
         
            +
                    puts "#{player.name} was skipped!"
         
     | 
| 
      
 18 
     | 
    
         
            +
                  else
         
     | 
| 
      
 19 
     | 
    
         
            +
                    player.blam
         
     | 
| 
      
 20 
     | 
    
         
            +
                  end
         
     | 
| 
      
 21 
     | 
    
         
            +
                end
         
     | 
| 
      
 22 
     | 
    
         
            +
              end
         
     | 
| 
      
 23 
     | 
    
         
            +
            end
         
     |