dr_cello_studio_game 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.txt +7 -0
- data/README.txt +7 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +37 -0
- data/lib/studio_game/auditable.rb +6 -0
- data/lib/studio_game/berserk_player.rb +38 -0
- data/lib/studio_game/clumsy_player.rb +33 -0
- data/lib/studio_game/die.rb +21 -0
- data/lib/studio_game/game.rb +85 -0
- data/lib/studio_game/gameturn.rb +31 -0
- data/lib/studio_game/loaded_die.rb +10 -0
- data/lib/studio_game/playable.rb +18 -0
- data/lib/studio_game/player.rb +66 -0
- data/lib/studio_game/treasure_trove.rb +15 -0
- data/spec/studio_game/berserk_player_spec.rb +31 -0
- data/spec/studio_game/clumsy_player_spec.rb +34 -0
- data/spec/studio_game/game_spec.rb +44 -0
- data/spec/studio_game/player_spec.rb +127 -0
- data/spec/studio_game/treasuretrove_spec.rb +55 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d4fc197aa3736a19cb42fe1ff3ec98beebf379b
|
4
|
+
data.tar.gz: 2348e5ce7bd475733593e858eceb9559a9ef8c03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2877b82d5cbc81ceb62069a19a2e35ac184c7b1d7e76bf24bed15f2bb68a26ae5ee094c50281fcda6d03e8ef2e80ea4ed0b597f245d2ae360249c8b9733973d1
|
7
|
+
data.tar.gz: a30d2fe7123ee18d57c908c61e263ab840895bc51035a97fe9979d77373c880b04bdc1aa6fd6e14bbe5d038818b41f4db31e44ecaa8714ebe53efef1fed16cf3
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
'Copyright (c) <2016> <Daniel Rainey>
|
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.txt
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
'Copyright (c) <2016> <Daniel Rainey>
|
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/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,37 @@
|
|
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
|
+
require_relative '../lib/studio_game/player'
|
7
|
+
|
8
|
+
player1 = StudioGame::Player.new("moe")
|
9
|
+
player2 = StudioGame::Player.new("larry", 60)
|
10
|
+
player3 = StudioGame::Player.new("curly", 125)
|
11
|
+
klutz = StudioGame::ClumsyPlayer.new ("klutz")
|
12
|
+
berserker = StudioGame::BerserkPlayer.new ('berserker')
|
13
|
+
|
14
|
+
knuckleheads = StudioGame::Game.new ("knuckleheads")
|
15
|
+
knuckleheads.add_players(klutz)
|
16
|
+
knuckleheads.add_players(berserker)
|
17
|
+
|
18
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
19
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
20
|
+
loop do
|
21
|
+
puts "\nHow many rounds? ('quit' to exit)"
|
22
|
+
answer = gets.chomp.downcase
|
23
|
+
case answer
|
24
|
+
when /^\d+$/
|
25
|
+
knuckleheads.play(answer.to_i)
|
26
|
+
when 'quit', 'exit'
|
27
|
+
knuckleheads.print_stats
|
28
|
+
break
|
29
|
+
else
|
30
|
+
puts "Please enter a number or 'quit'"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
knuckleheads.save_high_scores
|
35
|
+
|
36
|
+
|
37
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
class BerserkPlayer < Player
|
6
|
+
|
7
|
+
def initialize (name, health = 100)
|
8
|
+
super (name)
|
9
|
+
@heal_count = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def berserk?
|
13
|
+
@heal_count >5
|
14
|
+
end
|
15
|
+
|
16
|
+
def heal
|
17
|
+
super
|
18
|
+
@heal_count += 1
|
19
|
+
puts "#{@name} is berserk!" if berserk?
|
20
|
+
end
|
21
|
+
|
22
|
+
def slash
|
23
|
+
if berserk?
|
24
|
+
heal
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
if __FILE__ == $0
|
33
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
34
|
+
6.times { berserker.heal }
|
35
|
+
2.times {berserker.slash}
|
36
|
+
puts berserker.health
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
class ClumsyPlayer < Player
|
6
|
+
|
7
|
+
def found_treasure(treasure)
|
8
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
9
|
+
super(damaged_treasure)
|
10
|
+
puts "#{@name} found a #{treasure.name} worth #{points} points."
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
|
17
|
+
if __FILE__ == $0
|
18
|
+
clumsy = ClumsyPlayer.new("klutz")
|
19
|
+
|
20
|
+
hammer = Treasure.new(:hammer, 50)
|
21
|
+
clumsy.found_treasure(hammer)
|
22
|
+
clumsy.found_treasure(hammer)
|
23
|
+
clumsy.found_treasure(hammer)
|
24
|
+
|
25
|
+
crowbar = Treasure.new(:crowbar, 400)
|
26
|
+
clumsy.found_treasure(crowbar)
|
27
|
+
|
28
|
+
clumsy.each_found_treasure do |treasure|
|
29
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
30
|
+
end
|
31
|
+
puts "#{clumsy.points} grand total points"
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'gameturn'
|
4
|
+
require_relative 'treasure_trove'
|
5
|
+
module StudioGame
|
6
|
+
|
7
|
+
class Game
|
8
|
+
|
9
|
+
def initialize(title)
|
10
|
+
@title = title.capitalize
|
11
|
+
@players = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_players(a_player)
|
15
|
+
@players.push(a_player)
|
16
|
+
end
|
17
|
+
|
18
|
+
def load_players(from_file)
|
19
|
+
File.readlines(from_file).each do |line|
|
20
|
+
name, health = line.split(',')
|
21
|
+
player = Player.new(name, Integer(health))
|
22
|
+
add_players(player)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def save_high_scores(to_file="high_scores.txt")
|
27
|
+
File.open(to_file, "w") do |file|
|
28
|
+
file.puts "#{@title} High Scores:"
|
29
|
+
@players.sort.each do |player|
|
30
|
+
formatted_name = player.name.ljust(20, '.')
|
31
|
+
file.puts "#{formatted_name} #{player.score}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def play(rounds)
|
37
|
+
puts "There are #{@players.size} players in the #{@title}:"
|
38
|
+
|
39
|
+
treasures= TreasureTrove::TREASURES
|
40
|
+
|
41
|
+
puts "\nThere are #{treasures.size} treasures to be found."
|
42
|
+
treasures.each do |treasures|
|
43
|
+
puts "A #{treasures.name}, worth #{treasures.points}."
|
44
|
+
end
|
45
|
+
|
46
|
+
1.upto(rounds) do |round|
|
47
|
+
puts "\nRound #{round}:"
|
48
|
+
@players.each do |player|
|
49
|
+
GameTurn.take_turn(player)
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def print_stats
|
56
|
+
strong_players, wimpy_players = @players.partition {|player| player.strong?}
|
57
|
+
puts "\n #{@title} Player Ranking:"
|
58
|
+
|
59
|
+
puts "\n #{strong_players.size} strong players:"
|
60
|
+
strong_players.each do |player|
|
61
|
+
puts "#{player.name} (#{player.health})"
|
62
|
+
end
|
63
|
+
puts "\n #{wimpy_players.size} wimpy players:"
|
64
|
+
wimpy_players.each do |player|
|
65
|
+
puts "#{player.name} (#{player.health})"
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "\n #{@title} Highscores:"
|
69
|
+
@players.sort.each do |player|
|
70
|
+
formatted_name = player.name.ljust(20, '.')
|
71
|
+
puts "#{formatted_name} #{player.score}"
|
72
|
+
end
|
73
|
+
|
74
|
+
@players.sort.each do |player|
|
75
|
+
puts "\n#{player.name}'s point totals:"
|
76
|
+
player.each_found_treasure do |treasure|
|
77
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
78
|
+
|
79
|
+
end
|
80
|
+
puts "#{player.points} grand total points"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'player'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
require_relative 'game'
|
5
|
+
require_relative 'loaded_die'
|
6
|
+
require_relative 'auditable'
|
7
|
+
|
8
|
+
module StudioGame
|
9
|
+
|
10
|
+
module GameTurn
|
11
|
+
|
12
|
+
include Auditable
|
13
|
+
|
14
|
+
def self.take_turn(player)
|
15
|
+
die = Die.new
|
16
|
+
case die.roll
|
17
|
+
when 1..2
|
18
|
+
player.slash
|
19
|
+
when 3..4
|
20
|
+
puts "#{player} was skipped."
|
21
|
+
when 5..6
|
22
|
+
player.heal
|
23
|
+
else
|
24
|
+
puts 'die was not rolled.'
|
25
|
+
end
|
26
|
+
|
27
|
+
treasure = TreasureTrove.random
|
28
|
+
player.found_treasure(treasure)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
|
6
|
+
class Player
|
7
|
+
include Playable
|
8
|
+
|
9
|
+
attr_reader :health
|
10
|
+
attr_accessor :name
|
11
|
+
|
12
|
+
def initialize(name, health = 100)
|
13
|
+
@name = name.capitalize
|
14
|
+
@health = health
|
15
|
+
@found_treasure = Hash.new(0)
|
16
|
+
end
|
17
|
+
|
18
|
+
def found_treasure(treasure)
|
19
|
+
@found_treasure[treasure.name] += treasure.points
|
20
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points!"
|
21
|
+
puts "#{@name}'s Treasures: #{treasure}"
|
22
|
+
end
|
23
|
+
|
24
|
+
def points
|
25
|
+
@found_treasure.values.reduce(0, :+)
|
26
|
+
end
|
27
|
+
|
28
|
+
def score
|
29
|
+
@health + points
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s
|
33
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
34
|
+
end
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
def change_name(new_name)
|
39
|
+
@name = new_name.capitalize
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
def <=>(other)
|
45
|
+
other.score <=> score
|
46
|
+
end
|
47
|
+
|
48
|
+
def each_found_treasure
|
49
|
+
@found_treasure.each do |name, points|
|
50
|
+
yield Treasure.new(name, points)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end # player class
|
55
|
+
|
56
|
+
if __FILE__ ==$0
|
57
|
+
|
58
|
+
player = Player.new ('moe')
|
59
|
+
puts player.name
|
60
|
+
puts player.health
|
61
|
+
player.heal
|
62
|
+
puts player.health
|
63
|
+
player.slash
|
64
|
+
puts player.health
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Treasure = Struct.new(:name, :points)
|
2
|
+
|
3
|
+
module TreasureTrove
|
4
|
+
def self.random
|
5
|
+
TREASURES.sample
|
6
|
+
end
|
7
|
+
TREASURES = [
|
8
|
+
Treasure.new(:pie, 5),
|
9
|
+
Treasure.new(:bottle, 25),
|
10
|
+
Treasure.new(:hammer, 50),
|
11
|
+
Treasure.new(:skillet, 100),
|
12
|
+
Treasure.new(:broomstick, 200),
|
13
|
+
Treasure.new(:crowbar, 400)
|
14
|
+
]
|
15
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe BerserkPlayer do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@initial_health = 100
|
9
|
+
@player = BerserkPlayer.new("berserker", @initial_health)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "does not go berserk when w00ted up to 5 times" do
|
13
|
+
1.upto(5) { @player.slash }
|
14
|
+
|
15
|
+
@player.berserk?.should be_false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "goes berserk when w00ted more than 5 times" do
|
19
|
+
1.upto(6) { @player.heal }
|
20
|
+
|
21
|
+
@player.berserk?.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
25
|
+
1.upto(6) { @player.heal }
|
26
|
+
1.upto(2) { @player.slash }
|
27
|
+
|
28
|
+
@player.health.should == @initial_health + (8 * 15)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe ClumsyPlayer do
|
6
|
+
before do
|
7
|
+
@player = ClumsyPlayer.new("klutz")
|
8
|
+
end
|
9
|
+
|
10
|
+
it "only gets half the point value for each treasure" do
|
11
|
+
@player.points.should == 0
|
12
|
+
|
13
|
+
hammer = Treasure.new(:hammer, 50)
|
14
|
+
@player.found_treasure(hammer)
|
15
|
+
@player.found_treasure(hammer)
|
16
|
+
@player.found_treasure(hammer)
|
17
|
+
|
18
|
+
@player.points.should == 75
|
19
|
+
|
20
|
+
crowbar = Treasure.new(:crowbar, 400)
|
21
|
+
|
22
|
+
@player.found_treasure(crowbar)
|
23
|
+
|
24
|
+
@player.points.should == 275
|
25
|
+
|
26
|
+
yielded = []
|
27
|
+
@player.each_found_treasure do |treasure|
|
28
|
+
yielded << treasure
|
29
|
+
end
|
30
|
+
|
31
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe Game do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@game = Game.new('knuckleheads')
|
9
|
+
|
10
|
+
@initial_health = 100
|
11
|
+
@player = Player.new("moe", @initial_health)
|
12
|
+
|
13
|
+
@game.add_players(@player)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "heals the player if a high number is rolled" do
|
17
|
+
Die.any_instance.stub(:roll).and_return(5)
|
18
|
+
|
19
|
+
@game.play(2)
|
20
|
+
@player.health.should == @initial_health + (15 * 2)
|
21
|
+
end
|
22
|
+
|
23
|
+
it "skips the player if a medium number is rolled" do
|
24
|
+
Die.any_instance.stub(:roll).and_return(3)
|
25
|
+
@game.play(2)
|
26
|
+
@player.health.should == @initial_health
|
27
|
+
end
|
28
|
+
|
29
|
+
it "slashes the player if a low number is rolled" do
|
30
|
+
Die.any_instance.stub(:roll).and_return(1)
|
31
|
+
@game.play(2)
|
32
|
+
@player.health.should == @initial_health - (10 * 2)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "assigns a treasure for points during a player's turn" do
|
36
|
+
game = Game.new("Knuckleheads")
|
37
|
+
player = Player.new("moe")
|
38
|
+
|
39
|
+
game.add_players(player)
|
40
|
+
|
41
|
+
game.play(1)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
|
6
|
+
describe Player do
|
7
|
+
|
8
|
+
before do
|
9
|
+
$stdout = StringIO.new
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
@player = Player.new('larry')
|
14
|
+
@initial_health = 100
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has a capitalized name" do
|
18
|
+
player = Player.new ("larry")
|
19
|
+
|
20
|
+
player.name.should == "Larry"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "has an initial health" do
|
24
|
+
@player.health.should == 100
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a string representation" do
|
28
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
29
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
30
|
+
|
31
|
+
@player.to_s.should == "I'm Larry with health = 100, points = 100, and score = 200."
|
32
|
+
end
|
33
|
+
|
34
|
+
it "computes a score as the sum of its health and points" do
|
35
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
36
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
37
|
+
|
38
|
+
@player.score.should == 200
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
it "increases health by 15 when healed" do
|
43
|
+
@player.heal
|
44
|
+
|
45
|
+
@player.health.should == @initial_health + 15
|
46
|
+
end
|
47
|
+
|
48
|
+
it "decreases health by 10 when slashed" do
|
49
|
+
@player.slash
|
50
|
+
|
51
|
+
@player.health.should == @initial_health - 10
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with a health greater than 100" do
|
55
|
+
before do
|
56
|
+
@player = Player.new('larry', 150)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "is strong" do
|
60
|
+
@player.strong?.should be_true
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
context "with a health less than 100" do
|
65
|
+
before do
|
66
|
+
@player = Player.new('larry', 99)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "is weak" do
|
70
|
+
@player.strong?.should be_false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "in a collection of players" do
|
75
|
+
before do
|
76
|
+
@player1 = Player.new("moe", 100)
|
77
|
+
@player2 = Player.new("larry", 200)
|
78
|
+
@player3 = Player.new("curly", 300)
|
79
|
+
|
80
|
+
@players = [@player1, @player2, @player3]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "is sorted by decreasing score" do
|
84
|
+
@players.sort.should == [@player3, @player2, @player1]
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "computes points as the sum of all treasure points" do
|
89
|
+
@player1 = Player.new('larry')
|
90
|
+
|
91
|
+
@player1.points.should == 0
|
92
|
+
|
93
|
+
@player1.found_treasure(Treasure.new(:hammer, 50))
|
94
|
+
|
95
|
+
@player1.points.should == 50
|
96
|
+
|
97
|
+
@player1.found_treasure(Treasure.new(:crowbar, 400))
|
98
|
+
|
99
|
+
@player1.points.should == 450
|
100
|
+
|
101
|
+
@player1.found_treasure(Treasure.new(:hammer, 50))
|
102
|
+
|
103
|
+
@player1.points.should == 500
|
104
|
+
end
|
105
|
+
it "yields each found treasure and its total points" do
|
106
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
107
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
108
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
109
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
110
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
111
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
112
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
113
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
114
|
+
|
115
|
+
yielded = []
|
116
|
+
@player.each_found_treasure do |treasure|
|
117
|
+
yielded << treasure
|
118
|
+
end
|
119
|
+
|
120
|
+
yielded.should == [
|
121
|
+
Treasure.new(:skillet, 200),
|
122
|
+
Treasure.new(:hammer, 50),
|
123
|
+
Treasure.new(:bottle, 25)
|
124
|
+
]
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require'studio_game/treasure_trove'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Treasure do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@treasure = Treasure.new(:hammer, 50)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name attribute" do
|
11
|
+
@treasure.name.should == :hammer
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a points attribute" do
|
15
|
+
@treasure.points.should == 50
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe TreasureTrove do
|
21
|
+
|
22
|
+
it "has six treasures" do
|
23
|
+
TreasureTrove::TREASURES.size.should == 6
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a pie worth 5 points" do
|
27
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a bottle worth 25 points" do
|
31
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a hammer worth 50 points" do
|
35
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a skillet worth 100 points" do
|
39
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a broomstick worth 200 points" do
|
43
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a crowbar worth 400 points" do
|
47
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
48
|
+
end
|
49
|
+
it "returns a random treasure" do
|
50
|
+
treasure = TreasureTrove.random
|
51
|
+
|
52
|
+
TreasureTrove::TREASURES.should include(treasure)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dr_cello_studio_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Rainey
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-23 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
|
+
'Copyright (c) <2016> <Daniel Rainey>
|
29
|
+
|
30
|
+
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:
|
31
|
+
|
32
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
33
|
+
|
34
|
+
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.']
|
35
|
+
email: raineydjw@gmail.com
|
36
|
+
executables:
|
37
|
+
- studio_game
|
38
|
+
extensions: []
|
39
|
+
extra_rdoc_files: []
|
40
|
+
files:
|
41
|
+
- bin/players.csv
|
42
|
+
- bin/studio_game
|
43
|
+
- lib/studio_game/auditable.rb
|
44
|
+
- lib/studio_game/berserk_player.rb
|
45
|
+
- lib/studio_game/clumsy_player.rb
|
46
|
+
- lib/studio_game/die.rb
|
47
|
+
- lib/studio_game/game.rb
|
48
|
+
- lib/studio_game/gameturn.rb
|
49
|
+
- lib/studio_game/loaded_die.rb
|
50
|
+
- lib/studio_game/playable.rb
|
51
|
+
- lib/studio_game/player.rb
|
52
|
+
- lib/studio_game/treasure_trove.rb
|
53
|
+
- spec/studio_game/berserk_player_spec.rb
|
54
|
+
- spec/studio_game/clumsy_player_spec.rb
|
55
|
+
- spec/studio_game/game_spec.rb
|
56
|
+
- spec/studio_game/player_spec.rb
|
57
|
+
- spec/studio_game/treasuretrove_spec.rb
|
58
|
+
- LICENSE.txt
|
59
|
+
- README.txt
|
60
|
+
homepage: https://github.com/Raineydjw
|
61
|
+
licenses:
|
62
|
+
- MIT
|
63
|
+
metadata: {}
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '1.9'
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.0.14
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Simple random outcome adventure with treasure.
|
84
|
+
test_files:
|
85
|
+
- spec/studio_game/berserk_player_spec.rb
|
86
|
+
- spec/studio_game/clumsy_player_spec.rb
|
87
|
+
- spec/studio_game/game_spec.rb
|
88
|
+
- spec/studio_game/player_spec.rb
|
89
|
+
- spec/studio_game/treasuretrove_spec.rb
|