studio_game_pauls 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/LICENSE +7 -0
- data/README +1 -0
- data/bin/players.csv +3 -0
- data/bin/stooges.csv +3 -0
- data/bin/studio_game_pauls +35 -0
- data/lib/studio_game_pauls/auditable.rb +9 -0
- data/lib/studio_game_pauls/berserk_player.rb +35 -0
- data/lib/studio_game_pauls/clumsy_player.rb +28 -0
- data/lib/studio_game_pauls/die.rb +28 -0
- data/lib/studio_game_pauls/game.rb +115 -0
- data/lib/studio_game_pauls/game_turn.rb +27 -0
- data/lib/studio_game_pauls/loaded_die.rb +16 -0
- data/lib/studio_game_pauls/playable.rb +19 -0
- data/lib/studio_game_pauls/player.rb +65 -0
- data/lib/studio_game_pauls/treasure_trove.rb +20 -0
- data/spec/studio_game_pauls/berserk_player_spec.rb +32 -0
- data/spec/studio_game_pauls/clumsy_player_spec.rb +35 -0
- data/spec/studio_game_pauls/game_spec.rb +54 -0
- data/spec/studio_game_pauls/player_spec.rb +126 -0
- data/spec/studio_game_pauls/treasure_trove_spec.rb +59 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 4e0115adb297c07ca231fc4f19c31b5bfd2d822b
|
4
|
+
data.tar.gz: d8201794422c163541370894ab9d75199f616458
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 310676f4f784a297b4a76adc87d4bb5587181da2079af779b1c29431c6f0b1863fcda74c6b3795b24f78446a97d793ab00d77abc43fdcd4d66661a06047849ac
|
7
|
+
data.tar.gz: f5c8d05016bee21e8608ca5588b8eac11e43b536487edd51655ddd78b23a8c9ca443f90a44a7b28cbf4a3499aa2702ef831f5f0e560c8f276ed33e92d58f824a
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2013 Apple,Inc
|
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
|
+
Studo Game created from coursework for http://online.pragmaticstudio.com/courses/ruby
|
data/bin/players.csv
ADDED
data/bin/stooges.csv
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/studio_game_pauls/player'
|
3
|
+
require_relative '../lib/studio_game_pauls/clumsy_player'
|
4
|
+
require_relative '../lib/studio_game_pauls/berserk_player'
|
5
|
+
require_relative '../lib/studio_game_pauls/game'
|
6
|
+
|
7
|
+
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
9
|
+
|
10
|
+
knuckleheads = StudioGamePauls::Game.new("Knuckleheads")
|
11
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
12
|
+
|
13
|
+
klutz = StudioGamePauls::ClumsyPlayer.new("klutz", 105)
|
14
|
+
knuckleheads.add_player(klutz)
|
15
|
+
|
16
|
+
berserker = StudioGamePauls::BerserkPlayer.new("berserker", 50)
|
17
|
+
knuckleheads.add_player(berserker)
|
18
|
+
|
19
|
+
loop do
|
20
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
21
|
+
answer = gets.chomp.downcase
|
22
|
+
puts "answer: #{answer}"
|
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
|
+
puts "\n===================="
|
33
|
+
end
|
34
|
+
|
35
|
+
knuckleheads.save_high_scores
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGamePauls
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
def initialize(name, health=100)
|
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
|
+
berserk? ? w00t : super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
if __FILE__ == $0
|
27
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
28
|
+
6.times { berserker.w00t }
|
29
|
+
2.times { berserker.blam }
|
30
|
+
puts berserker.health
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGamePauls
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
def found_treasure(treasure)
|
6
|
+
super(Treasure.new(treasure.name, treasure.points / 2.0))
|
7
|
+
end
|
8
|
+
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
if __FILE__ == $0
|
13
|
+
clumsy = StudioGamePauls::ClumsyPlayer.new("klutz")
|
14
|
+
|
15
|
+
hammer = Treasure.new(:hammer, 50)
|
16
|
+
clumsy.found_treasure(hammer)
|
17
|
+
clumsy.found_treasure(hammer)
|
18
|
+
clumsy.found_treasure(hammer)
|
19
|
+
|
20
|
+
crowbar = Treasure.new(:crowbar, 400)
|
21
|
+
clumsy.found_treasure(crowbar)
|
22
|
+
|
23
|
+
clumsy.each_found_treasure do |treasure|
|
24
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
25
|
+
end
|
26
|
+
puts "#{clumsy.points} grand total points"
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'auditable'
|
2
|
+
|
3
|
+
module StudioGamePauls
|
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
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
if __FILE__ == $0
|
23
|
+
puts StudioGamePauls::Die.new.roll
|
24
|
+
puts StudioGamePauls::Die.new.roll
|
25
|
+
puts StudioGamePauls::Die.new.roll
|
26
|
+
puts StudioGamePauls::Die.new.roll
|
27
|
+
puts StudioGamePauls::Die.new.roll
|
28
|
+
end
|
@@ -0,0 +1,115 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'game_turn'
|
4
|
+
require_relative 'treasure_trove'
|
5
|
+
|
6
|
+
module StudioGamePauls
|
7
|
+
class Game
|
8
|
+
attr_reader :title
|
9
|
+
|
10
|
+
def initialize(title)
|
11
|
+
@title = title
|
12
|
+
@players = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def load_players(filename)
|
16
|
+
File.readlines(filename).each do |line|
|
17
|
+
puts "line read: #{line}"
|
18
|
+
player = Player.from_csv(line)
|
19
|
+
add_player player
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def save_high_scores(filename="high_scores.txt")
|
24
|
+
File.open(filename, "w") do |file|
|
25
|
+
file.puts "#{@title} High Scores:"
|
26
|
+
@players.sort.each do |player|
|
27
|
+
file.puts formatted_player_high_score(player)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def add_player(player)
|
33
|
+
@players << player
|
34
|
+
end
|
35
|
+
|
36
|
+
def play(rounds)
|
37
|
+
puts "There are #{@players.size} players in #{@title}."
|
38
|
+
@players.each do |player|
|
39
|
+
puts player
|
40
|
+
end
|
41
|
+
|
42
|
+
treasures = TreasureTrove::TREASURES
|
43
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
44
|
+
treasures.each do |treasure|
|
45
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
46
|
+
end
|
47
|
+
|
48
|
+
1.upto(rounds) do |round|
|
49
|
+
puts "\nRound: #{round}"
|
50
|
+
|
51
|
+
@players.each do |player|
|
52
|
+
GameTurn.take_turn(player)
|
53
|
+
puts player
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def print_name_and_health(player)
|
59
|
+
puts "#{player.name} (#{player.health})"
|
60
|
+
end
|
61
|
+
|
62
|
+
def print_players_strength
|
63
|
+
strong, wimpy = @players.partition { |p| p.strong?}
|
64
|
+
|
65
|
+
puts "\n#{strong.size} strong players:"
|
66
|
+
strong.each do |player|
|
67
|
+
print_name_and_health(player)
|
68
|
+
end
|
69
|
+
|
70
|
+
puts "\n#{wimpy.size} wimpy players:"
|
71
|
+
wimpy.each do |player|
|
72
|
+
print_name_and_health(player)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def formatted_player_high_score(player)
|
77
|
+
formatted_name = player.name.ljust(20, '.')
|
78
|
+
"#{formatted_name} #{player.score}"
|
79
|
+
end
|
80
|
+
|
81
|
+
def print_player_high_scores
|
82
|
+
puts "\n#{@title} High Scores:"
|
83
|
+
@players.sort.each do |player|
|
84
|
+
puts formatted_player_high_score(player)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def print_total_points(player)
|
89
|
+
puts "\n#{player.name}'s point total:\n#{player.points} grand total points"
|
90
|
+
end
|
91
|
+
|
92
|
+
def print_player_total_points
|
93
|
+
puts "\n#{@title}'s Total Points:"
|
94
|
+
@players.sort.each do |player|
|
95
|
+
print_total_points(player)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
def print_stats
|
100
|
+
puts "\n#{@title} Statistics:"
|
101
|
+
print_players_strength
|
102
|
+
print_player_high_scores
|
103
|
+
print_player_total_points
|
104
|
+
|
105
|
+
@players.sort.each do |player|
|
106
|
+
puts "\n#{player.name}'s point totals:"
|
107
|
+
player.each_found_treasure do |treasure|
|
108
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
109
|
+
end
|
110
|
+
puts "#{player.points} grand total points"
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
require_relative 'loaded_die'
|
5
|
+
|
6
|
+
module StudioGamePauls
|
7
|
+
module GameTurn
|
8
|
+
def self.take_turn(player)
|
9
|
+
die = Die.new
|
10
|
+
# die = LoadedDie.new
|
11
|
+
|
12
|
+
case die.roll
|
13
|
+
when 1..2
|
14
|
+
player.blam
|
15
|
+
when 3..4
|
16
|
+
puts "#{player.name} was skipped."
|
17
|
+
else
|
18
|
+
player.w00t
|
19
|
+
end
|
20
|
+
|
21
|
+
treasure = TreasureTrove.random
|
22
|
+
player.found_treasure(treasure)
|
23
|
+
# puts "#{player.name} found a #{treasure.name} worth #{treasure.points}."
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGamePauls
|
5
|
+
class Player
|
6
|
+
include Playable
|
7
|
+
|
8
|
+
attr_reader :health
|
9
|
+
attr_accessor :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 to_s
|
18
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.from_csv(line)
|
22
|
+
name, health = line.split(",")
|
23
|
+
Player.new(name, Integer(health))
|
24
|
+
end
|
25
|
+
|
26
|
+
def name=(new_name)
|
27
|
+
@name = new_name.capitalize
|
28
|
+
end
|
29
|
+
|
30
|
+
def score
|
31
|
+
@health + points
|
32
|
+
end
|
33
|
+
|
34
|
+
def <=>(other)
|
35
|
+
other.score <=> score
|
36
|
+
end
|
37
|
+
|
38
|
+
def found_treasure(treasure)
|
39
|
+
@found_treasures[treasure.name] += treasure.points
|
40
|
+
puts "\n#{@name} found a #{treasure.name} worth #{treasure.points}."
|
41
|
+
puts "#{@name}'s treasures: #{@found_treasures}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def points
|
45
|
+
@found_treasures.values.reduce(0, :+)
|
46
|
+
end
|
47
|
+
|
48
|
+
def each_found_treasure
|
49
|
+
@found_treasures.each do |name, points|
|
50
|
+
yield Treasure.new(name,points)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
if __FILE__ == $0
|
58
|
+
player = StudioGamePauls::Player.new("moe")
|
59
|
+
puts player.name
|
60
|
+
puts player.health
|
61
|
+
player.w00t
|
62
|
+
puts player.health
|
63
|
+
player.blam
|
64
|
+
puts player.health
|
65
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module StudioGamePauls
|
2
|
+
|
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
|
+
|
20
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'studio_game_pauls/berserk_player'
|
2
|
+
|
3
|
+
module StudioGamePauls
|
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
|
+
end
|
31
|
+
|
32
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'studio_game_pauls/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGamePauls
|
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
|
+
@player.found_treasure(crowbar)
|
22
|
+
|
23
|
+
@player.points.should == 275
|
24
|
+
|
25
|
+
yielded = []
|
26
|
+
@player.each_found_treasure do |treasure|
|
27
|
+
yielded << treasure
|
28
|
+
end
|
29
|
+
|
30
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'studio_game_pauls/game'
|
2
|
+
require 'studio_game_pauls/player'
|
3
|
+
|
4
|
+
module StudioGamePauls
|
5
|
+
|
6
|
+
describe Game do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@game = Game.new("Knuckleheads")
|
10
|
+
|
11
|
+
@initial_health = 100
|
12
|
+
@player = Player.new("moe", @initial_health)
|
13
|
+
|
14
|
+
@game.add_player(@player)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "w00ts the player if a high number is rolled" do
|
18
|
+
Die.any_instance.stub(:roll).and_return(5)
|
19
|
+
|
20
|
+
@game.play(2)
|
21
|
+
|
22
|
+
@player.health.should == @initial_health + (15 * 2)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "skips the player if a medium number is rolled" do
|
26
|
+
Die.any_instance.stub(:roll).and_return(3)
|
27
|
+
|
28
|
+
@game.play(2)
|
29
|
+
|
30
|
+
@player.health.should == @initial_health
|
31
|
+
end
|
32
|
+
|
33
|
+
it "blams the player if a low number is rolled" do
|
34
|
+
Die.any_instance.stub(:roll).and_return(1)
|
35
|
+
|
36
|
+
@game.play(2)
|
37
|
+
|
38
|
+
@player.health.should == @initial_health - (10 * 2)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "assigns a treasure for points during a player's turn" do
|
42
|
+
game = Game.new("Knuckleheads")
|
43
|
+
player = Player.new("moe")
|
44
|
+
|
45
|
+
game.add_player(player)
|
46
|
+
|
47
|
+
game.play(1)
|
48
|
+
|
49
|
+
player.points.should_not be_zero
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'studio_game_pauls/player'
|
2
|
+
require 'studio_game_pauls/treasure_trove'
|
3
|
+
|
4
|
+
module StudioGamePauls
|
5
|
+
|
6
|
+
describe Player do
|
7
|
+
# $stdout = StringIO.new
|
8
|
+
before do
|
9
|
+
@initial_name = "larry"
|
10
|
+
@initial_health = 150
|
11
|
+
@player = Player.new(@initial_name, @initial_health)
|
12
|
+
end
|
13
|
+
it "has a capitalized name" do
|
14
|
+
@player.name.should == "Larry"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has an initial health" do
|
18
|
+
@player.health.should == 150
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has a string representation" do
|
22
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
23
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
24
|
+
|
25
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
|
26
|
+
end
|
27
|
+
|
28
|
+
it "computes a score as the sum of its health and points" do
|
29
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
30
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
31
|
+
|
32
|
+
@player.score.should == 250
|
33
|
+
end
|
34
|
+
|
35
|
+
it "increases health by 15 when w00ted" do
|
36
|
+
@player.w00t
|
37
|
+
@player.score.should == 165
|
38
|
+
end
|
39
|
+
|
40
|
+
it "decreases health by 10 when blammed" do
|
41
|
+
@player.blam
|
42
|
+
@player.score.should == 140
|
43
|
+
end
|
44
|
+
|
45
|
+
it "computes points as the sum of all treasure points" do
|
46
|
+
@player.points.should == 0
|
47
|
+
|
48
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
49
|
+
|
50
|
+
@player.points.should == 50
|
51
|
+
|
52
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
53
|
+
|
54
|
+
@player.points.should == 450
|
55
|
+
|
56
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
57
|
+
|
58
|
+
@player.points.should == 500
|
59
|
+
end
|
60
|
+
|
61
|
+
it "yields each found treasure and its total points" do
|
62
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
63
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
64
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
65
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
66
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
67
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
68
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
69
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
70
|
+
|
71
|
+
yielded = []
|
72
|
+
@player.each_found_treasure do |treasure|
|
73
|
+
yielded << treasure
|
74
|
+
end
|
75
|
+
|
76
|
+
yielded.should == [
|
77
|
+
Treasure.new(:skillet, 200),
|
78
|
+
Treasure.new(:hammer, 50),
|
79
|
+
Treasure.new(:bottle, 25)
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
it "can be created from a CSV string" do
|
84
|
+
player = Player.from_csv("larry,150")
|
85
|
+
|
86
|
+
player.name.should == "Larry"
|
87
|
+
player.health.should == 150
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with a health greater then 100" do
|
91
|
+
before do
|
92
|
+
@player = Player.new("larry", 150)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "is strong" do
|
96
|
+
@player.should be_strong
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "with a health less then or equal to 100" do
|
101
|
+
before do
|
102
|
+
@player = Player.new("larry", 100)
|
103
|
+
end
|
104
|
+
|
105
|
+
it "is wimpy" do
|
106
|
+
@player.should_not be_strong
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context "in a collection of players" do
|
111
|
+
before do
|
112
|
+
@player1 = Player.new("moe", 100)
|
113
|
+
@player2 = Player.new("larry", 200)
|
114
|
+
@player3 = Player.new("curly", 300)
|
115
|
+
|
116
|
+
@players = [@player1, @player2, @player3]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "is sorted by decreasing score" do
|
120
|
+
@players.sort.should == [@player3, @player2, @player1]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'studio_game_pauls/treasure_trove'
|
2
|
+
|
3
|
+
module StudioGamePauls
|
4
|
+
|
5
|
+
describe Treasure do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@treasure = Treasure.new(:hammer, 50)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a name attribute" do
|
12
|
+
@treasure.name.should == :hammer
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has a points attribute" do
|
16
|
+
@treasure.points.should == 50
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
describe TreasureTrove do
|
22
|
+
|
23
|
+
it "has six treasures" do
|
24
|
+
TreasureTrove::TREASURES.size.should == 6
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has a pie worth 5 points" do
|
28
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "has a bottle worth 25 points" do
|
32
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "has a hammer worth 50 points" do
|
36
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a skillet worth 100 points" do
|
40
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "has a broomstick worth 200 points" do
|
44
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
45
|
+
end
|
46
|
+
|
47
|
+
it "has a crowbar worth 400 points" do
|
48
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
49
|
+
end
|
50
|
+
|
51
|
+
it "returns a random treasure" do
|
52
|
+
treasure = TreasureTrove.random
|
53
|
+
|
54
|
+
TreasureTrove::TREASURES.should include(treasure)
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio_game_pauls
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul S.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-21 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
|
+
Studo Game created from coursework for http://online.pragmaticstudio.com/courses/ruby
|
29
|
+
email: jump23@me.com
|
30
|
+
executables:
|
31
|
+
- studio_game_pauls
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- bin/players.csv
|
36
|
+
- bin/stooges.csv
|
37
|
+
- bin/studio_game_pauls
|
38
|
+
- lib/studio_game_pauls/auditable.rb
|
39
|
+
- lib/studio_game_pauls/berserk_player.rb
|
40
|
+
- lib/studio_game_pauls/clumsy_player.rb
|
41
|
+
- lib/studio_game_pauls/die.rb
|
42
|
+
- lib/studio_game_pauls/game.rb
|
43
|
+
- lib/studio_game_pauls/game_turn.rb
|
44
|
+
- lib/studio_game_pauls/loaded_die.rb
|
45
|
+
- lib/studio_game_pauls/playable.rb
|
46
|
+
- lib/studio_game_pauls/player.rb
|
47
|
+
- lib/studio_game_pauls/treasure_trove.rb
|
48
|
+
- spec/studio_game_pauls/berserk_player_spec.rb
|
49
|
+
- spec/studio_game_pauls/clumsy_player_spec.rb
|
50
|
+
- spec/studio_game_pauls/game_spec.rb
|
51
|
+
- spec/studio_game_pauls/player_spec.rb
|
52
|
+
- spec/studio_game_pauls/treasure_trove_spec.rb
|
53
|
+
- LICENSE
|
54
|
+
- README
|
55
|
+
homepage: ''
|
56
|
+
licenses: []
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '1.9'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.1.11
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: http://online.pragmaticstudio.com/courses/ruby coursework
|
78
|
+
test_files:
|
79
|
+
- spec/studio_game_pauls/berserk_player_spec.rb
|
80
|
+
- spec/studio_game_pauls/clumsy_player_spec.rb
|
81
|
+
- spec/studio_game_pauls/game_spec.rb
|
82
|
+
- spec/studio_game_pauls/player_spec.rb
|
83
|
+
- spec/studio_game_pauls/treasure_trove_spec.rb
|