studio-game 1.0.3
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 +0 -0
- data/README +0 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +34 -0
- data/lib/studio_game/auditable.rb +9 -0
- data/lib/studio_game/berserk_player.rb +23 -0
- data/lib/studio_game/clumsy_player.rb +22 -0
- data/lib/studio_game/dice.rb +17 -0
- data/lib/studio_game/game.rb +101 -0
- data/lib/studio_game/game_turn.rb +27 -0
- data/lib/studio_game/loaded_die.rb +18 -0
- data/lib/studio_game/playable.rb +24 -0
- data/lib/studio_game/player.rb +65 -0
- data/lib/studio_game/treasure_trove.rb +19 -0
- data/spec/studio_game/berserk_player_spec.rb +38 -0
- data/spec/studio_game/clumsy_player_spec.rb +51 -0
- data/spec/studio_game/game_spec.rb +62 -0
- data/spec/studio_game/player_spec.rb +157 -0
- data/spec/studio_game/treasure_trove_spec.rb +56 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8fd943818dd7de0eaf4e6f3ec6dc646bdea481d2
|
4
|
+
data.tar.gz: 77271281bf4e2093c5152daa692ff04045e335eb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 415b1bc4b241e41f0a64aa3c938c9258070eacfcfaede086a7177e7dd680dac68ea4dbf3fd7d3e52277831887356a216053d4d4415c920acfb634917ccc26c75
|
7
|
+
data.tar.gz: d22897cdf157a6b7774338118fb2d87ab66e19ee94f0aaf48c36b38316a890d5389d07a444e5e75e6a40b4da59e51335a3e38b4d302f23a951463becc6a9f9ac
|
data/LICENSE
ADDED
File without changes
|
data/README
ADDED
File without changes
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative "../lib/studio_game/game"
|
3
|
+
player1 = StudioGame::Player.new("moe")
|
4
|
+
player2 = StudioGame::Player.new("larry", 60)
|
5
|
+
player3 = StudioGame::Player.new("curly", 125)
|
6
|
+
player4 = StudioGame::ClumsyPlayer.new("klutz",10)
|
7
|
+
player5 = StudioGame::BerserkPlayer.new("berserker")
|
8
|
+
|
9
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
10
|
+
knuckleheads.add_player(player1)
|
11
|
+
knuckleheads.add_player(player2)
|
12
|
+
knuckleheads.add_player(player3)
|
13
|
+
knuckleheads.add_player(player4)
|
14
|
+
knuckleheads.add_player(player5)
|
15
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
16
|
+
knuckleheads.load(ARGV.shift || default_player_file)
|
17
|
+
|
18
|
+
loop do
|
19
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
20
|
+
answer = gets.chomp.downcase
|
21
|
+
case answer
|
22
|
+
when /^\d+$/
|
23
|
+
knuckleheads.play(answer.to_i)
|
24
|
+
when "quit","exit"
|
25
|
+
knuckleheads.print_stats
|
26
|
+
knuckleheads.high_scores
|
27
|
+
break
|
28
|
+
else
|
29
|
+
puts "\nPlease enter number of rounds or 'quit'."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
knuckleheads.save_high_scores_to
|
34
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "player"
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
|
6
|
+
attr_accessor :blams,:woots
|
7
|
+
|
8
|
+
def initialize(name,health=100)
|
9
|
+
super(name,health)
|
10
|
+
@woots = 0
|
11
|
+
end
|
12
|
+
|
13
|
+
def w00t
|
14
|
+
@woots += 1
|
15
|
+
berserk? ? blam : super
|
16
|
+
end
|
17
|
+
|
18
|
+
def berserk?
|
19
|
+
@woots > 5 ? true : false
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "player"
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
|
6
|
+
attr_accessor :boost_factor
|
7
|
+
|
8
|
+
def initialize(name,boost_factor,health=100)
|
9
|
+
super(name,health)
|
10
|
+
@boost_factor = boost_factor
|
11
|
+
end
|
12
|
+
|
13
|
+
def found_treasure(treasure)
|
14
|
+
super(treasure,2)
|
15
|
+
end
|
16
|
+
|
17
|
+
def w00t
|
18
|
+
1.upto(@boost_factor) { @health += 15 }
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require_relative "player"
|
2
|
+
require_relative "clumsy_player"
|
3
|
+
require_relative "berserk_player"
|
4
|
+
require_relative "treasure_trove"
|
5
|
+
require_relative "game_turn"
|
6
|
+
|
7
|
+
module StudioGame
|
8
|
+
class Game
|
9
|
+
|
10
|
+
attr_reader :title
|
11
|
+
|
12
|
+
def initialize(title)
|
13
|
+
@title = title.capitalize
|
14
|
+
@players = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def load(players_from_csv="players.csv")
|
18
|
+
CSV.foreach(players_from_csv) do |row|
|
19
|
+
player = Player.new(row[0],Integer(row[1]))
|
20
|
+
add_player(player)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save_high_scores_to(filename="high_scores.txt")
|
25
|
+
File.open(filename,"w") do |file|
|
26
|
+
file.puts "#{@title} High Scores:"
|
27
|
+
@players.sort.each do |player|
|
28
|
+
file.puts high_score_entry(player)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_player(player)
|
34
|
+
@players << player
|
35
|
+
end
|
36
|
+
|
37
|
+
def play(rounds)
|
38
|
+
|
39
|
+
puts "There are #{TreasureTrove::TREASURES.length} treasures to be found."
|
40
|
+
TreasureTrove::TREASURES.each do |treasure|
|
41
|
+
puts "A #{treasure.name} is worth #{treasure.points}"
|
42
|
+
end
|
43
|
+
|
44
|
+
1.upto(rounds) do |round|
|
45
|
+
puts "\nRound #{round}."
|
46
|
+
@players.sort.each do |player|
|
47
|
+
GameTurn.take_turn(player)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def print_stats
|
53
|
+
puts "\n#{@title}'s Statistics:"
|
54
|
+
|
55
|
+
strong,wimpy = @players.partition {|player| player.strong? }
|
56
|
+
|
57
|
+
puts "Strong players:"
|
58
|
+
strong.sort.each do |player|
|
59
|
+
puts player.print_name_and_health
|
60
|
+
end
|
61
|
+
|
62
|
+
puts "\nWimpy players:"
|
63
|
+
wimpy.sort.each do |player|
|
64
|
+
puts player.print_name_and_health
|
65
|
+
end
|
66
|
+
|
67
|
+
@players.each do |player|
|
68
|
+
|
69
|
+
puts "#{player.name}'s point totals:"
|
70
|
+
|
71
|
+
player.each_found_treasure do |treasure|
|
72
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
73
|
+
end
|
74
|
+
|
75
|
+
puts "#{player.points} grand total points"
|
76
|
+
puts "\n"
|
77
|
+
end
|
78
|
+
|
79
|
+
puts "#{total_points} total points from treasures found."
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
def total_points
|
84
|
+
@players.reduce(0) do |sum,player|
|
85
|
+
sum + player.points
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def high_score_entry(player)
|
90
|
+
"#{player.name.ljust(20,".")} #{player.score}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def high_scores
|
94
|
+
puts "\n#{@title} High Scores:"
|
95
|
+
@players.sort.each do |player|
|
96
|
+
puts high_score_entry(player)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative "dice"
|
2
|
+
require_relative 'loaded_die'
|
3
|
+
require_relative "treasure_trove"
|
4
|
+
require_relative "player"
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
module GameTurn
|
8
|
+
|
9
|
+
def self.roll
|
10
|
+
dice = Dice.new
|
11
|
+
dice.roll
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.take_turn(player)
|
15
|
+
case self.roll
|
16
|
+
when 1..2
|
17
|
+
player.blam
|
18
|
+
when 3..4
|
19
|
+
puts "Nothing happened"
|
20
|
+
else
|
21
|
+
player.w00t
|
22
|
+
end
|
23
|
+
player.found_treasure(TreasureTrove::TREASURES.sample)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module StudioGame
|
2
|
+
module Playable
|
3
|
+
|
4
|
+
def w00t
|
5
|
+
self.health += 15
|
6
|
+
puts "#{self.name} was w00ted\n"
|
7
|
+
end
|
8
|
+
|
9
|
+
def blam
|
10
|
+
self.health -= 10
|
11
|
+
puts "#{self.name} was blammed\n"
|
12
|
+
end
|
13
|
+
|
14
|
+
def status
|
15
|
+
self.health > 100 ? "Strong" : "Wimpy"
|
16
|
+
end
|
17
|
+
|
18
|
+
def strong?
|
19
|
+
status == "Strong"
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "csv"
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
|
7
|
+
include Playable
|
8
|
+
|
9
|
+
attr_accessor :health, :name
|
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 each_found_treasure
|
18
|
+
@found_treasures.each do |name,points|
|
19
|
+
treasure = Treasure.new(name,points)
|
20
|
+
yield(treasure)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def score
|
25
|
+
@health + points
|
26
|
+
end
|
27
|
+
|
28
|
+
def to_s
|
29
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
30
|
+
end
|
31
|
+
|
32
|
+
def <=>(other_player)
|
33
|
+
other_player.score <=> score
|
34
|
+
end
|
35
|
+
|
36
|
+
def print_name_and_health
|
37
|
+
"#{@name} #{@health}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def print_stats
|
41
|
+
puts "#{@name}'s point totals"
|
42
|
+
puts "#{points} grand total points"
|
43
|
+
end
|
44
|
+
|
45
|
+
def format_treasure(treasure)
|
46
|
+
"#{treasure[0].to_s.capitalize.ljust(20,".")}#{treasure[1].to_s}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def points
|
50
|
+
@found_treasures.values.reduce(0,:+)
|
51
|
+
end
|
52
|
+
|
53
|
+
def found_treasure(treasure,value_divisor=1)
|
54
|
+
@found_treasures[treasure.name] += ( treasure.points / value_divisor )
|
55
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
56
|
+
puts "#{@name}'s treasures:"
|
57
|
+
if @found_treasures.empty?
|
58
|
+
puts "Not found any treasures yet."
|
59
|
+
else
|
60
|
+
@found_treasures.each { |k,v| puts "#{format_treasure([k,v])}" }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
Treasure = Struct.new(:name,:points)
|
2
|
+
|
3
|
+
module StudioGame
|
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
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe BerserkPlayer do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@initial_health = 100
|
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_falsey
|
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_truthy
|
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 + (5 * 15)) - (3 * 10))
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe ClumsyPlayer do
|
5
|
+
before do
|
6
|
+
@player = ClumsyPlayer.new("klutz",1)
|
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
|
+
|
32
|
+
context "with a boost factor" do
|
33
|
+
before do
|
34
|
+
@initial_health = 100
|
35
|
+
@boost_factor = 5
|
36
|
+
@player = ClumsyPlayer.new("klutz", @boost_factor, @initial_health)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a boost factor" do
|
40
|
+
@player.boost_factor.should == 5
|
41
|
+
end
|
42
|
+
|
43
|
+
it "gets boost factor number of w00ts when w00ted" do
|
44
|
+
@player.w00t
|
45
|
+
|
46
|
+
@player.health.should == @initial_health + (15 * @boost_factor)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require "studio_game/game"
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Game do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@game = Game.new("weeez cweeem")
|
8
|
+
@initial_health = 100
|
9
|
+
@player = Player.new("curly",@initial_health)
|
10
|
+
@game.add_player(@player)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "is played with a low roll 1 and returns 90" do
|
14
|
+
Dice.any_instance.stub(:roll).and_return(1)
|
15
|
+
GameTurn.take_turn(@player)
|
16
|
+
@player.health.should == 90
|
17
|
+
end
|
18
|
+
|
19
|
+
it "is played with a medium roll of 3 and returns 100" do
|
20
|
+
Dice.any_instance.stub(:roll).and_return(3)
|
21
|
+
GameTurn.take_turn(@player)
|
22
|
+
@player.health.should == 100
|
23
|
+
end
|
24
|
+
|
25
|
+
it "is played with a high roll of 6 and returns 115" do
|
26
|
+
Dice.any_instance.stub(:roll).and_return(6)
|
27
|
+
GameTurn.take_turn(@player)
|
28
|
+
@player.health.should == 115
|
29
|
+
end
|
30
|
+
|
31
|
+
it "assigns a treasure for points during a player's turn" do
|
32
|
+
game = Game.new("Knuckleheads")
|
33
|
+
player = Player.new("moe")
|
34
|
+
|
35
|
+
game.add_player(player)
|
36
|
+
|
37
|
+
game.play(1) do
|
38
|
+
game.total_points > 2000
|
39
|
+
end
|
40
|
+
|
41
|
+
player.points.should_not be_zero
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
it "computes total points as the sum of all player points" do
|
46
|
+
game = Game.new("Knuckleheads")
|
47
|
+
|
48
|
+
player1 = Player.new("moe")
|
49
|
+
player2 = Player.new("larry")
|
50
|
+
|
51
|
+
game.add_player(player1)
|
52
|
+
game.add_player(player2)
|
53
|
+
|
54
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
55
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
56
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
57
|
+
|
58
|
+
game.total_points.should == 500
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
require "studio_game/player"
|
2
|
+
require "studio_game/treasure_trove"
|
3
|
+
|
4
|
+
$stdout = StringIO.new
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
describe Player do
|
8
|
+
|
9
|
+
context "created with an initial health of 60" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
@initial_health = 150
|
13
|
+
@player = Player.new("larry",@initial_health)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has an initial health of 75" do
|
17
|
+
@player.health.should == @initial_health
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has a string representation" do
|
21
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
22
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
23
|
+
|
24
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a score method which returns the health plus the accrued points of a player" do
|
28
|
+
@player.score.should == @initial_health + 0
|
29
|
+
end
|
30
|
+
|
31
|
+
it "computes a score as the sum of its health and points" do
|
32
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
33
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
34
|
+
|
35
|
+
@player.score.should == 250
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a w00t method which increases @health by 15" do
|
39
|
+
@player.w00t
|
40
|
+
@player.health.should == @initial_health + 15
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has a blam method which decreases @health by 10" do
|
44
|
+
@player.blam
|
45
|
+
@player.health.should == @initial_health - 10
|
46
|
+
end
|
47
|
+
|
48
|
+
it "has a name which is capitalized" do
|
49
|
+
@player.name.should == "Larry"
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
context "created with a default health of 100" do
|
55
|
+
|
56
|
+
before do
|
57
|
+
@player = Player.new("phil")
|
58
|
+
end
|
59
|
+
|
60
|
+
it "has a default health of 100" do
|
61
|
+
@player.health.should == 100
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
context "created with a health of 150" do
|
67
|
+
|
68
|
+
before do
|
69
|
+
@player = Player.new("phil",150)
|
70
|
+
end
|
71
|
+
|
72
|
+
it "has a status of strong" do
|
73
|
+
@player.status.should == "Strong"
|
74
|
+
end
|
75
|
+
|
76
|
+
it "has a strong? value of true" do
|
77
|
+
@player.should be_strong
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context "created with a health of 100" do
|
83
|
+
before do
|
84
|
+
@player = Player.new("phil",100)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "has a status of weak" do
|
88
|
+
@player.status.should == "Wimpy"
|
89
|
+
end
|
90
|
+
|
91
|
+
it "has a strong? state of false" do
|
92
|
+
@player.should_not be_strong
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "created with a health of 100, 200 and 300" do
|
97
|
+
before do
|
98
|
+
@player1 = Player.new("moe", 100)
|
99
|
+
@player2 = Player.new("larry", 200)
|
100
|
+
@player3 = Player.new("curly", 300)
|
101
|
+
@players = [@player1, @player2, @player3]
|
102
|
+
end
|
103
|
+
|
104
|
+
it "is sorted by decreasing score" do
|
105
|
+
@players.sort.should == [@player3, @player2, @player1]
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "created to test @found_treasure hash" do
|
110
|
+
|
111
|
+
before do
|
112
|
+
@player = Player.new("phil")
|
113
|
+
end
|
114
|
+
|
115
|
+
it "computes points as the sum of all treasure points" do
|
116
|
+
@player.points.should == 0
|
117
|
+
|
118
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
119
|
+
|
120
|
+
@player.points.should == 50
|
121
|
+
|
122
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
123
|
+
|
124
|
+
@player.points.should == 450
|
125
|
+
|
126
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
127
|
+
|
128
|
+
@player.points.should == 500
|
129
|
+
end
|
130
|
+
|
131
|
+
it "yields each found treasure and its total points" do
|
132
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
133
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
134
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
135
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
136
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
137
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
138
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
139
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
140
|
+
|
141
|
+
yielded = []
|
142
|
+
@player.each_found_treasure do |treasure|
|
143
|
+
yielded << treasure
|
144
|
+
end
|
145
|
+
|
146
|
+
yielded.should == [
|
147
|
+
Treasure.new(:skillet, 200),
|
148
|
+
Treasure.new(:hammer, 50),
|
149
|
+
Treasure.new(:bottle, 25)
|
150
|
+
]
|
151
|
+
|
152
|
+
yielded.sample.class.should == Treasure
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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
|
+
TreasureTrove::TREASURES.should include(treasure)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio-game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- William Fish
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-24 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
|
+
email: support@william.fish
|
29
|
+
executables:
|
30
|
+
- studio_game
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- bin/players.csv
|
35
|
+
- bin/studio_game
|
36
|
+
- lib/studio_game/auditable.rb
|
37
|
+
- lib/studio_game/berserk_player.rb
|
38
|
+
- lib/studio_game/clumsy_player.rb
|
39
|
+
- lib/studio_game/dice.rb
|
40
|
+
- lib/studio_game/game.rb
|
41
|
+
- lib/studio_game/game_turn.rb
|
42
|
+
- lib/studio_game/loaded_die.rb
|
43
|
+
- lib/studio_game/playable.rb
|
44
|
+
- lib/studio_game/player.rb
|
45
|
+
- lib/studio_game/treasure_trove.rb
|
46
|
+
- spec/studio_game/berserk_player_spec.rb
|
47
|
+
- spec/studio_game/clumsy_player_spec.rb
|
48
|
+
- spec/studio_game/game_spec.rb
|
49
|
+
- spec/studio_game/player_spec.rb
|
50
|
+
- spec/studio_game/treasure_trove_spec.rb
|
51
|
+
- LICENSE
|
52
|
+
- README
|
53
|
+
homepage: http://pragmaticstudio.com
|
54
|
+
licenses: []
|
55
|
+
metadata: {}
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '1.9'
|
65
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 2.0.14
|
73
|
+
signing_key:
|
74
|
+
specification_version: 4
|
75
|
+
summary: A game in which players find treasure and receive a ranking at the end.
|
76
|
+
test_files:
|
77
|
+
- spec/studio_game/berserk_player_spec.rb
|
78
|
+
- spec/studio_game/clumsy_player_spec.rb
|
79
|
+
- spec/studio_game/game_spec.rb
|
80
|
+
- spec/studio_game/player_spec.rb
|
81
|
+
- spec/studio_game/treasure_trove_spec.rb
|