studio_game_UK 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +7 -0
- data/README +1 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +31 -0
- data/bin/super_heros.csv +4 -0
- data/lib/studio_game/Die.rb +21 -0
- data/lib/studio_game/auditable.rb +10 -0
- data/lib/studio_game/berserk_player.rb +29 -0
- data/lib/studio_game/clumsy_player.rb +19 -0
- data/lib/studio_game/game.rb +91 -0
- data/lib/studio_game/game_turn.rb +26 -0
- data/lib/studio_game/iterators.rb +39 -0
- data/lib/studio_game/loaded_die.rb +15 -0
- data/lib/studio_game/movie.rb +23 -0
- data/lib/studio_game/playable.rb +28 -0
- data/lib/studio_game/player.rb +73 -0
- data/lib/studio_game/treasure_trove.rb +21 -0
- data/spec/berserk_player_spec.rb +32 -0
- data/spec/clumsy_player_spec.rb +41 -0
- data/spec/game_spec.rb +46 -0
- data/spec/player_spec.rb +115 -0
- data/spec/treasure_trove_spec.rb +31 -0
- metadata +83 -0
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) <year> <copyright holders>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Role playing game with auditing
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/studio_game/game'
|
4
|
+
require_relative '../lib/studio_game/clumsy_player'
|
5
|
+
require_relative '../lib/studio_game/berserk_player'
|
6
|
+
|
7
|
+
game = StudioGame::Game.new("Knuckleheads")
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__),'players.csv')
|
9
|
+
game.load_players(ARGV.shift || default_player_file)
|
10
|
+
|
11
|
+
berserker = StudioGame::BerserkPlayer.new('berserker',50)
|
12
|
+
game.add_player(berserker)
|
13
|
+
|
14
|
+
clumsy = StudioGame::ClumsyPlayer.new('clumsy',75)
|
15
|
+
game.add_player(clumsy)
|
16
|
+
|
17
|
+
loop do
|
18
|
+
puts "how many rounds? ('quit' to exit)"
|
19
|
+
answer = gets.chomp.downcase
|
20
|
+
case answer
|
21
|
+
when /^\d+$/
|
22
|
+
game.play(answer.to_i)
|
23
|
+
when 'quit','exit'
|
24
|
+
game.print_stats
|
25
|
+
break
|
26
|
+
else
|
27
|
+
puts "Please enter a number or quit."
|
28
|
+
end
|
29
|
+
|
30
|
+
game.save
|
31
|
+
end
|
data/bin/super_heros.csv
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
class BerserkPlayer < Player
|
6
|
+
|
7
|
+
def initialize(name,health)
|
8
|
+
super(name,health)
|
9
|
+
@w00t_count = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
def w00t
|
13
|
+
super
|
14
|
+
@w00t_count += 1
|
15
|
+
end
|
16
|
+
|
17
|
+
def blam
|
18
|
+
if berserk?
|
19
|
+
w00t
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def berserk?
|
26
|
+
@w00t_count > 5
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
module StudioGame
|
3
|
+
class ClumsyPlayer < Player
|
4
|
+
|
5
|
+
def initialize(name,health,boost_factor=5)
|
6
|
+
super(name,health)
|
7
|
+
@boost_factor = boost_factor
|
8
|
+
end
|
9
|
+
|
10
|
+
def found_treasure(treasure)
|
11
|
+
super(Treasure.new(treasure.name,treasure.points/2))
|
12
|
+
end
|
13
|
+
|
14
|
+
def w00t
|
15
|
+
@boost_factor.times { super }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'berserk_player'
|
3
|
+
require_relative 'clumsy_player'
|
4
|
+
require_relative 'game_turn'
|
5
|
+
require_relative 'treasure_trove'
|
6
|
+
|
7
|
+
module StudioGame
|
8
|
+
|
9
|
+
class Game
|
10
|
+
|
11
|
+
attr_reader :title
|
12
|
+
|
13
|
+
|
14
|
+
def initialize(title)
|
15
|
+
@title = title
|
16
|
+
@players = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def load_players(filename="players.csv")
|
20
|
+
File.readlines(filename).each do |line|
|
21
|
+
add_player(Player.from_csv(line))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def save(to_file="high_scores.txt")
|
26
|
+
File.open(to_file,"w") do |file|
|
27
|
+
file.puts "#{@title} High Scores:"
|
28
|
+
@players.each do |player|
|
29
|
+
file.puts player.to_csv
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def add_player(player)
|
35
|
+
@players << player
|
36
|
+
end
|
37
|
+
|
38
|
+
def play(rounds)
|
39
|
+
puts "There are #{@players.size} players in #{@title}"
|
40
|
+
puts @players
|
41
|
+
|
42
|
+
puts "\nThere are #{TreasureTrove::TREASURES.size} treasures to be found:"
|
43
|
+
TreasureTrove::TREASURES.each do |t|
|
44
|
+
puts "A #{t.name} is worth #{t.points}"
|
45
|
+
end
|
46
|
+
|
47
|
+
1.upto(rounds) do |round|
|
48
|
+
puts "\nRound #{round}:"
|
49
|
+
@players.each do |p|
|
50
|
+
GameTurn.take_turn(p)
|
51
|
+
puts p
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def wimpy_players
|
57
|
+
@players.reject { |p| p.strong? }
|
58
|
+
end
|
59
|
+
|
60
|
+
def strong_players
|
61
|
+
@players.reject { |p| !p.strong?}
|
62
|
+
end
|
63
|
+
|
64
|
+
def total_points
|
65
|
+
@players.reduce(0) {|sum,player| sum + player.points}
|
66
|
+
end
|
67
|
+
|
68
|
+
def print_stats
|
69
|
+
strongs,wimpies = @players.partition { |p| p.strong? }
|
70
|
+
puts "\n#{strongs.size} strong players:"
|
71
|
+
strongs.sort.each do |p|
|
72
|
+
p.print_name_and_health
|
73
|
+
end
|
74
|
+
|
75
|
+
puts "\n#{wimpies.size} wimpy players:"
|
76
|
+
wimpies.sort.each do |p|
|
77
|
+
p.print_name_and_health
|
78
|
+
end
|
79
|
+
|
80
|
+
@players.each do |p|
|
81
|
+
puts "\n#{p.name}'s point totals:"
|
82
|
+
puts "#{p.points} grand total points\n"
|
83
|
+
|
84
|
+
p.each_treasure do |treasure|
|
85
|
+
puts "#{treasure.name} totaled #{treasure.points}"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'loaded_die'
|
3
|
+
require_relative 'player'
|
4
|
+
require_relative 'treasure_trove'
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
module GameTurn
|
8
|
+
|
9
|
+
def self.take_turn(player)
|
10
|
+
die = Die.new
|
11
|
+
roll = die.roll
|
12
|
+
|
13
|
+
case die.roll
|
14
|
+
when 1..2
|
15
|
+
player.blam
|
16
|
+
when 5..6
|
17
|
+
player.w00t
|
18
|
+
end
|
19
|
+
|
20
|
+
treasure = TreasureTrove.random
|
21
|
+
player.found_treasure(treasure)
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
def conversation
|
2
|
+
puts "Hello"
|
3
|
+
yield
|
4
|
+
puts "Goodbye"
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
conversation { puts "Good to meet you!"}
|
9
|
+
|
10
|
+
def five_times
|
11
|
+
|
12
|
+
1.upto(5) do |n|
|
13
|
+
yield(n)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
five_times do |n|
|
19
|
+
|
20
|
+
puts "#{n} situps"
|
21
|
+
puts "#{n} pushups"
|
22
|
+
puts "#{n} chinups"
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def n_times(number)
|
27
|
+
|
28
|
+
1.upto(number) do |n|
|
29
|
+
yield(n)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
n_times(6) do |n|
|
35
|
+
puts "#{n} situps"
|
36
|
+
puts "#{n} pushups"
|
37
|
+
puts "#{n} chinups"
|
38
|
+
end
|
39
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module StudioGame
|
2
|
+
|
3
|
+
class Movie
|
4
|
+
|
5
|
+
def initialize(name,rank)
|
6
|
+
@name = name.capitalize
|
7
|
+
@rank = rank
|
8
|
+
end
|
9
|
+
|
10
|
+
def to_s
|
11
|
+
puts "#{@name} has a rank of #{@rank}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def thumbs_up
|
15
|
+
@rank +=1
|
16
|
+
end
|
17
|
+
|
18
|
+
def thumbs_down
|
19
|
+
@rank -= 1
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module StudioGame
|
2
|
+
|
3
|
+
module Playable
|
4
|
+
|
5
|
+
def w00t
|
6
|
+
self.health += 15
|
7
|
+
puts "#{self.name} got w00ted!"
|
8
|
+
end
|
9
|
+
|
10
|
+
def blam
|
11
|
+
self.health -= 10
|
12
|
+
puts "#{self.name} got blammed"
|
13
|
+
end
|
14
|
+
|
15
|
+
def score
|
16
|
+
self.health + points
|
17
|
+
end
|
18
|
+
|
19
|
+
def strong?
|
20
|
+
self.health > 100 ? true : false
|
21
|
+
end
|
22
|
+
|
23
|
+
def <=>(other_player)
|
24
|
+
other_player.score <=> self.score
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
|
6
|
+
class Player
|
7
|
+
include Playable
|
8
|
+
|
9
|
+
attr_accessor :health
|
10
|
+
attr_accessor :name, :found_treasure
|
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 points
|
19
|
+
@found_treasure.values.reduce(0,:+)
|
20
|
+
end
|
21
|
+
|
22
|
+
def found_treasure(treasure)
|
23
|
+
@found_treasure[treasure.name] += treasure.points
|
24
|
+
puts "#{self.name} found a #{treasure.name} worth #{treasure.points} points"
|
25
|
+
puts "#{self.name}'s treasure: #{@found_treasure}"
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.from_csv(line)
|
29
|
+
name,health = line.split(",")
|
30
|
+
new(name,health.to_i)
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_csv
|
34
|
+
"#{@name.ljust(20,'.')}#{score}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
"I'm #{@name} with a health of #{@health} and score #{score}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def current_time
|
42
|
+
Time.new.strftime("%I:%M:%S")
|
43
|
+
end
|
44
|
+
|
45
|
+
def say_hello(name,health=10)
|
46
|
+
|
47
|
+
puts "I'm #{name} with a health of #{health} as of #{current_time}\n"
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_name_and_health
|
52
|
+
puts "#{self.name.ljust(20,".")}#{self.score}"
|
53
|
+
end
|
54
|
+
|
55
|
+
def each_treasure
|
56
|
+
@found_treasure.each do |name,points|
|
57
|
+
yield Treasure.new(name,points)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
if __FILE__ == $0
|
66
|
+
player = Player.new("moe")
|
67
|
+
puts player.name
|
68
|
+
puts player.health
|
69
|
+
player.w00t
|
70
|
+
puts player.health
|
71
|
+
player.blam
|
72
|
+
puts player.health
|
73
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module StudioGame
|
2
|
+
|
3
|
+
Treasure = Struct.new(:name,:points)
|
4
|
+
|
5
|
+
module TreasureTrove
|
6
|
+
|
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
|
+
|
16
|
+
def self.random
|
17
|
+
TREASURES.sample
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe BerserkPlayer do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@initial_health = 50
|
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.w00t }
|
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.w00t }
|
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.w00t }
|
26
|
+
1.upto(2) { @player.blam }
|
27
|
+
|
28
|
+
@player.health.should == @initial_health + (8 * 15)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe ClumsyPlayer do
|
6
|
+
before do
|
7
|
+
@player = ClumsyPlayer.new("klutz",50)
|
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
|
+
hammer.should_not be nil
|
15
|
+
@player.should_not be nil
|
16
|
+
|
17
|
+
@player.found_treasure(hammer)
|
18
|
+
@player.found_treasure(hammer)
|
19
|
+
@player.found_treasure(hammer)
|
20
|
+
|
21
|
+
@player.points.should == 75
|
22
|
+
|
23
|
+
crowbar = Treasure.new(:crowbar, 400)
|
24
|
+
@player.found_treasure(crowbar)
|
25
|
+
|
26
|
+
@player.points.should == 275
|
27
|
+
|
28
|
+
yielded = []
|
29
|
+
@player.each_treasure do |treasure|
|
30
|
+
yielded << treasure
|
31
|
+
end
|
32
|
+
|
33
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should w00t by a factor of 5" do
|
37
|
+
@player.w00t
|
38
|
+
@player.health.should == 125
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/spec/game_spec.rb
ADDED
@@ -0,0 +1,46 @@
|
|
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
|
+
@game.add_player(@player)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should w00t on a high roll" do
|
16
|
+
Die.any_instance.stub(:roll).and_return(5)
|
17
|
+
@game.play(2)
|
18
|
+
@player.health.should == @initial_health + (15*2)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should stay same on medium roll" do
|
22
|
+
Die.any_instance.stub(:roll).and_return(3)
|
23
|
+
@game.play(3)
|
24
|
+
@player.health.should == @initial_health
|
25
|
+
end
|
26
|
+
|
27
|
+
it "assigns a treasure for points during a player's turn" do
|
28
|
+
@game.play(1)
|
29
|
+
@player.points.should_not be_zero
|
30
|
+
end
|
31
|
+
|
32
|
+
it "computes total points as the sum of all players points" do
|
33
|
+
player2 = Player.new("larry")
|
34
|
+
|
35
|
+
@game.add_player(player2)
|
36
|
+
|
37
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
38
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
39
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
40
|
+
|
41
|
+
@game.total_points.should == 500
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
data/spec/player_spec.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe Player do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@initial_health = 90
|
9
|
+
@player = Player.new("larry",@initial_health)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a capitalized name" do
|
13
|
+
player = Player.new("larry",90)
|
14
|
+
player.name.should == "Larry"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has an initial health" do
|
18
|
+
@player.health.should == @initial_health
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has a string representation" do
|
22
|
+
@player.to_s.should == "I'm Larry with a health of #{@initial_health} and score #{@initial_health + @player.points}"
|
23
|
+
end
|
24
|
+
|
25
|
+
it "computes a score as the sum of its health and length of name" do
|
26
|
+
@player.score.should == @initial_health + @player.points
|
27
|
+
end
|
28
|
+
|
29
|
+
it "increase health by 15 when w00ted" do
|
30
|
+
@player.w00t
|
31
|
+
@player.health.should == @initial_health + 15
|
32
|
+
end
|
33
|
+
|
34
|
+
it "decreases health by 10 when blammed" do
|
35
|
+
@player.blam
|
36
|
+
@player.health.should == @initial_health - 10
|
37
|
+
end
|
38
|
+
|
39
|
+
context "player is wimpy" do
|
40
|
+
|
41
|
+
before do
|
42
|
+
@initial_health = 99
|
43
|
+
@player = Player.new("curly",@initial_health)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "is wimpy" do
|
47
|
+
@player.strong?.should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
context "player is strong" do
|
53
|
+
|
54
|
+
before do
|
55
|
+
@initial_health = 110
|
56
|
+
@player = Player.new("moe",110)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "is strong" do
|
60
|
+
@player.strong?.should be_true
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
it "computes points as the sum of all treasure points" do
|
66
|
+
@player.points.should == 0
|
67
|
+
|
68
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
69
|
+
|
70
|
+
@player.points.should == 50
|
71
|
+
|
72
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
73
|
+
|
74
|
+
@player.points.should == 450
|
75
|
+
|
76
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
77
|
+
|
78
|
+
@player.points.should == 500
|
79
|
+
end
|
80
|
+
|
81
|
+
it "yields each found treasure and its total points" do
|
82
|
+
@player.found_treasure(Treasure.new(:skillet,100))
|
83
|
+
@player.found_treasure(Treasure.new(:skillet,100))
|
84
|
+
@player.found_treasure(Treasure.new(:bottle,5))
|
85
|
+
@player.found_treasure(Treasure.new(:hammer,50))
|
86
|
+
|
87
|
+
yielded = []
|
88
|
+
@player.each_treasure do |treasure|
|
89
|
+
yielded << treasure
|
90
|
+
end
|
91
|
+
|
92
|
+
yielded.should == [
|
93
|
+
Treasure.new(:skillet,200),
|
94
|
+
Treasure.new(:bottle,5),
|
95
|
+
Treasure.new(:hammer,50)
|
96
|
+
]
|
97
|
+
end
|
98
|
+
|
99
|
+
context "in a collection of players" do
|
100
|
+
before do
|
101
|
+
@player1 = Player.new("moe", 100)
|
102
|
+
@player2 = Player.new("larry", 200)
|
103
|
+
@player3 = Player.new("curly", 300)
|
104
|
+
|
105
|
+
@players = [@player1, @player2, @player3]
|
106
|
+
end
|
107
|
+
|
108
|
+
it "is sorted by decreasing score" do
|
109
|
+
@players.sort.should == [@player3, @player2, @player1]
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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 be(:hammer)
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a points attribute" do
|
15
|
+
@treasure.points.should be(50)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe TreasureTrove do
|
20
|
+
|
21
|
+
it "should have a treasure with 6 items" do
|
22
|
+
TreasureTrove::TREASURES.size.should == 6
|
23
|
+
end
|
24
|
+
|
25
|
+
it "should have a random treasure" do
|
26
|
+
treasure = TreasureTrove.random
|
27
|
+
TreasureTrove::TREASURES.should include(treasure)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio_game_UK
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mark Jones
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-04 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70355159486320 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70355159486320
|
25
|
+
description: Role playing game with auditing
|
26
|
+
email: pope at vatican dot com
|
27
|
+
executables:
|
28
|
+
- studio_game
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- bin/players.csv
|
33
|
+
- bin/studio_game
|
34
|
+
- bin/super_heros.csv
|
35
|
+
- lib/studio_game/auditable.rb
|
36
|
+
- lib/studio_game/berserk_player.rb
|
37
|
+
- lib/studio_game/clumsy_player.rb
|
38
|
+
- lib/studio_game/Die.rb
|
39
|
+
- lib/studio_game/game.rb
|
40
|
+
- lib/studio_game/game_turn.rb
|
41
|
+
- lib/studio_game/iterators.rb
|
42
|
+
- lib/studio_game/loaded_die.rb
|
43
|
+
- lib/studio_game/movie.rb
|
44
|
+
- lib/studio_game/playable.rb
|
45
|
+
- lib/studio_game/player.rb
|
46
|
+
- lib/studio_game/treasure_trove.rb
|
47
|
+
- spec/berserk_player_spec.rb
|
48
|
+
- spec/clumsy_player_spec.rb
|
49
|
+
- spec/game_spec.rb
|
50
|
+
- spec/player_spec.rb
|
51
|
+
- spec/treasure_trove_spec.rb
|
52
|
+
- LICENSE
|
53
|
+
- README
|
54
|
+
homepage: http://ecb.co.uk
|
55
|
+
licenses: []
|
56
|
+
post_install_message:
|
57
|
+
rdoc_options: []
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '1.9'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ! '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 1.8.11
|
75
|
+
signing_key:
|
76
|
+
specification_version: 3
|
77
|
+
summary: Playing games
|
78
|
+
test_files:
|
79
|
+
- spec/berserk_player_spec.rb
|
80
|
+
- spec/clumsy_player_spec.rb
|
81
|
+
- spec/game_spec.rb
|
82
|
+
- spec/player_spec.rb
|
83
|
+
- spec/treasure_trove_spec.rb
|