studio_game_by_toni_rib 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b1b5b71a8f94a9bfe10fe5c327b47528adb2c16
4
+ data.tar.gz: a25eb834e0e3969384109e476a0c28688445ad8a
5
+ SHA512:
6
+ metadata.gz: fdbea3b8697f5a3050753361f50d96b97b6acaa3ca5e979bfc81e26d97a86a59fc4e9efcd7384ba022f0b882f8437d5d9e1e2a21a019183897ff90048fb9c759
7
+ data.tar.gz: f792bb633eb87d83d1654f1d9a091e73ca79712c1dfbd1f627e9e7444f5a8691e125de3111b43def70489a786b101e0c13588b06d9a853a8689f1f887f8b5643
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2015 Toni Rib
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,2 @@
1
+ StudioGame allows the user to play a game in which players can get w00ted or blammed
2
+ on each turn. In addition they find and accrue treasures for points.
@@ -0,0 +1,3 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
@@ -0,0 +1,31 @@
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
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
8
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
9
+ knuckleheads.load_players(ARGV.shift || default_player_file)
10
+
11
+ klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
12
+ knuckleheads.add_player(klutz)
13
+
14
+ berserker = StudioGame::BerserkPlayer.new("berserker", 50)
15
+ knuckleheads.add_player(berserker)
16
+
17
+ loop do
18
+ puts "\nHow many game rounds? ('quit' to exit)"
19
+ answer = gets.chomp.downcase
20
+ case answer
21
+ when /^\d+$/
22
+ knuckleheads.play(answer.to_i)
23
+ when 'quit', 'exit'
24
+ knuckleheads.print_stats
25
+ break
26
+ else
27
+ puts "Please enter a number or 'quit'"
28
+ end
29
+ end
30
+
31
+ knuckleheads.save_high_scores
@@ -0,0 +1,7 @@
1
+ module StudioGame
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{self.number} (#{self.class})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class BerserkPlayer < Player
5
+
6
+ def initialize(name, health)
7
+ @w00t_count = 0
8
+ super(name, health)
9
+ end
10
+
11
+ def berserk?
12
+ @w00t_count > 5
13
+ end
14
+
15
+ def w00t
16
+ super
17
+ @w00t_count += 1
18
+ puts "#{@name} is berserk!" if berserk?
19
+ end
20
+
21
+ def blam
22
+ berserk? ? w00t : super
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+ def found_treasure(treasure)
6
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2)
7
+ super damaged_treasure
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class Die
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ @number = rand(1..6)
11
+ audit
12
+ @number
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,95 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game_turn'
4
+ require_relative 'treasure_trove'
5
+ require 'csv'
6
+
7
+ module StudioGame
8
+ class Game
9
+ attr_reader :title
10
+
11
+ def initialize(title)
12
+ @title = title.capitalize
13
+ @players = []
14
+ end
15
+
16
+ def load_players(from_file)
17
+ CSV.foreach(from_file) do |row|
18
+ player = Player.new(row[0], row[1].to_i)
19
+ add_player(player)
20
+ end
21
+ end
22
+
23
+ def save_high_scores(to_file = "high_scores.txt")
24
+ File.open(to_file, "w") do |file|
25
+ file.puts "#{@title} High Scores:"
26
+ @players.sort.each do |player|
27
+ file.puts high_score_entry(player)
28
+ end
29
+ end
30
+ end
31
+
32
+ def high_score_entry(player)
33
+ formatted_name = player.name.ljust(20, '.')
34
+ "#{formatted_name} #{player.score}"
35
+ end
36
+
37
+ def add_player(player)
38
+ @players << player
39
+ end
40
+
41
+ def total_points
42
+ @players.reduce(0) { |sum, player| sum + player.points }
43
+ end
44
+
45
+ def play(rounds)
46
+
47
+ puts "There are #{@players.size} players in #{@title}:"
48
+
49
+ @players.each do |player|
50
+ puts player
51
+ end
52
+
53
+ @treasures = TreasureTrove::TREASURES
54
+ puts "\nThere are #{@treasures.size} treasures to be found:"
55
+ @treasures.each do |treasure|
56
+ puts "A #{treasure.name} is worth #{treasure.points} points"
57
+ end
58
+
59
+ 1.upto(rounds) do |round|
60
+ puts "\nRound #{round}:"
61
+ @players.each do |player|
62
+ GameTurn.take_turn(player)
63
+ end
64
+ end
65
+ end
66
+
67
+ def print_name_and_health(player)
68
+ puts "#{player.name} (#{player.health})"
69
+ end
70
+
71
+ def print_stats
72
+ strong_players, wimpy_players = @players.partition { |player| player.strong? }
73
+
74
+ puts "\n#{@title} Statistics:"
75
+ puts "\n#{strong_players.size} strong players:"
76
+ strong_players.each { |player| puts print_name_and_health(player)}
77
+ puts "\n#{wimpy_players.size} wimpy players:"
78
+ wimpy_players.each { |player| puts print_name_and_health(player)}
79
+
80
+ @players.sort.each do |player|
81
+ puts "\n#{player.name}'s point totals:"
82
+ player.each_found_treasure do |treasure|
83
+ puts "#{treasure.points} total #{treasure.name} points"
84
+ end
85
+ puts "#{player.points} grand total points"
86
+ end
87
+
88
+ puts "\n#{total_points} total points from treasures found"
89
+
90
+ puts "\n#{@title}'s High Scores:"
91
+ @players.sort.each { |player| puts high_score_entry(player) }
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'loaded_die'
4
+ require_relative 'treasure_trove'
5
+
6
+ module StudioGame
7
+ module GameTurn
8
+ def self.take_turn(player)
9
+ die = Die.new
10
+ case die.roll
11
+ when 1..2
12
+ player.blam
13
+ when 3..4
14
+ puts "#{player.name} was skipped."
15
+ else
16
+ player.w00t
17
+ end
18
+ treasure = TreasureTrove.random
19
+ player.found_treasure(treasure)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
4
+ class LoadedDie
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ numbers = [1, 1, 2, 5, 6, 6]
11
+ @number = numbers.sample
12
+ audit
13
+ @number
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module StudioGame
2
+ module Playable
3
+ def w00t
4
+ puts "#{self.name} got w00ted!"
5
+ self.health = self.health + 15
6
+ end
7
+
8
+ def blam
9
+ puts "#{self.name} got blammed!"
10
+ self.health = self.health - 10
11
+ end
12
+
13
+ def strong?
14
+ self.health > 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,51 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Player
6
+ include Playable
7
+
8
+ attr_accessor :name
9
+ attr_accessor :health
10
+
11
+ def initialize(name, health = 100)
12
+ @name = name.capitalize
13
+ @health = health
14
+ @found_treasures = Hash.new(0)
15
+ end
16
+
17
+ def score
18
+ @health + points
19
+ end
20
+
21
+ def to_s
22
+ "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
23
+ end
24
+
25
+ def self.from_csv(str_csv)
26
+ name, health = str_csv.split(',')
27
+ Player.new(name, Integer(health))
28
+ end
29
+
30
+ def found_treasure(treasure)
31
+ @found_treasures[treasure.name] += treasure.points
32
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
33
+ puts "#{@name}'s treasures: #{@found_treasures}."
34
+ end
35
+
36
+ def points
37
+ @found_treasures.values.reduce(0, :+)
38
+ end
39
+
40
+ def <=>(other_player)
41
+ other_player.score <=> score
42
+ end
43
+
44
+ def each_found_treasure
45
+ @found_treasures.each do |name, points|
46
+ yield Treasure.new(name, points)
47
+ end
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,18 @@
1
+ module StudioGame
2
+ Treasure = Struct.new(:name, :points)
3
+
4
+ module TreasureTrove
5
+ TREASURES = [
6
+ Treasure.new(:pie, 5),
7
+ Treasure.new(:bottle, 25),
8
+ Treasure.new(:hammer, 50),
9
+ Treasure.new(:skillet, 100),
10
+ Treasure.new(:broomstick, 200),
11
+ Treasure.new(:crowbar, 400)
12
+ ]
13
+
14
+ def self.random
15
+ TREASURES.sample
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,31 @@
1
+ require 'studio_game/berserk_player'
2
+
3
+ module StudioGame
4
+ RSpec.describe BerserkPlayer do
5
+
6
+ before do
7
+ @initial_health = 50
8
+ @player = BerserkPlayer.new("berserker", @initial_health)
9
+ end
10
+
11
+ it "does not go berserk when w00ted up to 5 times" do
12
+ 1.upto(5) { @player.w00t }
13
+
14
+ expect(@player.berserk?).to be_falsey
15
+ end
16
+
17
+ it "goes berserk when w00ted more than 5 times" do
18
+ 1.upto(6) { @player.w00t }
19
+
20
+ expect(@player.berserk?).to be_truthy
21
+ end
22
+
23
+ it "gets w00ted instead of blammed when it's gone berserk" do
24
+ 1.upto(6) { @player.w00t }
25
+ 1.upto(2) { @player.blam }
26
+
27
+ expect(@player.health).to eq(@initial_health + (8 * 15))
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,32 @@
1
+ require 'studio_game/clumsy_player'
2
+
3
+ module StudioGame
4
+ RSpec.describe ClumsyPlayer do
5
+ before do
6
+ @player = ClumsyPlayer.new("klutz")
7
+ end
8
+
9
+ it "only gets half the point value for each treasure" do
10
+ expect(@player.points).to be_zero
11
+
12
+ hammer = Treasure.new(:hammer, 50)
13
+ @player.found_treasure(hammer)
14
+ @player.found_treasure(hammer)
15
+ @player.found_treasure(hammer)
16
+
17
+ expect(@player.points).to eq(75)
18
+
19
+ crowbar = Treasure.new(:crowbar, 400)
20
+ @player.found_treasure(crowbar)
21
+
22
+ expect(@player.points).to eq(275)
23
+
24
+ yielded = []
25
+ @player.each_found_treasure do |treasure|
26
+ yielded << treasure
27
+ end
28
+
29
+ expect(yielded).to eq([Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)])
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,59 @@
1
+ require 'studio_game/game'
2
+
3
+ module StudioGame
4
+ RSpec.describe Game do
5
+
6
+ before do
7
+ @game = Game.new("Knuckleheads")
8
+
9
+ @initial_health = 100
10
+ @player = Player.new("moe", @initial_health)
11
+
12
+ @game.add_player(@player)
13
+ $stdout = StringIO.new
14
+ end
15
+
16
+ it "w00ts the player if a high number is rolled" do
17
+ allow_any_instance_of(Die).to receive(:roll).and_return(5)
18
+
19
+ @game.play(2)
20
+
21
+ expect(@player.health).to eq(@initial_health + 15 * 2)
22
+ end
23
+
24
+ it "skips the player if a medium number is rolled" do
25
+ allow_any_instance_of(Die).to receive(:roll).and_return(3)
26
+
27
+ @game.play(2)
28
+
29
+ expect(@player.health).to eq(@initial_health)
30
+ end
31
+
32
+ it "blams the player if a low number is rolled" do
33
+ allow_any_instance_of(Die).to receive(:roll).and_return(1)
34
+
35
+ @game.play(2)
36
+
37
+ expect(@player.health).to eq(@initial_health - 10 * 2)
38
+ end
39
+
40
+ it "assigns a treasure for points during a player's turn" do
41
+ @game.play(1)
42
+
43
+ expect(@player.points).not_to be_zero
44
+ end
45
+
46
+ it "computes total points as the sum of all player points" do
47
+ @player2 = Player.new("larry")
48
+
49
+ @game.add_player(@player2)
50
+
51
+ @player.found_treasure(Treasure.new(:hammer, 50))
52
+ @player.found_treasure(Treasure.new(:hammer, 50))
53
+ @player2.found_treasure(Treasure.new(:crowbar, 400))
54
+
55
+ expect(@game.total_points).to eq(500)
56
+ end
57
+
58
+ end
59
+ end
@@ -0,0 +1,130 @@
1
+ require 'studio_game/player'
2
+ require 'studio_game/treasure_trove'
3
+
4
+ module StudioGame
5
+ RSpec.describe Player do
6
+
7
+ before do
8
+ @initial_health = 150
9
+ @player = Player.new("larry", @initial_health)
10
+ $stdout = StringIO.new
11
+ end
12
+
13
+ it "has a capitalized name" do
14
+ expect(@player.name).to eq "Larry"
15
+ end
16
+
17
+ it "has an initial health" do
18
+ expect(@player.health).to eq @initial_health
19
+ end
20
+
21
+ it "has a string representation" do
22
+ @player.found_treasure(Treasure.new(:hammer, 50))
23
+ @player.found_treasure(Treasure.new(:hammer, 50))
24
+
25
+ expect(@player.to_s).to eq "I'm Larry with health = 150, points = 100, and score = 250."
26
+ end
27
+
28
+ it "increases health by 15 when w00ted" do
29
+ expect(@player.w00t).to eq (@initial_health + 15)
30
+ end
31
+
32
+ it "decreases health by 10 when blammed" do
33
+ expect(@player.blam).to eq (@initial_health - 10)
34
+ end
35
+
36
+ it "computes points as the sum of all treasure points" do
37
+ expect(@player.points).to eq(0)
38
+
39
+ @player.found_treasure(Treasure.new(:hammer, 50))
40
+
41
+ expect(@player.points).to eq(50)
42
+
43
+ @player.found_treasure(Treasure.new(:crowbar, 400))
44
+
45
+ expect(@player.points).to eq(450)
46
+
47
+ @player.found_treasure(Treasure.new(:hammer, 50))
48
+
49
+ expect(@player.points).to eq(500)
50
+ end
51
+
52
+ it "computes a score as the sum of its health and points" do
53
+ @player.found_treasure(Treasure.new(:hammer, 50))
54
+ @player.found_treasure(Treasure.new(:hammer, 50))
55
+
56
+ expect(@player.score).to eq(250)
57
+ end
58
+
59
+ context "player with initial health of 150" do
60
+ before do
61
+ @player = Player.new("larry", 150)
62
+ end
63
+
64
+ it "is strong" do
65
+ expect(@player).to be_strong
66
+ end
67
+ end
68
+
69
+ context "player with initial health of 100" do
70
+ before do
71
+ @player = Player.new("moe", 100)
72
+ end
73
+
74
+ it "is wimpy" do
75
+ expect(@player).not_to be_strong
76
+ end
77
+ end
78
+
79
+ context "in a collection of players" do
80
+ before do
81
+ @player1 = Player.new("moe", 100)
82
+ @player2 = Player.new("larry", 200)
83
+ @player3 = Player.new("curly", 300)
84
+
85
+ @players = [@player1, @player2, @player3]
86
+ end
87
+
88
+ it "is sorted by decreasing score" do
89
+ expect(@players.sort).to eq [@player3, @player2, @player1]
90
+ end
91
+ end
92
+
93
+ it "yields each found treasure and its total points" do
94
+ @player.found_treasure(Treasure.new(:skillet, 100))
95
+ @player.found_treasure(Treasure.new(:skillet, 100))
96
+ @player.found_treasure(Treasure.new(:hammer, 50))
97
+ @player.found_treasure(Treasure.new(:bottle, 5))
98
+ @player.found_treasure(Treasure.new(:bottle, 5))
99
+ @player.found_treasure(Treasure.new(:bottle, 5))
100
+ @player.found_treasure(Treasure.new(:bottle, 5))
101
+ @player.found_treasure(Treasure.new(:bottle, 5))
102
+
103
+ yielded = []
104
+ @player.each_found_treasure do |treasure|
105
+ yielded << treasure
106
+ end
107
+
108
+ expect(yielded).to eq [
109
+ Treasure.new(:skillet, 200),
110
+ Treasure.new(:hammer, 50),
111
+ Treasure.new(:bottle, 25)
112
+ ]
113
+ end
114
+
115
+ it "creates a player from a string of csv" do
116
+ str = "Toni,110"
117
+
118
+ expect(Player.from_csv(str).name).to eq("Toni")
119
+ expect(Player.from_csv(str).score).to eq(110)
120
+ end
121
+
122
+ it "can be created from a CSV string" do
123
+ player = Player.from_csv("larry,150")
124
+
125
+ expect(player.name).to eq("Larry")
126
+ expect(player.score).to eq(150)
127
+ end
128
+
129
+ end
130
+ end
@@ -0,0 +1,92 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Allows RSpec to persist some state between runs in order to support
54
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
55
+ # you configure your source control system to ignore this file.
56
+ # config.example_status_persistence_file_path = "spec/examples.txt"
57
+
58
+ # Limits the available syntax to the non-monkey patched syntax that is
59
+ # recommended. For more details, see:
60
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
61
+ # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
62
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
63
+ config.disable_monkey_patching!
64
+
65
+ # This setting enables warnings. It's recommended, but in some cases may
66
+ # be too noisy due to issues in dependencies.
67
+ config.warnings = true
68
+
69
+ # Many RSpec users commonly either run the entire suite or an individual
70
+ # file, and it's useful to allow more verbose output when running an
71
+ # individual spec file.
72
+ if config.files_to_run.one?
73
+ # Use the documentation formatter for detailed output,
74
+ # unless a formatter has already been configured
75
+ # (e.g. via a command-line flag).
76
+ config.default_formatter = 'doc'
77
+ end
78
+
79
+
80
+ # Run specs in random order to surface order dependencies. If you find an
81
+ # order dependency and want to debug it, you can fix the order by providing
82
+ # the seed, which is printed after each run.
83
+ # --seed 1234
84
+ config.order = :random
85
+
86
+ # Seed global randomization in this process using the `--seed` CLI option.
87
+ # Setting this allows you to use `--seed` to deterministically reproduce
88
+ # test failures related to randomization by passing the same `--seed` value
89
+ # as the one that triggered the failure.
90
+ Kernel.srand config.seed
91
+
92
+ end
@@ -0,0 +1,57 @@
1
+ require 'studio_game/treasure_trove'
2
+
3
+ module StudioGame
4
+ RSpec.describe Treasure do
5
+
6
+ before do
7
+ @treasure = Treasure.new(:hammer, 50)
8
+ end
9
+
10
+ it "has a name attribute" do
11
+ expect(@treasure.name).to eq(:hammer)
12
+ end
13
+
14
+ it "has a points attribute" do
15
+ expect(@treasure.points).to eq(50)
16
+ end
17
+
18
+ end
19
+
20
+ RSpec.describe TreasureTrove do
21
+
22
+ it "has six treasures" do
23
+ expect(TreasureTrove::TREASURES.size).to eq(6)
24
+ end
25
+
26
+ it "has a pie worth 5 points" do
27
+ expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
28
+ end
29
+
30
+ it "has a bottle worth 25 points" do
31
+ expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
32
+ end
33
+
34
+ it "has a hammer worth 50 points" do
35
+ expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
36
+ end
37
+
38
+ it "has a skillet worth 100 points" do
39
+ expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
40
+ end
41
+
42
+ it "has a broomstick worth 200 points" do
43
+ expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
44
+ end
45
+
46
+ it "has a crowbar worth 400 points" do
47
+ expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400))
48
+ end
49
+
50
+ it "returns a random treasure" do
51
+ treasure = TreasureTrove.random
52
+
53
+ expect(TreasureTrove::TREASURES).to include(treasure)
54
+ end
55
+
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_by_toni_rib
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Toni Rib
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |-
28
+ StudioGame allows the user to play a game in which players can get w00ted or blammed
29
+ on each turn. In addition they find and accrue treasures for points.
30
+ email: tonimarierib@gmail.com
31
+ executables:
32
+ - studio_game
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - LICENSE
37
+ - README
38
+ - bin/players.csv
39
+ - bin/studio_game
40
+ - lib/studio_game/auditable.rb
41
+ - lib/studio_game/berserk_player.rb
42
+ - lib/studio_game/clumsy_player.rb
43
+ - lib/studio_game/die.rb
44
+ - lib/studio_game/game.rb
45
+ - lib/studio_game/game_turn.rb
46
+ - lib/studio_game/loaded_die.rb
47
+ - lib/studio_game/playable.rb
48
+ - lib/studio_game/player.rb
49
+ - lib/studio_game/treasure_trove.rb
50
+ - spec/studio_game/berserk_player_spec.rb
51
+ - spec/studio_game/clumsy_player_spec.rb
52
+ - spec/studio_game/game_spec.rb
53
+ - spec/studio_game/player_spec.rb
54
+ - spec/studio_game/spec_helper.rb
55
+ - spec/studio_game/treasure_trove_spec.rb
56
+ homepage: http://tonirib.github.io/online-responsive-resume
57
+ licenses:
58
+ - MIT
59
+ metadata: {}
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '2.0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubyforge_project:
76
+ rubygems_version: 2.4.6
77
+ signing_key:
78
+ specification_version: 4
79
+ summary: Action packed treasure finding turn based game
80
+ test_files:
81
+ - spec/studio_game/berserk_player_spec.rb
82
+ - spec/studio_game/clumsy_player_spec.rb
83
+ - spec/studio_game/game_spec.rb
84
+ - spec/studio_game/player_spec.rb
85
+ - spec/studio_game/spec_helper.rb
86
+ - spec/studio_game/treasure_trove_spec.rb