studio_game1064 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/players.csv +3 -0
- data/bin/players2.csv +3 -0
- data/bin/studio_game +48 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +38 -0
- data/lib/studio_game/clumsy_player.rb +30 -0
- data/lib/studio_game/die.rb +26 -0
- data/lib/studio_game/game.rb +99 -0
- data/lib/studio_game/game_turn.rb +28 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +62 -0
- data/lib/studio_game/treasure_trove.rb +19 -0
- data/spec/studio_game/berserk_player_spec.rb +36 -0
- data/spec/studio_game/clumsy_player_spec.rb +32 -0
- data/spec/studio_game/game_spec.rb +57 -0
- data/spec/studio_game/rspec_player.rb +126 -0
- data/spec/studio_game/treasure_trove_spec.rb +60 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 944d4f84ca4fb15f25b663f38ede6f55ee0d164d
|
4
|
+
data.tar.gz: aaf240d42369a9460de308600de10f322e19fccd
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9455c387489ba5f50a49ee636ce77dd6f7355fa70cf3cf8edf006b5a9ec46569ee820cebd18c8b5294d13556b3318c89521475954608a8be9f6d2afc76cd5991
|
7
|
+
data.tar.gz: ed4c75331bb2d46e386101db9777fe923af18e381c8fad7698739b2e3c46f61c65dc3d6422e0dc79ef4e36a38645d0dae1c938df578a574b794acf3c5797aab9
|
data/bin/players.csv
ADDED
data/bin/players2.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/studio_game/player'
|
4
|
+
require_relative '../lib/studio_game/game'
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
6
|
+
require_relative '../lib/studio_game/berserk_player'
|
7
|
+
|
8
|
+
|
9
|
+
player1 = StudioGame::Player.new("moe")
|
10
|
+
player2 = StudioGame::Player.new("larry", 60)
|
11
|
+
player3 = StudioGame::Player.new("Curly", 125)
|
12
|
+
player4 = StudioGame::Player.new("Alvin", 1000)
|
13
|
+
player5 = StudioGame::Player.new("Simon", 30000)
|
14
|
+
player6 = StudioGame::Player.new("theodore", 150)
|
15
|
+
klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
|
16
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
17
|
+
|
18
|
+
knuckleheads = StudioGame::Game.new("knuckleheads")
|
19
|
+
|
20
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
21
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
22
|
+
|
23
|
+
knuckleheads.add_player(klutz)
|
24
|
+
knuckleheads.add_player(berserker)
|
25
|
+
|
26
|
+
loop do
|
27
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
28
|
+
answer = gets.chomp.downcase
|
29
|
+
case answer
|
30
|
+
when /^\d+$/
|
31
|
+
knuckleheads.play(answer.to_i)
|
32
|
+
when 'quit', 'exit'
|
33
|
+
knuckleheads.print_stats
|
34
|
+
break
|
35
|
+
else
|
36
|
+
puts "Please enter number or type quit to exit"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
knuckleheads.save_high_scores
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
def initialize(name, health)
|
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
|
+
if berserk?
|
22
|
+
w00t
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
# or use the ternary operator:
|
28
|
+
# berserk? ? w00t : super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
if __FILE__ == $0
|
34
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
35
|
+
6.times { berserker.w00t }
|
36
|
+
2.times { berserker.blam }
|
37
|
+
puts berserker.health
|
38
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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.0)
|
7
|
+
super(damaged_treasure)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
if __FILE__ == $0
|
15
|
+
clumsy = ClumsyPlayer.new("klutz")
|
16
|
+
|
17
|
+
hammer = Treasure.new(:hammer, 50)
|
18
|
+
clumsy.found_treasure(hammer)
|
19
|
+
clumsy.found_treasure(hammer)
|
20
|
+
clumsy.found_treasure(hammer)
|
21
|
+
|
22
|
+
crowbar = Treasure.new(:crowbar, 400)
|
23
|
+
clumsy.found_treasure(crowbar)
|
24
|
+
|
25
|
+
clumsy.each_found_treasure do |treasure|
|
26
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
27
|
+
end
|
28
|
+
puts "#{clumsy.points} grand total points"
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,26 @@
|
|
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 = StudioGame::Die.new
|
23
|
+
puts die.roll
|
24
|
+
puts die.roll
|
25
|
+
puts die.roll
|
26
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'game_turn'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
class Game
|
7
|
+
|
8
|
+
attr_accessor :title
|
9
|
+
|
10
|
+
def initialize(title)
|
11
|
+
@title = title
|
12
|
+
@players = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_player(a_player)
|
16
|
+
@players.push(a_player)
|
17
|
+
end
|
18
|
+
|
19
|
+
def play(rounds)
|
20
|
+
puts "There are #{@players.size} players in #{@title}: "
|
21
|
+
|
22
|
+
@players.each do |player|
|
23
|
+
puts player
|
24
|
+
end
|
25
|
+
|
26
|
+
treasures = TreasureTrove::TREASURES
|
27
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
28
|
+
treasures.each do |treasure|
|
29
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
30
|
+
end
|
31
|
+
|
32
|
+
1.upto(rounds) do |round|
|
33
|
+
puts "\nRound #{round}:"
|
34
|
+
@players.each do |player|
|
35
|
+
GameTurn.take_turn(player)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def print_name_and_health(player)
|
41
|
+
puts "#{player.name} (#{player.health})"
|
42
|
+
end
|
43
|
+
|
44
|
+
def high_score_entry(player)
|
45
|
+
formatted_name = player.name.ljust(20, '.')
|
46
|
+
"#{formatted_name} #{player.score}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def total_points
|
50
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
51
|
+
end
|
52
|
+
|
53
|
+
def print_stats
|
54
|
+
puts "\n#{@title} Statistics:"
|
55
|
+
|
56
|
+
strong_players, wimpy_players = @players.partition { |player| player.strong? }
|
57
|
+
|
58
|
+
puts "\n#{strong_players.size} strong players:"
|
59
|
+
strong_players.each do |player|
|
60
|
+
print_name_and_health(player)
|
61
|
+
end
|
62
|
+
|
63
|
+
puts "\n#{wimpy_players.size} wimpy players:"
|
64
|
+
wimpy_players.each do |player|
|
65
|
+
print_name_and_health(player)
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "\n#{total_points} total points from treasures found"
|
69
|
+
@players.each do |player|
|
70
|
+
puts "\n#{player.name}'s point totals:"
|
71
|
+
player.each_found_treasure do |treasure|
|
72
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
73
|
+
end
|
74
|
+
puts "#{player.points} grand total points"
|
75
|
+
end
|
76
|
+
|
77
|
+
puts "\n#{@title} High Scores:"
|
78
|
+
@players.sort.each do |player|
|
79
|
+
puts high_score_entry(player)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_players(from_file)
|
84
|
+
File.readlines(from_file).each do |line|
|
85
|
+
add_player(Player.from_csv(line))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def save_high_scores(to_file="high_scores.txt")
|
90
|
+
File.open(to_file, "w") do |file|
|
91
|
+
file.puts "#{@title} High Scores:"
|
92
|
+
@players.sort.each do |player|
|
93
|
+
file.puts high_score_entry(player)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
@@ -0,0 +1,28 @@
|
|
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
|
+
|
19
|
+
treasure = TreasureTrove.random
|
20
|
+
player.found_treasure(treasure)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if __FILE__ == $0
|
26
|
+
player = StudioGame::Player.new("curly", 125)
|
27
|
+
StudioGame::GameTurn.take_turn(player)
|
28
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
|
7
|
+
attr_accessor :name
|
8
|
+
attr_reader :health
|
9
|
+
|
10
|
+
def initialize(name, health=100)
|
11
|
+
@name = name.capitalize
|
12
|
+
@health = health
|
13
|
+
@found_treasures = Hash.new(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
include Playable
|
17
|
+
|
18
|
+
def score
|
19
|
+
@health + points
|
20
|
+
end
|
21
|
+
|
22
|
+
def points
|
23
|
+
@found_treasures.values.reduce(0, :+)
|
24
|
+
end
|
25
|
+
|
26
|
+
def found_treasure(treasure)
|
27
|
+
@found_treasures[treasure.name] += treasure.points
|
28
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
29
|
+
end
|
30
|
+
|
31
|
+
def each_found_treasure
|
32
|
+
@found_treasures.each do |name, points|
|
33
|
+
next_treasure = Treasure.new(name, points)
|
34
|
+
yield next_treasure
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def <=>(other)
|
39
|
+
other.score <=> score
|
40
|
+
end
|
41
|
+
|
42
|
+
def to_s
|
43
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.from_csv(string)
|
47
|
+
name, health = string.split(',')
|
48
|
+
new(name, Integer(health))
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
if __FILE__ == $0
|
54
|
+
player = Player.new("moe")
|
55
|
+
puts player.name
|
56
|
+
puts player.health
|
57
|
+
player.w00t
|
58
|
+
puts player.health
|
59
|
+
player.blam
|
60
|
+
puts player.health
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
|
2
|
+
module StudioGame
|
3
|
+
Treasure = Struct.new(:name, :points)
|
4
|
+
|
5
|
+
module TreasureTrove
|
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,36 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
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
|
+
1.upto(5) { @player.w00t }
|
13
|
+
|
14
|
+
@player.berserk?.should be_false
|
15
|
+
|
16
|
+
# or if using Rspec 3.0:
|
17
|
+
# @player.berserk?.should be_falsey
|
18
|
+
end
|
19
|
+
|
20
|
+
it "goes berserk when w00ted more than 5 times" do
|
21
|
+
1.upto(6) { @player.w00t }
|
22
|
+
|
23
|
+
@player.berserk?.should be_true
|
24
|
+
|
25
|
+
# or if using Rspec 3.0:
|
26
|
+
# @player.berserk?.should be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
30
|
+
1.upto(6) { @player.w00t }
|
31
|
+
1.upto(2) { @player.blam }
|
32
|
+
|
33
|
+
@player.health.should == @initial_health + (8 * 15)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
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
|
+
@player.points.should == 0
|
11
|
+
|
12
|
+
hammer = Treasure.new(:hammer, 50)
|
13
|
+
@player.found_treasure(hammer)
|
14
|
+
@player.found_treasure(hammer)
|
15
|
+
@player.found_treasure(hammer)
|
16
|
+
|
17
|
+
@player.points.should == 75
|
18
|
+
|
19
|
+
crowbar = Treasure.new(:crowbar, 400)
|
20
|
+
@player.found_treasure(crowbar)
|
21
|
+
|
22
|
+
@player.points.should == 275
|
23
|
+
|
24
|
+
yielded = []
|
25
|
+
@player.each_found_treasure do |treasure|
|
26
|
+
yielded << treasure
|
27
|
+
end
|
28
|
+
|
29
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
|
3
|
+
module StudioGame
|
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 "has a title" do
|
16
|
+
expect(@game.title) == "Knuckleheads"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "w00ts the player if a high number is rolled" do
|
20
|
+
Die.any_instance.stub(:roll).and_return(5)
|
21
|
+
|
22
|
+
@game.play(2)
|
23
|
+
|
24
|
+
expect(@player.health) == @initial_health + (15 * 2)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "skips the player if a medium number is rolled" do
|
28
|
+
Die.any_instance.stub(:roll).and_return(3)
|
29
|
+
|
30
|
+
@game.play(2)
|
31
|
+
|
32
|
+
expect(@player.health) == @initial_health
|
33
|
+
end
|
34
|
+
|
35
|
+
it "blams the player if a low number is rolled" do
|
36
|
+
Die.any_instance.stub(:roll).and_return(1)
|
37
|
+
|
38
|
+
@game.play(2)
|
39
|
+
|
40
|
+
expect(@player.health) == @initial_health - (10 * 2)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "assigns a treasure for points during a player's turn" do
|
44
|
+
game = Game.new("Knuckleheads")
|
45
|
+
player = Player.new("moe")
|
46
|
+
|
47
|
+
game.add_player(player)
|
48
|
+
|
49
|
+
game.play(1)
|
50
|
+
|
51
|
+
player.points.should_not be_zero
|
52
|
+
|
53
|
+
# or use alternate expectation syntax:
|
54
|
+
# expect(player.points).not_to be_zero
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Player do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@initial_health = 150
|
8
|
+
@player = Player.new("larry", @initial_health)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a capitalized name" do
|
12
|
+
@player.name.should == "Larry"
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has an initial health" do
|
16
|
+
@player.health.should == 150
|
17
|
+
end
|
18
|
+
|
19
|
+
it "has a string representation" do
|
20
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
21
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
22
|
+
|
23
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
|
24
|
+
end
|
25
|
+
|
26
|
+
it "increases health by 15 when w00ted" do
|
27
|
+
@player.w00t
|
28
|
+
|
29
|
+
@player.health.should == @initial_health + 15
|
30
|
+
end
|
31
|
+
|
32
|
+
it "decreases health by 10 when blammed" do
|
33
|
+
@player.blam
|
34
|
+
|
35
|
+
@player.health.should == @initial_health - 10
|
36
|
+
end
|
37
|
+
|
38
|
+
context "created with a default health" do
|
39
|
+
before do
|
40
|
+
@player = Player.new("larry")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has a health of 100" do
|
44
|
+
@player.health.should == 100
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with a health greater than 100" do
|
49
|
+
before do
|
50
|
+
@player = Player.new("larry", 150)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "is strong" do
|
54
|
+
@player.should be_strong
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "with a health of 100 or less" do
|
59
|
+
before do
|
60
|
+
@player = Player.new("larry", 100)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "is wimpy" do
|
64
|
+
@player.should_not be_strong
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "in a collection of players" do
|
69
|
+
before do
|
70
|
+
@player1 = Player.new("moe", 100)
|
71
|
+
@player2 = Player.new("larry", 200)
|
72
|
+
@player3 = Player.new("curly", 300)
|
73
|
+
|
74
|
+
@players = [@player1, @player2, @player3]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is sorted by decreasing score" do
|
78
|
+
@players.sort.should == [@player3, @player2, @player1]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "computes a score as the sum of its health and points" do
|
83
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
84
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
85
|
+
|
86
|
+
@player.score.should == 250
|
87
|
+
end
|
88
|
+
|
89
|
+
it "computes points as the sum of all treasure points" do
|
90
|
+
@player.points.should == 0
|
91
|
+
|
92
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
93
|
+
|
94
|
+
@player.points.should == 50
|
95
|
+
|
96
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
97
|
+
|
98
|
+
@player.points.should == 450
|
99
|
+
|
100
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
101
|
+
|
102
|
+
@player.points.should == 500
|
103
|
+
end
|
104
|
+
it "yields each found treasure and its total points" do
|
105
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
106
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
107
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
108
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
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
|
+
|
114
|
+
yielded = []
|
115
|
+
@player.each_found_treasure do |treasure|
|
116
|
+
yielded << treasure
|
117
|
+
end
|
118
|
+
|
119
|
+
yielded.should == [
|
120
|
+
Treasure.new(:skillet, 200),
|
121
|
+
Treasure.new(:hammer, 50),
|
122
|
+
Treasure.new(:bottle, 25)
|
123
|
+
]
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,60 @@
|
|
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
|
+
|
50
|
+
it "returns a random treasure" do
|
51
|
+
treasure = TreasureTrove.random
|
52
|
+
|
53
|
+
TreasureTrove::TREASURES.should include(treasure)
|
54
|
+
|
55
|
+
# or use alternate expectation syntax:
|
56
|
+
# expect(TreasureTrove::TREASURES).to include(treasure)
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio_game1064
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- James Washington
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: My first ruby gem
|
14
|
+
email: jwash8711@yahoo.com
|
15
|
+
executables:
|
16
|
+
- studio_game
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/players.csv
|
21
|
+
- bin/players2.csv
|
22
|
+
- bin/studio_game
|
23
|
+
- lib/studio_game/auditable.rb
|
24
|
+
- lib/studio_game/berserk_player.rb
|
25
|
+
- lib/studio_game/clumsy_player.rb
|
26
|
+
- lib/studio_game/die.rb
|
27
|
+
- lib/studio_game/game.rb
|
28
|
+
- lib/studio_game/game_turn.rb
|
29
|
+
- lib/studio_game/loaded_die.rb
|
30
|
+
- lib/studio_game/playable.rb
|
31
|
+
- lib/studio_game/player.rb
|
32
|
+
- lib/studio_game/treasure_trove.rb
|
33
|
+
- spec/studio_game/berserk_player_spec.rb
|
34
|
+
- spec/studio_game/clumsy_player_spec.rb
|
35
|
+
- spec/studio_game/game_spec.rb
|
36
|
+
- spec/studio_game/rspec_player.rb
|
37
|
+
- spec/studio_game/treasure_trove_spec.rb
|
38
|
+
homepage: https://www.facebook.com/jwash12
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.9'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubyforge_project:
|
58
|
+
rubygems_version: 2.4.8
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: random text game
|
62
|
+
test_files:
|
63
|
+
- spec/studio_game/berserk_player_spec.rb
|
64
|
+
- spec/studio_game/clumsy_player_spec.rb
|
65
|
+
- spec/studio_game/game_spec.rb
|
66
|
+
- spec/studio_game/rspec_player.rb
|
67
|
+
- spec/studio_game/treasure_trove_spec.rb
|