studio_game23 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 37806bd0d73ee8d7c0199ed023bdaf142dfcc4678ce738242451da61b45d1f61
4
+ data.tar.gz: 79b3ae4e9da9145a2b1c5c43100420d1b95046927c4ebdfa7e028a52c13cab3b
5
+ SHA512:
6
+ metadata.gz: 11a2e4f56f886cfcd954b7ea45d0cd1194f44737e6e1f100333b8d4f03f80408ecf574b144d27400798a58601f0d01acd982829e4be6f38008e553a0245e19b7
7
+ data.tar.gz: c6a062436e33927a0a1333f43fbae8cd4a53a1709c71e156ef68145ad789cda5c5c9f83d24073222837c562e1aa5ace2ebae29c7c910d854cd8e26e11e9484cb
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ MIT License
data/README ADDED
@@ -0,0 +1 @@
1
+ This is just a simple gem, created during a Ruby online course for learning purposes.
@@ -0,0 +1,4 @@
1
+ Anna, 150
2
+ Konrad, 40
3
+ Crispin, 80
4
+ Juni, 99
data/bin/players.csv ADDED
@@ -0,0 +1,3 @@
1
+ Alvin, 100
2
+ Simon, 60
3
+ Theo, 125
data/bin/studio_game23 ADDED
@@ -0,0 +1,33 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require_relative '../lib/studio_game23/game'
4
+
5
+ game1 = StudioGame23::Game.new("Test")
6
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
7
+ game1.load_players(ARGV.shift || default_player_file)
8
+
9
+
10
+ clumsy_player = StudioGame23::ClumsyPlayer.new("klutz", 100, 3)
11
+ game1.add_player(clumsy_player)
12
+
13
+ berserk_player = StudioGame23::BerserkPlayer.new("berserker", 50)
14
+ game1.add_player(berserk_player)
15
+
16
+ loop do
17
+ puts "\nHow many game rounds? ('quit' to exit)"
18
+ rounds = gets.chomp.downcase
19
+ case rounds
20
+ when /^\d+$/
21
+ game1.play(rounds.to_i) do
22
+ game1.total_points >= 2000
23
+ end
24
+ when 'quit', 'exit'
25
+ game1.print_stats
26
+ break
27
+ else
28
+ puts "Please enter a number or 'quit'."
29
+ end
30
+
31
+ end
32
+
33
+ game1.save_high_scores
@@ -0,0 +1,8 @@
1
+ module StudioGame23
2
+ module Auditable
3
+
4
+ def audit
5
+ puts "Rolled a #{self.number} (#{self.class})"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame23
4
+ class BerserkPlayer < Player
5
+
6
+ def initialize(name, health=100)
7
+ super(name, health)
8
+ @w00t_count = 0
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
+ end
25
+
26
+ if __FILE__ == $0
27
+ berserker = BerserkPlayer.new("berserker", 50)
28
+ 6.times { berserker.w00t }
29
+ 2.times { berserker.blam }
30
+ puts berserker.health
31
+ end
32
+ end
@@ -0,0 +1,43 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame23
4
+ class ClumsyPlayer < Player
5
+
6
+ attr_reader :boost_factor
7
+
8
+ def initialize(name, health, boost_factor=1)
9
+ super(name, health)
10
+ @boost_factor = boost_factor.to_i
11
+ end
12
+
13
+ def found_treasure(treasure)
14
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
15
+ super(damaged_treasure)
16
+ end
17
+
18
+ def w00t
19
+ @boost_factor.times { super }
20
+ end
21
+ end
22
+
23
+ if __FILE__ == $0
24
+ clumsy = ClumsyPlayer.new("klutz", 100, 2)
25
+
26
+ hammer = Treasure.new(:hammer, 50)
27
+ 3.times {clumsy.found_treasure(hammer)}
28
+
29
+ crowbar = Treasure.new(:crowbar, 400)
30
+ clumsy.found_treasure(crowbar)
31
+
32
+ clumsy.each_found_treasure do |treasure|
33
+ puts "#{treasure.points} total #{treasure.name} points"
34
+ end
35
+ puts "#{clumsy.points} grand total points"
36
+ end
37
+ end
38
+
39
+ # __FILE__ is a reference to the current file name
40
+
41
+ # $0 contains the name of the script being executed
42
+
43
+ # $ on a variable's name indicates a global variable
@@ -0,0 +1,20 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame23
4
+ class Die
5
+
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
+ end
@@ -0,0 +1,115 @@
1
+ require_relative 'player'
2
+ require_relative 'clumsy_player'
3
+ require_relative 'berserk_player'
4
+ require_relative 'die'
5
+ require_relative 'game_turn'
6
+ require_relative 'treasure_trove'
7
+ require 'csv'
8
+
9
+ module StudioGame23
10
+ class Game
11
+ attr_reader :title
12
+
13
+ def initialize(title)
14
+ @title = title
15
+ @players = []
16
+ end
17
+
18
+ def add_player(player)
19
+ @players << player
20
+ end
21
+
22
+ def print_stats
23
+ strong, wimpy = @players.partition{|player| player.strong?}
24
+
25
+ puts "\n#{title} Statistics:"
26
+
27
+ puts "\n#{strong.size} Strong players: "
28
+ print_name_and_health(strong)
29
+
30
+ puts "\n#{wimpy.size} Wimpy players:"
31
+ print_name_and_health(wimpy)
32
+
33
+ #sorted_players = @players.sort
34
+
35
+ puts "\n#{title} High Scores:"
36
+ high_score_entry { |line| puts line }
37
+
38
+ puts "\nPlayer's points:"
39
+ @players.each do |player|
40
+ puts "\n#{player.name}'s points total:"
41
+ player.each_found_treasure do |treasure|
42
+ puts "#{treasure.points} total #{treasure.name} points"
43
+ end
44
+ puts "#{player.points} grand total points"
45
+ end
46
+
47
+ puts "\n#{total_points} total points from treasures found"
48
+ end
49
+
50
+ def print_name_and_health(players)
51
+ players.each do |player|
52
+ puts "#{player.name} (#{player.health})"
53
+ end
54
+ end
55
+
56
+ def load_players(from_file)
57
+ #File.readlines(from_file).each do |line|
58
+ # player = Player.from_csv(line)
59
+ # add_player(player)
60
+ #end
61
+
62
+ CSV.foreach(from_file) do |row|
63
+ player = Player.new(row[0], Integer(row[1]))
64
+ add_player(player)
65
+ end
66
+ end
67
+
68
+ def high_score_entry
69
+ sorted_players = @players.sort
70
+ sorted_players.each do |player|
71
+ line_to_save = "#{player.name}...........#{player.score}"
72
+ yield line_to_save
73
+ end
74
+ end
75
+
76
+ def save_high_scores(to_file = 'high_scores.txt')
77
+ File.open(to_file, 'w') do |file|
78
+ file.puts "#{@title} High Scores:"
79
+ high_score_entry do |line|
80
+ file.puts line
81
+ end
82
+ end
83
+ end
84
+
85
+ def total_points
86
+ @players.reduce(0) { |total_points, player| total_points + player.points }
87
+ end
88
+
89
+ def play(rounds)
90
+ puts "There are #{@players.size} players in #{title.capitalize}:"
91
+ puts @players
92
+
93
+ treasures = TreasureTrove::TREASURES
94
+ puts "\nThere are #{treasures.size} treasures in the trove:"
95
+
96
+ treasures.each do |treasure|
97
+ puts "A #{treasure.name} is worth #{treasure.points} points"
98
+ end
99
+
100
+ 1.upto(rounds) do |round|
101
+ if block_given?
102
+ if !yield
103
+ puts "\nRound: #{round}"
104
+ @players.each do |player|
105
+ GameTurn.take_turn(player)
106
+ puts player
107
+ end
108
+ else
109
+ break
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'die'
2
+ require_relative 'player'
3
+ require_relative 'treasure_trove'
4
+
5
+ module StudioGame23
6
+ module GameTurn
7
+ def self.take_turn(player)
8
+ die = Die.new
9
+ number_rolled = die.roll
10
+
11
+ case number_rolled
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
+ end
23
+ end
24
+ end
@@ -0,0 +1,17 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame23
4
+ class LoadedDie
5
+
6
+ include Auditable
7
+
8
+ attr_reader :number
9
+
10
+ def roll
11
+ numbers = [1, 1, 2, 5, 6, 6]
12
+ @number = numbers.sample
13
+ audit
14
+ @number
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ module StudioGame23
2
+ module Playable
3
+ def blam
4
+ self.health -= 10
5
+ puts "#{name} got blammed!"
6
+ end
7
+
8
+ def w00t
9
+ self.health += 15
10
+ puts "#{name} got w00ted!"
11
+ end
12
+
13
+ def strong?
14
+ health >= 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,68 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame23
5
+ class Player
6
+
7
+ include Playable
8
+
9
+ attr_accessor :name, :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 name=(new_name)
18
+ @name = new_name.capitalize
19
+ end
20
+
21
+ def to_s
22
+ "I'm #{@name} with a health = #{@health}, points = #{points}, and score = #{score}."
23
+ end
24
+
25
+ def score
26
+ @health + points
27
+ end
28
+
29
+ def <=>(other)
30
+ other.score <=> score
31
+ end
32
+
33
+ def found_treasure(treasure)
34
+ @found_treasures[treasure.name] += treasure.points
35
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
36
+ puts "#{@name}'s treasures: #{@found_treasures}"
37
+ end
38
+
39
+ def points
40
+ @found_treasures.values.reduce(0, :+)
41
+ end
42
+
43
+ def each_found_treasure
44
+ @found_treasures.each do |name, points|
45
+ yield Treasure.new(name, points)
46
+ end
47
+ end
48
+
49
+ def self.from_csv(csv_string)
50
+ name, health = csv_string.split(', ')
51
+ player = Player.new(name, Integer(health))
52
+ end
53
+
54
+ end
55
+
56
+ if __FILE__ == $0
57
+ player = Player.new("moe")
58
+ puts player.name
59
+ puts player.health
60
+ player.w00t
61
+ puts player.health
62
+ player.blam
63
+ puts player.health
64
+ else
65
+ puts "FILE: #{__FILE__.to_s}"
66
+ puts "$0: #{$0.to_s}"
67
+ end
68
+ end
@@ -0,0 +1,19 @@
1
+ module StudioGame23
2
+ Treasure = Struct.new(:name, :points)
3
+
4
+ module TreasureTrove
5
+
6
+ TREASURES = [
7
+ Treasure.new(:pie, 5),
8
+ Treasure.new(:bottle, 25),
9
+ Treasure.new(:hammer, 50),
10
+ Treasure.new(:skillet, 100),
11
+ Treasure.new(:broomstick, 200),
12
+ Treasure.new(:crowbar, 400)
13
+ ]
14
+
15
+ def self.random
16
+ TREASURES.sample
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,100 @@
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
+ # See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
16
+ RSpec.configure do |config|
17
+ # rspec-expectations config goes here. You can use an alternate
18
+ # assertion/expectation library such as wrong or the stdlib/minitest
19
+ # assertions if you prefer.
20
+ config.expect_with :rspec do |expectations|
21
+ # This option will default to `true` in RSpec 4. It makes the `description`
22
+ # and `failure_message` of custom matchers include text for helper methods
23
+ # defined using `chain`, e.g.:
24
+ # be_bigger_than(2).and_smaller_than(4).description
25
+ # # => "be bigger than 2 and smaller than 4"
26
+ # ...rather than:
27
+ # # => "be bigger than 2"
28
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
29
+ expectations.syntax = [:should, :expect]
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ mocks.syntax = [:should, :expect]
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ =begin
52
+ # This allows you to limit a spec run to individual examples or groups
53
+ # you care about by tagging them with `:focus` metadata. When nothing
54
+ # is tagged with `:focus`, all examples get run. RSpec also provides
55
+ # aliases for `it`, `describe`, and `context` that include `:focus`
56
+ # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
57
+ config.filter_run_when_matching :focus
58
+
59
+ # Allows RSpec to persist some state between runs in order to support
60
+ # the `--only-failures` and `--next-failure` CLI options. We recommend
61
+ # you configure your source control system to ignore this file.
62
+ config.example_status_persistence_file_path = "spec/examples.txt"
63
+
64
+ # Limits the available syntax to the non-monkey patched syntax that is
65
+ # recommended. For more details, see:
66
+ # https://relishapp.com/rspec/rspec-core/docs/configuration/zero-monkey-patching-mode
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = "doc"
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,31 @@
1
+ require 'studio_game23/berserk_player'
2
+
3
+ module StudioGame23
4
+ 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
+
13
+ 1.upto(5) {@player.w00t}
14
+
15
+ expect(@player.berserk?).to be false
16
+ end
17
+
18
+ it "goes berserk when w00ted more than 5 times" do
19
+ 1.upto(6) {@player.w00t}
20
+
21
+ expect(@player.berserk?).to be true
22
+ end
23
+
24
+ it "gets w00ted instead of blammed when it's gone berserk" do
25
+ 1.upto(6) {@player.w00t}
26
+ 1.upto(2) {@player.blam}
27
+
28
+ expect(@player.health).to eq @initial_health + (8 * 15)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,45 @@
1
+ require 'studio_game23/clumsy_player'
2
+
3
+ module StudioGame23
4
+ describe ClumsyPlayer do
5
+
6
+ before do
7
+ @initial_health = 105
8
+ @boost_factor = 3
9
+ @player = ClumsyPlayer.new('klutz', @initial_health, @boost_factor)
10
+ end
11
+
12
+ it "only gets half the point value for each treasure" do
13
+
14
+ expect(@player.points).to eq 0
15
+
16
+ hammer = Treasure.new(:hammer, 50)
17
+ @player.found_treasure(hammer)
18
+ @player.found_treasure(hammer)
19
+ @player.found_treasure(hammer)
20
+
21
+ expect(@player.points).to eq 75
22
+
23
+ crowbar = Treasure.new(:crowbar, 400)
24
+ @player.found_treasure(crowbar)
25
+
26
+ expect(@player.points).to eq 275
27
+
28
+ yielded = []
29
+ @player.each_found_treasure do |treasure|
30
+ yielded << treasure
31
+ end
32
+
33
+ expect(yielded).to eq [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
34
+ end
35
+
36
+ it "has a boost_factor" do
37
+ expect(@player.boost_factor).to eq 3
38
+ end
39
+
40
+ it "gets a boost_factor boost in health when w00ted" do
41
+ @player.w00t
42
+ expect(@player.health).to eq (@initial_health + 3 * 15)
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,66 @@
1
+ require 'studio_game23/game'
2
+
3
+ module StudioGame23
4
+ 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
+ end
14
+
15
+ it "w00t the player if a high number is rolled" do
16
+ Die.any_instance.stub(:roll).and_return(5)
17
+
18
+ @game.play(2) { }
19
+ puts @player.health
20
+ expect(@player.health).to eq @initial_health + (15*2)
21
+ #@player.health.should == @initial_health + 15
22
+ end
23
+
24
+ it "skips the player if a medium number is rolled" do
25
+ Die.any_instance.stub(:roll).and_return(3)
26
+
27
+ @game.play(2) { }
28
+ expect(@player.health).to eq @initial_health
29
+ #@player.health.should == @initial_health
30
+ end
31
+
32
+ it "blams a player if a low number is rolled" do
33
+ Die.any_instance.stub(:roll).and_return(1)
34
+
35
+ @game.play(2) { }
36
+ expect(@player.health).to eq @initial_health - (10*2)
37
+ #@player.health.should == @initial_health - 10
38
+ end
39
+
40
+ it "assigns a treasure for points during a player's turn" do
41
+ game = Game.new("Knuckleheads")
42
+ player = Player.new("moe")
43
+
44
+ game.add_player(player)
45
+
46
+ game.play(1) { false }
47
+
48
+ expect(player.points).not_to be_zero
49
+ end
50
+
51
+ it "computes total points as the sum of all player points" do
52
+ game = Game.new("Knuckleheads")
53
+
54
+ player1 = Player.new("moe")
55
+ player2 = Player.new("larry")
56
+
57
+ game.add_player(player1)
58
+ game.add_player(player2)
59
+
60
+ 2.times { player1.found_treasure(Treasure.new(:hammer, 50)) }
61
+ player2.found_treasure(Treasure.new(:crowbar, 400))
62
+
63
+ expect(game.total_points).to eq 500
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,132 @@
1
+ require 'studio_game23/player'
2
+ require 'studio_game23/treasure_trove'
3
+
4
+ module StudioGame23
5
+ 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
+ #@player.name.should == "Larry"
16
+ end
17
+
18
+ it "has an initial health" do
19
+ expect(@player.health).to eq 150
20
+ #@player.health.should == 150
21
+ end
22
+
23
+ it "has a string representation" do
24
+ 2.times { @player.found_treasure(Treasure.new(:hammer, 50)) }
25
+ expect(@player.to_s).to eq "I'm Larry with a health = 150, points = 100, and score = 250."
26
+ #@player.to_s.should == "I'm Larry with a health of 150 and a score of 155."
27
+ end
28
+
29
+ it "computes a score as the sum of its health and points" do
30
+ 2.times { @player.found_treasure(Treasure.new(:hammer, 50)) }
31
+ expect(@player.score).to eq @player.health + (2 * 50)
32
+ #@player.score.should == "larry".length + 150
33
+ end
34
+
35
+ it "increases health by 15 when w00ted" do
36
+
37
+ @player.w00t
38
+ expect(@player.health).to be @initial_health + 15
39
+ #@player.health.should == @initial_health + 15
40
+ end
41
+
42
+ it "decreases health by 10 when blammed" do
43
+ @player.blam
44
+ expect(@player.health).to eq @initial_health - 10
45
+ #@player.health.should == @initial_health - 10
46
+ end
47
+
48
+ it "computes points as the sum of all treasure points" do
49
+ expect(@player.points).to eq 0
50
+
51
+ @player.found_treasure(Treasure.new(:hammer, 50))
52
+
53
+ expect(@player.points).to eq 50
54
+
55
+ @player.found_treasure(Treasure.new(:crowbar, 400))
56
+
57
+ expect(@player.points).to eq 450
58
+
59
+ @player.found_treasure(Treasure.new(:hammer, 50))
60
+
61
+ expect(@player.points).to eq 500
62
+ end
63
+
64
+ it "yields each found treasure and its total points" do
65
+ @player.found_treasure(Treasure.new(:skillet, 100))
66
+ @player.found_treasure(Treasure.new(:skillet, 100))
67
+ @player.found_treasure(Treasure.new(:hammer, 50))
68
+ @player.found_treasure(Treasure.new(:bottle, 5))
69
+ @player.found_treasure(Treasure.new(:bottle, 5))
70
+ @player.found_treasure(Treasure.new(:bottle, 5))
71
+ @player.found_treasure(Treasure.new(:bottle, 5))
72
+ @player.found_treasure(Treasure.new(:bottle, 5))
73
+
74
+ yielded = []
75
+ @player.each_found_treasure do |treasure|
76
+ yielded << treasure
77
+ end
78
+
79
+ expect(yielded).to eq [Treasure.new(:skillet, 200), Treasure.new(:hammer, 50), Treasure.new(:bottle, 25)]
80
+ end
81
+
82
+ context "with a health greater than 100" do
83
+
84
+ before do
85
+ @initial_health = 150
86
+ @player = Player.new("Strong Player", @initial_health)
87
+ end
88
+
89
+ it "has a strong status" do
90
+ expect(@player).to be_strong
91
+ #@player.should be_strong
92
+ end
93
+ end
94
+
95
+ context "with a health less than 100" do
96
+
97
+ before do
98
+ @initial_health = 90
99
+ @player = Player.new("Wimpy Player", @initial_health)
100
+ end
101
+
102
+ it "is wimpy" do
103
+ expect(@player).not_to be_strong
104
+ #@player.should_not be_strong
105
+ end
106
+ end
107
+
108
+ context "in a collection of players" do
109
+ before do
110
+ @player1 = Player.new("moe", 100)
111
+ @player2 = Player.new("larry", 200)
112
+ @player3 = Player.new("curly", 300)
113
+
114
+ @players = [@player1, @player2, @player3]
115
+ end
116
+
117
+ it "is sorted by decreasing score" do
118
+ @players.sort.should == [@player3, @player2, @player1]
119
+ end
120
+ end
121
+
122
+ context "receiving information about a player as a csv_line" do
123
+
124
+ it "creates a new player from csv information" do
125
+ player1 = Player.from_csv("Alwin, 100")
126
+ player2 = Player.new("Alwin", 100)
127
+ expect(player1.name).to eq player2.name
128
+ expect(player1.health).to eq player2.health
129
+ end
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,54 @@
1
+ require 'studio_game23/treasure_trove'
2
+
3
+ module StudioGame23
4
+ describe Treasure do
5
+ before do
6
+ @treasure = Treasure.new(:hammer, 50)
7
+ end
8
+
9
+ it "has a name attribute" do
10
+ expect(@treasure.name).to eq :hammer
11
+ end
12
+
13
+ it "has a points attribute" do
14
+ expect(@treasure.points).to eq 50
15
+ end
16
+ end
17
+
18
+ describe TreasureTrove do
19
+
20
+ it "has six treasures" do
21
+ expect(TreasureTrove::TREASURES.size).to eq 6
22
+ end
23
+
24
+ it "has a pie worth 5 points" do
25
+ expect(TreasureTrove::TREASURES[0]).to eq Treasure.new(:pie, 5)
26
+ end
27
+
28
+ it "has a bottle worth 25 points" do
29
+ expect(TreasureTrove::TREASURES[1]).to eq Treasure.new(:bottle, 25)
30
+ end
31
+
32
+ it "has a hammer worth 50 points" do
33
+ expect(TreasureTrove::TREASURES[2]).to eq Treasure.new(:hammer, 50)
34
+ end
35
+
36
+ it "has a skillet worth 100 points" do
37
+ expect(TreasureTrove::TREASURES[3]).to eq Treasure.new(:skillet, 100)
38
+ end
39
+
40
+ it "has a broomstick worth 200 points" do
41
+ expect(TreasureTrove::TREASURES[4]).to eq Treasure.new(:broomstick, 200)
42
+ end
43
+
44
+ it "has a crowbar worth 400 points" do
45
+ expect(TreasureTrove::TREASURES[5]).to eq Treasure.new(:crowbar, 400)
46
+ end
47
+
48
+ it "returns a random treasure" do
49
+ treasure = TreasureTrove.random
50
+
51
+ expect(TreasureTrove::TREASURES).to include(treasure)
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game23
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Anna
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-02-05 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: '2.8'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 2.8.0
23
+ type: :development
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '2.8'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 2.8.0
33
+ description: 'This is just a simple gem, created during a Ruby online course for learning
34
+ purposes.
35
+
36
+ '
37
+ email: njutik@web.de
38
+ executables:
39
+ - studio_game23
40
+ extensions: []
41
+ extra_rdoc_files: []
42
+ files:
43
+ - LICENSE
44
+ - README
45
+ - bin/my_favorite_players.csv
46
+ - bin/players.csv
47
+ - bin/studio_game23
48
+ - lib/studio_game23/auditable.rb
49
+ - lib/studio_game23/berserk_player.rb
50
+ - lib/studio_game23/clumsy_player.rb
51
+ - lib/studio_game23/die.rb
52
+ - lib/studio_game23/game.rb
53
+ - lib/studio_game23/game_turn.rb
54
+ - lib/studio_game23/loaded_die.rb
55
+ - lib/studio_game23/playable.rb
56
+ - lib/studio_game23/player.rb
57
+ - lib/studio_game23/treasure_trove.rb
58
+ - spec/spec_helper.rb
59
+ - spec/studio_game23/berserk_player_spec.rb
60
+ - spec/studio_game23/clumsy_player_spec.rb
61
+ - spec/studio_game23/game_spec.rb
62
+ - spec/studio_game23/player_spec.rb
63
+ - spec/studio_game23/treasure_trove_spec.rb
64
+ homepage: ''
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '1.9'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubygems_version: 3.4.6
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: A Studio Game for learning purposes only
87
+ test_files:
88
+ - spec/spec_helper.rb
89
+ - spec/studio_game23/berserk_player_spec.rb
90
+ - spec/studio_game23/clumsy_player_spec.rb
91
+ - spec/studio_game23/game_spec.rb
92
+ - spec/studio_game23/player_spec.rb
93
+ - spec/studio_game23/treasure_trove_spec.rb