nt_studio_game 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 +9 -0
- data/bin/high_scores.txt +5 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +39 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +32 -0
- data/lib/studio_game/clumsy_player.rb +38 -0
- data/lib/studio_game/die.rb +18 -0
- data/lib/studio_game/game.rb +117 -0
- data/lib/studio_game/game_turn.rb +22 -0
- data/lib/studio_game/loaded_die.rb +14 -0
- data/lib/studio_game/playable.rb +18 -0
- data/lib/studio_game/player.rb +63 -0
- data/lib/studio_game/treasure_trove.rb +18 -0
- data/spec/studio_game/berserk_player_spec.rb +31 -0
- data/spec/studio_game/clumsy_player_spec.rb +33 -0
- data/spec/studio_game/game_spec.rb +47 -0
- data/spec/studio_game/player_spec.rb +100 -0
- data/spec/studio_game/treasure_trove_spec.rb +52 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 3c7294371c71b93efb5b8e8c7a6ceef23a50625e
|
4
|
+
data.tar.gz: aac5aef793cb101d2f55ff4516bc8aaa3461945e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 54915beac98908bb0929e76b7da24cac01a492252b01daa8f48b0ed71d6e849508f8c03737e7ab55730e2e819cb2f36590f69c2e72a0a6650650671a231a4d79
|
7
|
+
data.tar.gz: 7efa8c8a96a0a5c1d3c5361744be60dc60442d4e1d5c627f9f3f72a0a62498c591aae42d8f5927f558ee7b57fd019173d8e2df58505d0ee2ad4331fccd30d872
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
copyright (C) 2014 Nathaniel Taylor
|
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
data/bin/high_scores.txt
ADDED
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/studio_game/game'
|
3
|
+
require_relative '../lib/studio_game/clumsy_player'
|
4
|
+
require_relative '../lib/studio_game/berserk_player'
|
5
|
+
|
6
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
7
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
8
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
9
|
+
|
10
|
+
klutz = StudioGame::ClumsyPlayer.new("klutz",105,10)
|
11
|
+
knuckleheads.add_player(klutz)
|
12
|
+
|
13
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
14
|
+
knuckleheads.add_player(berserker)
|
15
|
+
|
16
|
+
loop do
|
17
|
+
puts "How many game rounds? ('quit' to exit)"
|
18
|
+
rounds = gets.chomp
|
19
|
+
case rounds
|
20
|
+
when /^\d+$/
|
21
|
+
knuckleheads.play(Integer(rounds)) do
|
22
|
+
knuckleheads.total_points >= 200000
|
23
|
+
end
|
24
|
+
when "quit", "exit"
|
25
|
+
knuckleheads.statistics
|
26
|
+
break
|
27
|
+
else
|
28
|
+
puts "Please put a number or 'quit'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
knuckleheads.save_high_scores
|
33
|
+
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
|
38
|
+
|
39
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
module StudioGame
|
3
|
+
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
|
6
|
+
def initialize(name, health=100)
|
7
|
+
super(name, health)
|
8
|
+
@w00t_count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def berserk?
|
12
|
+
@w00t_count > 5
|
13
|
+
end
|
14
|
+
|
15
|
+
def w00t
|
16
|
+
super
|
17
|
+
@w00t_count += 1
|
18
|
+
puts "#{@name} is berserk!" if @w00t_count == 6
|
19
|
+
end
|
20
|
+
|
21
|
+
def blam
|
22
|
+
berserk? ? w00t : super
|
23
|
+
end
|
24
|
+
end
|
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
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
|
6
|
+
def initialize(name,health=100,boost=10)
|
7
|
+
super(name,health)
|
8
|
+
@boost_factor = boost
|
9
|
+
end
|
10
|
+
|
11
|
+
def w00t
|
12
|
+
@health += @boost_factor
|
13
|
+
super
|
14
|
+
end
|
15
|
+
|
16
|
+
def found_treasure(treasure)
|
17
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0 )
|
18
|
+
super(damaged_treasure)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if __FILE__ == $0
|
23
|
+
clumsy = ClumsyPlayer.new("klutz")
|
24
|
+
|
25
|
+
hammer = Treasure.new(:hammer, 50)
|
26
|
+
clumsy.found_treasure(hammer)
|
27
|
+
clumsy.found_treasure(hammer)
|
28
|
+
clumsy.found_treasure(hammer)
|
29
|
+
|
30
|
+
crowbar = Treasure.new(:crowbar, 400)
|
31
|
+
clumsy.found_treasure(crowbar)
|
32
|
+
|
33
|
+
clumsy.each_found_treasure do |treasure|
|
34
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
35
|
+
end
|
36
|
+
puts "#{clumsy.points} grand total points"
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'loaded_die'
|
4
|
+
require_relative 'game_turn'
|
5
|
+
require_relative 'treasure_trove'
|
6
|
+
|
7
|
+
module StudioGame
|
8
|
+
class Game
|
9
|
+
attr_accessor :title
|
10
|
+
attr_reader :players
|
11
|
+
|
12
|
+
|
13
|
+
def initialize(title,players=[])
|
14
|
+
@title = title
|
15
|
+
@players = players
|
16
|
+
end
|
17
|
+
|
18
|
+
def add_player(player)
|
19
|
+
@players.push(player)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def play(rounds)
|
24
|
+
puts "\nThere are #{@players.size} players in #{title}:"
|
25
|
+
|
26
|
+
each_player do |p|
|
27
|
+
puts p
|
28
|
+
end
|
29
|
+
|
30
|
+
tr = TreasureTrove::TREASURES
|
31
|
+
puts "\nThere are #{tr.size} treasures to be found:\n"
|
32
|
+
|
33
|
+
tr.each do |t|
|
34
|
+
puts "A #{t.name} is worth #{t.points} points\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
1.upto(rounds) do |i|
|
38
|
+
puts "\nRound #{i}\n"
|
39
|
+
|
40
|
+
each_player do |p|
|
41
|
+
GameTurn.take_turn(p)
|
42
|
+
end
|
43
|
+
# break if yield
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
def statistics
|
49
|
+
strong, wimpy = @players.partition {|n| n.strong?}
|
50
|
+
puts "\n\n\n#{@title} Statistics:\n\n"
|
51
|
+
puts "#{strong.size} strong player#{"s"if strong.size != 1}:\n"
|
52
|
+
strong.each do |p|
|
53
|
+
puts "#{p.name} (#{p.health})\n"
|
54
|
+
end
|
55
|
+
puts "\n"
|
56
|
+
|
57
|
+
puts "#{wimpy.size} wimpy player#{"s"if strong.size != 1}:\n"
|
58
|
+
wimpy.each do |p|
|
59
|
+
puts "#{p.name} (#{p.health})\n"
|
60
|
+
end
|
61
|
+
|
62
|
+
print_high_scores
|
63
|
+
each_player { |p| p.print_points }
|
64
|
+
puts "\nThe total combined score is #{total_points}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def high_score_entry(player)
|
68
|
+
"#{player.name.ljust(30,'.')} #{player.score}\n"
|
69
|
+
end
|
70
|
+
|
71
|
+
def each_player
|
72
|
+
sorted_players = @players.sort
|
73
|
+
sorted_players.each { |sp| yield sp }
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
def print_high_scores
|
78
|
+
puts "\n#{@title} High Scores:\n"
|
79
|
+
each_player do |sp|
|
80
|
+
puts high_score_entry(sp)
|
81
|
+
end
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
def read_csv(file)
|
86
|
+
File.new(file).readlines.each do |line|
|
87
|
+
x, y = line.split(",")
|
88
|
+
yield(x,y)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def load_players(file)
|
93
|
+
read_csv(file) do |name, health|
|
94
|
+
player = Player.new(name,Integer(health))
|
95
|
+
add_player(player)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
def total_points
|
101
|
+
@players.reduce(0) {|sum, p| sum + p.score}
|
102
|
+
end
|
103
|
+
|
104
|
+
def save_high_scores(file_name="high_scores.txt")
|
105
|
+
File.open(file_name,"w") do |file|
|
106
|
+
each_player do |pl|
|
107
|
+
file.puts high_score_entry(pl)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'game'
|
2
|
+
require_relative 'treasure_trove'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
module GameTurn
|
6
|
+
def self.take_turn(player)
|
7
|
+
d = Die.new.roll
|
8
|
+
case d
|
9
|
+
when 1..2
|
10
|
+
player.blam
|
11
|
+
when 3..4
|
12
|
+
player.pass
|
13
|
+
when 5..6
|
14
|
+
player.w00t
|
15
|
+
else
|
16
|
+
end
|
17
|
+
tr = TreasureTrove.random
|
18
|
+
player.found_treasure(tr)
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module StudioGame
|
2
|
+
module Playable
|
3
|
+
def blam
|
4
|
+
self.health -= 10
|
5
|
+
puts "#{self.name} got blammed!"
|
6
|
+
end
|
7
|
+
|
8
|
+
def w00t
|
9
|
+
self.health += 15
|
10
|
+
puts "#{self.name} got w00ted!"
|
11
|
+
end
|
12
|
+
|
13
|
+
def strong?
|
14
|
+
self.health > 100
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
include Playable
|
7
|
+
|
8
|
+
attr_accessor :health, :treasures, :name
|
9
|
+
|
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.capitalize} with a health of #{@health} and a score of #{score.to_s}."
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
def pass
|
24
|
+
puts "#{@name} got passed."
|
25
|
+
end
|
26
|
+
|
27
|
+
def found_treasure(t)
|
28
|
+
@found_treasures[t.name] += t.points
|
29
|
+
puts "#{@name} found a #{t.name} worth #{t.points}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def points
|
33
|
+
@found_treasures.values.reduce(0) { |sum, v| sum + v }
|
34
|
+
end
|
35
|
+
|
36
|
+
def score
|
37
|
+
@health + @name.length + self.points
|
38
|
+
end
|
39
|
+
|
40
|
+
def <=>(other)
|
41
|
+
other.score <=> self.score
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
def each_found_treasure
|
46
|
+
@found_treasures.each do |key, value|
|
47
|
+
yield( Treasure.new(key,value))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def print_points
|
52
|
+
puts "\n#{@name}'s point totals:"
|
53
|
+
self.each_found_treasure do |treasure|
|
54
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
55
|
+
end
|
56
|
+
puts "#{self.points} grand total points"
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module StudioGame
|
2
|
+
Treasure = Struct.new(:name,:points)
|
3
|
+
module TreasureTrove
|
4
|
+
TREASURES = [Treasure.new(:pie,5),
|
5
|
+
Treasure.new(:bottle,25),
|
6
|
+
Treasure.new(:hammer,50),
|
7
|
+
Treasure.new(:skillet,100),
|
8
|
+
Treasure.new(:broomstick,200),
|
9
|
+
Treasure.new(:crowbar,400)]
|
10
|
+
|
11
|
+
|
12
|
+
def self.random
|
13
|
+
r = rand(0..5)
|
14
|
+
TREASURES[r]
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
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 == false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "goes berserk when w00ted more than 5 times" do
|
18
|
+
1.upto(6) { @player.w00t }
|
19
|
+
|
20
|
+
@player.berserk?.should == true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
24
|
+
1.upto(6) { @player.w00t }
|
25
|
+
1.upto(2) { @player.blam }
|
26
|
+
|
27
|
+
@player.health.should == @initial_health + (8 * 15)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
require 'studio_game/player'
|
3
|
+
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
describe Game do
|
7
|
+
before do
|
8
|
+
@zelda = Game.new("Zelda")
|
9
|
+
@initial_health = 100
|
10
|
+
@player = Player.new("steve", @initial_health)
|
11
|
+
@zelda.add_player(@player)
|
12
|
+
|
13
|
+
end
|
14
|
+
it "should have a title" do
|
15
|
+
@zelda.title.should == "Zelda"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should be able to add players" do
|
19
|
+
@zelda.players.size.should == 1
|
20
|
+
p5 = Player.new("Juaquin")
|
21
|
+
@zelda.add_player(p5)
|
22
|
+
@zelda.players.size.should == 2
|
23
|
+
end
|
24
|
+
|
25
|
+
it "w00ts a player if a high number is rolled" do
|
26
|
+
Die.any_instance.stub(:roll).and_return(5)
|
27
|
+
@zelda.play(1)
|
28
|
+
@player.health.should == @initial_health + 15
|
29
|
+
end
|
30
|
+
|
31
|
+
it "passes a player if a medium number is rolled" do
|
32
|
+
Die.any_instance.stub(:roll).and_return(3)
|
33
|
+
@zelda.play(1)
|
34
|
+
@player.health.should == @initial_health
|
35
|
+
end
|
36
|
+
|
37
|
+
it "blams a player if a low number is rolled" do
|
38
|
+
Die.any_instance.stub(:roll).and_return(2)
|
39
|
+
@zelda.play(1)
|
40
|
+
@player.health.should == @initial_health - 10
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Player do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@health = 150
|
8
|
+
@player = Player.new("bob",@health)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "has a capitalized name" do
|
12
|
+
@player.name.should == "Bob"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
it "has an initial health" do
|
17
|
+
@player.health.should == 150
|
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 Bob with a health of 150 and a score of 253."
|
25
|
+
end
|
26
|
+
|
27
|
+
it "computes a score as the sum of its health and length of name" do
|
28
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
29
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
30
|
+
@player.score.should == 253
|
31
|
+
end
|
32
|
+
|
33
|
+
it "increases health by 15 when w00ted" do
|
34
|
+
@player.w00t
|
35
|
+
@player.health.should == @health + 15
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
it "decreases health by 10 when blammed" do
|
40
|
+
@player.blam
|
41
|
+
@player.health.should == @health - 10
|
42
|
+
end
|
43
|
+
|
44
|
+
it "yields each found treasure and its total points" do
|
45
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
46
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
47
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
48
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
49
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
50
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
51
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
52
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
53
|
+
|
54
|
+
yielded = []
|
55
|
+
@player.each_found_treasure do |treasure|
|
56
|
+
yielded << treasure
|
57
|
+
end
|
58
|
+
|
59
|
+
yielded.should == [
|
60
|
+
Treasure.new(:skillet, 200),
|
61
|
+
Treasure.new(:hammer, 50),
|
62
|
+
Treasure.new(:bottle, 25)
|
63
|
+
]
|
64
|
+
end
|
65
|
+
|
66
|
+
context "with default health" do
|
67
|
+
before do
|
68
|
+
@player = Player.new("bob")
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should have default health" do
|
72
|
+
@player.health.should == 100
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
context "with a health greater than 100" do
|
78
|
+
before do
|
79
|
+
@player = Player.new("bob",150)
|
80
|
+
end
|
81
|
+
|
82
|
+
it "is strong" do
|
83
|
+
puts @player.strong?
|
84
|
+
puts "Hello!"
|
85
|
+
@player.strong?.should == true
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "with a health of 100 or less" do
|
90
|
+
before do
|
91
|
+
@player = Player.new("bob",100)
|
92
|
+
end
|
93
|
+
|
94
|
+
it "is not strong" do
|
95
|
+
@player.strong?.should == false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'studio_game/treasure_trove'
|
2
|
+
|
3
|
+
|
4
|
+
module StudioGame
|
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
|
+
end
|
52
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nt_studio_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Nathaniel Taylor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-16 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
|
+
blahblah
|
29
|
+
blahblah
|
30
|
+
blahblah
|
31
|
+
blahblah
|
32
|
+
blahblah
|
33
|
+
blahblah
|
34
|
+
blahblah
|
35
|
+
|
36
|
+
|
37
|
+
email: nathanielty@aol.com
|
38
|
+
executables:
|
39
|
+
- studio_game
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- LICENSE
|
44
|
+
- README
|
45
|
+
- bin/high_scores.txt
|
46
|
+
- bin/players.csv
|
47
|
+
- bin/studio_game
|
48
|
+
- lib/studio_game/auditable.rb
|
49
|
+
- lib/studio_game/berserk_player.rb
|
50
|
+
- lib/studio_game/clumsy_player.rb
|
51
|
+
- lib/studio_game/die.rb
|
52
|
+
- lib/studio_game/game.rb
|
53
|
+
- lib/studio_game/game_turn.rb
|
54
|
+
- lib/studio_game/loaded_die.rb
|
55
|
+
- lib/studio_game/playable.rb
|
56
|
+
- lib/studio_game/player.rb
|
57
|
+
- lib/studio_game/treasure_trove.rb
|
58
|
+
- spec/studio_game/berserk_player_spec.rb
|
59
|
+
- spec/studio_game/clumsy_player_spec.rb
|
60
|
+
- spec/studio_game/game_spec.rb
|
61
|
+
- spec/studio_game/player_spec.rb
|
62
|
+
- spec/studio_game/treasure_trove_spec.rb
|
63
|
+
homepage: http://www.pragmaticstudio.com
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.9'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.2
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: pragmatic studio ruby tutorial exercises
|
87
|
+
test_files:
|
88
|
+
- spec/studio_game/berserk_player_spec.rb
|
89
|
+
- spec/studio_game/clumsy_player_spec.rb
|
90
|
+
- spec/studio_game/game_spec.rb
|
91
|
+
- spec/studio_game/player_spec.rb
|
92
|
+
- spec/studio_game/treasure_trove_spec.rb
|