studio_game_ar 1.0.0
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 +11 -0
- data/README +1 -0
- data/bin/high_scores.txt +6 -0
- data/bin/player_health.csv +3 -0
- data/bin/player_tennis.csv +3 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +46 -0
- data/bin/studio_game.rb~ +43 -0
- data/bin/studio_game~ +44 -0
- data/lib/studio_game/auditable.rb +10 -0
- data/lib/studio_game/berserk_player.rb +39 -0
- data/lib/studio_game/clumsy_player.rb +29 -0
- data/lib/studio_game/die.rb +19 -0
- data/lib/studio_game/files.rb +10 -0
- data/lib/studio_game/game.rb +107 -0
- data/lib/studio_game/game_turn.rb +22 -0
- data/lib/studio_game/iterators.rb +14 -0
- data/lib/studio_game/loaded_die.rb +17 -0
- data/lib/studio_game/playable.rb +18 -0
- data/lib/studio_game/player.rb +65 -0
- data/lib/studio_game/treasure_trove.rb +23 -0
- data/spec/studio_game/berserk_player_spec.rb +41 -0
- data/spec/studio_game/berserk_player_spec.rb~ +41 -0
- data/spec/studio_game/clumsy_player_spec.rb +35 -0
- data/spec/studio_game/clumsy_player_spec.rb~ +35 -0
- data/spec/studio_game/game_spec.rb +53 -0
- data/spec/studio_game/game_spec.rb~ +53 -0
- data/spec/studio_game/player_spec.rb +135 -0
- data/spec/studio_game/player_spec.rb~ +135 -0
- data/spec/studio_game/treasure_trove_spec.rb +54 -0
- data/spec/studio_game/treasure_trove_spec.rb~ +54 -0
- metadata +100 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 6641b9cc8c7eb64506c60f1d34ce87df6e314b92
|
|
4
|
+
data.tar.gz: e0ae9aa9986e52a428a943dcf15f51a443bfeb25
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7116a3598966a223e1fd37d01d912d36d29e2656db40423f33caf463f6a68a9c6591b109d5914c369596f2700330f1c22d014f4ff0b709beace2b60d887862b3
|
|
7
|
+
data.tar.gz: ba85ef977894992b066441c909535bb3bf6582075edc6d27b2d2a0fa35a75acd2d352ef9589127c9780a7c0c9765acfc67e9523811cc827ef497041de897e93c
|
data/LICENSE
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2016 Lloyd Co.
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
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:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
9
|
+
|
|
10
|
+
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.
|
|
11
|
+
|
data/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Players start with a given score. Throughout the game they can find treasures which increase their score. The object of the game is to accumulate as many points as possible as the rounds continue. Whoever has the highest amount of points wins.
|
data/bin/high_scores.txt
ADDED
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/player'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/studio_game/game'
|
|
6
|
+
|
|
7
|
+
require_relative '../lib/studio_game/clumsy_player'
|
|
8
|
+
|
|
9
|
+
require_relative '../lib/studio_game/berserk_player'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
player1 = StudioGame::Player.new("Peter")
|
|
14
|
+
player2 = StudioGame::Player.new("Ana")
|
|
15
|
+
player3 = StudioGame::Player.new("Abe")
|
|
16
|
+
player4 = StudioGame::Player.new("shemp", 90)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
|
20
|
+
|
|
21
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
|
22
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
player5 = StudioGame::ClumsyPlayer.new("klutz", 105)
|
|
26
|
+
knuckleheads.add_player(player5)
|
|
27
|
+
|
|
28
|
+
player6 = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
29
|
+
knuckleheads.add_player(player6)
|
|
30
|
+
|
|
31
|
+
loop do
|
|
32
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
|
33
|
+
answer = gets.chomp.downcase
|
|
34
|
+
case answer
|
|
35
|
+
when /^\d+$/
|
|
36
|
+
puts "Enjoy your #{answer} game rounds."
|
|
37
|
+
knuckleheads.play(answer.to_i)
|
|
38
|
+
when 'quit', 'exit'
|
|
39
|
+
knuckleheads.print_stats
|
|
40
|
+
break
|
|
41
|
+
else
|
|
42
|
+
puts "Please enter a number or 'quit'"
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
knuckleheads.save_high_scores
|
data/bin/studio_game.rb~
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative '../lib/studio_game/player'
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/game'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
|
6
|
+
|
|
7
|
+
require_relative '../lib/studio_game/berserk_player'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
player1 = StudioGame::Player.new("Peter")
|
|
12
|
+
player2 = StudioGame::Player.new("Ana")
|
|
13
|
+
player3 = StudioGame::Player.new("Abe")
|
|
14
|
+
player4 = StudioGame::Player.new("shemp", 90)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
|
18
|
+
|
|
19
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv') knuckleheads.load_players(ARGV.shift || default_player_file)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
player5 = StudioGame::ClumsyPlayer.new("klutz", 105)
|
|
23
|
+
knuckleheads.add_player(player5)
|
|
24
|
+
|
|
25
|
+
player6 = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
26
|
+
knuckleheads.add_player(player6)
|
|
27
|
+
|
|
28
|
+
loop do
|
|
29
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
|
30
|
+
answer = gets.chomp.downcase
|
|
31
|
+
case answer
|
|
32
|
+
when /^\d+$/
|
|
33
|
+
puts "Enjoy your #{answer} game rounds."
|
|
34
|
+
knuckleheads.play(answer.to_i)
|
|
35
|
+
when 'quit', 'exit'
|
|
36
|
+
knuckleheads.print_stats
|
|
37
|
+
break
|
|
38
|
+
else
|
|
39
|
+
puts "Please enter a number or 'quit'"
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
knuckleheads.save_high_scores
|
data/bin/studio_game~
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
require_relative '../lib/studio_game/player'
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/game'
|
|
4
|
+
|
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
|
6
|
+
|
|
7
|
+
require_relative '../lib/studio_game/berserk_player'
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
player1 = StudioGame::Player.new("Peter")
|
|
12
|
+
player2 = StudioGame::Player.new("Ana")
|
|
13
|
+
player3 = StudioGame::Player.new("Abe")
|
|
14
|
+
player4 = StudioGame::Player.new("shemp", 90)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
|
18
|
+
|
|
19
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
|
20
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
player5 = StudioGame::ClumsyPlayer.new("klutz", 105)
|
|
24
|
+
knuckleheads.add_player(player5)
|
|
25
|
+
|
|
26
|
+
player6 = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
27
|
+
knuckleheads.add_player(player6)
|
|
28
|
+
|
|
29
|
+
loop do
|
|
30
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
|
31
|
+
answer = gets.chomp.downcase
|
|
32
|
+
case answer
|
|
33
|
+
when /^\d+$/
|
|
34
|
+
puts "Enjoy your #{answer} game rounds."
|
|
35
|
+
knuckleheads.play(answer.to_i)
|
|
36
|
+
when 'quit', 'exit'
|
|
37
|
+
knuckleheads.print_stats
|
|
38
|
+
break
|
|
39
|
+
else
|
|
40
|
+
puts "Please enter a number or 'quit'"
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
knuckleheads.save_high_scores
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
|
|
5
|
+
class BerserkPlayer < Player
|
|
6
|
+
|
|
7
|
+
def initialize(player, health=100)
|
|
8
|
+
super(player, health)
|
|
9
|
+
@w00t_count = 0
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def berserk?
|
|
13
|
+
@w00t_count > 5
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def w00t
|
|
17
|
+
super
|
|
18
|
+
@w00t_count +=1
|
|
19
|
+
if berserk?
|
|
20
|
+
puts "#{@name} is berserk!"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def blam
|
|
25
|
+
if berserk?
|
|
26
|
+
w00t
|
|
27
|
+
else
|
|
28
|
+
super
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
if __FILE__ == $0
|
|
34
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
35
|
+
6.times { berserker.w00t }
|
|
36
|
+
2.times { berserker.blam }
|
|
37
|
+
puts berserker.health
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
|
|
5
|
+
class ClumsyPlayer < Player
|
|
6
|
+
|
|
7
|
+
def found_treasure(treasure)
|
|
8
|
+
super(Treasure.new(treasure.name, treasure.points/2))
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
if __FILE__ == $0
|
|
14
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
15
|
+
|
|
16
|
+
hammer = Treasure.new(:hammer, 50)
|
|
17
|
+
clumsy.found_treasure(hammer)
|
|
18
|
+
clumsy.found_treasure(hammer)
|
|
19
|
+
clumsy.found_treasure(hammer)
|
|
20
|
+
|
|
21
|
+
crowbar = Treasure.new(:crowbar, 400)
|
|
22
|
+
clumsy.found_treasure(crowbar)
|
|
23
|
+
|
|
24
|
+
clumsy.each_found_treasure do |treasure|
|
|
25
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
26
|
+
end
|
|
27
|
+
puts "#{clumsy.points} grand total points"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'game_turn'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
|
|
8
|
+
class Game
|
|
9
|
+
attr_accessor :name
|
|
10
|
+
attr_reader :players
|
|
11
|
+
|
|
12
|
+
def initialize (mylist)
|
|
13
|
+
@name = mylist.capitalize
|
|
14
|
+
@players = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def load_players(from_file)
|
|
18
|
+
File.readlines(from_file).each do |line|
|
|
19
|
+
add_player(Player.from_csv(line))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def high_score_entry(player)
|
|
24
|
+
formatted_name = player.name.ljust(20, '.')
|
|
25
|
+
"#{formatted_name} #{player.score}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def save_high_scores(to_file="high_scores.txt")
|
|
30
|
+
File.open(to_file, "w") do |file|
|
|
31
|
+
file.puts "#{@name} High Scores:"
|
|
32
|
+
@players.sort.each do |player|
|
|
33
|
+
file.puts high_score_entry(player)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def add_player(player)
|
|
39
|
+
@players << player
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def play(rounds)
|
|
43
|
+
puts "#{@name}'s game:"
|
|
44
|
+
puts @players.sort
|
|
45
|
+
|
|
46
|
+
treasures = TreasureTrove::TREASURES
|
|
47
|
+
puts "\nThere are #{treasures.size} treasures to be found."
|
|
48
|
+
|
|
49
|
+
treasures.each do |t|
|
|
50
|
+
puts "#{t.name} has #{t.points} points"
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
1.upto(rounds) do |round|
|
|
54
|
+
puts "\nRound number #{round}:"
|
|
55
|
+
@players.each do |player|
|
|
56
|
+
GameTurn.take_turn(player)
|
|
57
|
+
player.found_treasure(TreasureTrove.random)
|
|
58
|
+
puts player
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def total_points
|
|
64
|
+
@players.reduce(0) do |sum, player|
|
|
65
|
+
sum + player.points
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def print_stats
|
|
70
|
+
puts "\n#{@name}'s status:"
|
|
71
|
+
|
|
72
|
+
puts "#{total_points} total points earned"
|
|
73
|
+
|
|
74
|
+
@players.sort.each do |p|
|
|
75
|
+
puts "\n#{p.name}'s total points:"
|
|
76
|
+
p.each_found_treasure do |treasure|
|
|
77
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
78
|
+
end
|
|
79
|
+
puts "#{p.points} grand total points"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
strong, weak = @players.partition { |player| player.strong? }
|
|
83
|
+
|
|
84
|
+
puts "\nStrong:"
|
|
85
|
+
strong.each { |p| self.print_name_and_health(p)}
|
|
86
|
+
# puts strong.sort
|
|
87
|
+
|
|
88
|
+
puts "\nWeak:"
|
|
89
|
+
weak.each { |p| self.print_name_and_health(p)}
|
|
90
|
+
# puts weak.sort
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
puts "\n#{@name} High Scores:"
|
|
94
|
+
@players.sort.each do |player|
|
|
95
|
+
puts high_score_entry(player)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def to_s
|
|
100
|
+
puts "There are #{@players.length} players in Knuckleheads:"
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def print_name_and_health(player)
|
|
104
|
+
puts "#{player.name} has a health of #{player.health}."
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
require_relative 'loaded_die'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
|
|
5
|
+
module GameTurn
|
|
6
|
+
def self.take_turn(player)
|
|
7
|
+
die = Die.new
|
|
8
|
+
number_rolled = die.roll
|
|
9
|
+
case number_rolled
|
|
10
|
+
when 1..2
|
|
11
|
+
player.blam
|
|
12
|
+
when 3..4
|
|
13
|
+
puts "#{player.name} was skipped."
|
|
14
|
+
else
|
|
15
|
+
player.w00t
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
treasure =TreasureTrove.random
|
|
19
|
+
player.found_treasure(treasure)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
require_relative 'playable'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
class Player
|
|
7
|
+
include Playable
|
|
8
|
+
attr_accessor :name
|
|
9
|
+
attr_reader :health
|
|
10
|
+
|
|
11
|
+
def initialize(player, health=100)
|
|
12
|
+
@name = player.capitalize
|
|
13
|
+
@health = health
|
|
14
|
+
@found_treasures = Hash.new(0)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.from_csv(string)
|
|
18
|
+
name, health = string.split(',')
|
|
19
|
+
Player.new(name, Integer(health))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_csv
|
|
23
|
+
"#{@name}, #{health}"
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def each_found_treasure
|
|
27
|
+
@found_treasures.each do |name, points|
|
|
28
|
+
treasure = Treasure.new(name, points)
|
|
29
|
+
yield treasure
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def found_treasure(treasure)
|
|
34
|
+
@found_treasures[treasure.name] += treasure.points
|
|
35
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
|
36
|
+
puts "#{@name}'s treasures: #{@found_treasures}"
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def points
|
|
40
|
+
@found_treasures.values.reduce(0, :+)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def score
|
|
44
|
+
@health + points
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def to_s
|
|
48
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def <=>(other_player)
|
|
52
|
+
other_player.score <=> score
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
if __FILE__ == $0
|
|
58
|
+
player = 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,23 @@
|
|
|
1
|
+
module StudioGame
|
|
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
|
+
if __FILE__ == $0
|
|
21
|
+
puts TreasureTrove::TREASURES
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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_falsey
|
|
16
|
+
|
|
17
|
+
# or if using Rspec 3.0:
|
|
18
|
+
# @player.berserk?.should be_falsey
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "goes berserk when w00ted more than 5 times" do
|
|
22
|
+
1.upto(6) { @player.w00t }
|
|
23
|
+
|
|
24
|
+
@player.berserk?.should be_truthy
|
|
25
|
+
|
|
26
|
+
# or if using Rspec 3.0:
|
|
27
|
+
# @player.berserk?.should be_truthy
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
|
31
|
+
1.upto(6) { @player.w00t }
|
|
32
|
+
1.upto(2) { @player.blam }
|
|
33
|
+
|
|
34
|
+
@player.health.should == @initial_health + (8 * 15)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
require_relative '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_falsey
|
|
16
|
+
|
|
17
|
+
# or if using Rspec 3.0:
|
|
18
|
+
# @player.berserk?.should be_falsey
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "goes berserk when w00ted more than 5 times" do
|
|
22
|
+
1.upto(6) { @player.w00t }
|
|
23
|
+
|
|
24
|
+
@player.berserk?.should be_truthy
|
|
25
|
+
|
|
26
|
+
# or if using Rspec 3.0:
|
|
27
|
+
# @player.berserk?.should be_truthy
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
|
31
|
+
1.upto(6) { @player.w00t }
|
|
32
|
+
1.upto(2) { @player.blam }
|
|
33
|
+
|
|
34
|
+
@player.health.should == @initial_health + (8 * 15)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'studio_game/clumsy_player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
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,35 @@
|
|
|
1
|
+
require_relative 'clumsy_player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
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,53 @@
|
|
|
1
|
+
require 'studio_game/game'
|
|
2
|
+
require 'studio_game/die'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
describe Game do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@game = Game.new("Knuckleheads")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "game rules" do
|
|
13
|
+
before do
|
|
14
|
+
@initial_health = 100
|
|
15
|
+
@player = Player.new("moe", @initial_health)
|
|
16
|
+
|
|
17
|
+
@game.add_player(@player)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "w00ts the player if a high number is rolled" do
|
|
21
|
+
Die.any_instance.stub(:roll).and_return(6)
|
|
22
|
+
@game.play(2)
|
|
23
|
+
@player.health.should == @initial_health + (15*2)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "blams the player if a low number is rolled" do
|
|
27
|
+
Die.any_instance.stub(:roll).and_return(2)
|
|
28
|
+
@game.play(2)
|
|
29
|
+
@player.health.should == @initial_health - (10*2)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "keeps the health the same when a medium number is rolled" do
|
|
33
|
+
Die.any_instance.stub(:roll).and_return(3)
|
|
34
|
+
@game.play(2)
|
|
35
|
+
@player.health.should == @initial_health
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "assigns a treasure for points during a player's turn" do
|
|
39
|
+
game = Game.new("Knuckleheads")
|
|
40
|
+
player = Player.new("moe")
|
|
41
|
+
|
|
42
|
+
game.add_player(player)
|
|
43
|
+
|
|
44
|
+
game.play(1)
|
|
45
|
+
|
|
46
|
+
player.points.should_not be_zero
|
|
47
|
+
|
|
48
|
+
# or use alternate expectation syntax:
|
|
49
|
+
# expect(player.points).not_to be_zero
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
require_relative 'game'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
describe Game do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@game = Game.new("Knuckleheads")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
context "game rules" do
|
|
13
|
+
before do
|
|
14
|
+
@initial_health = 100
|
|
15
|
+
@player = Player.new("moe", @initial_health)
|
|
16
|
+
|
|
17
|
+
@game.add_player(@player)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it "w00ts the player if a high number is rolled" do
|
|
21
|
+
Die.any_instance.stub(:roll).and_return(6)
|
|
22
|
+
@game.play(2)
|
|
23
|
+
@player.health.should == @initial_health + (15*2)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "blams the player if a low number is rolled" do
|
|
27
|
+
Die.any_instance.stub(:roll).and_return(2)
|
|
28
|
+
@game.play(2)
|
|
29
|
+
@player.health.should == @initial_health - (10*2)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "keeps the health the same when a medium number is rolled" do
|
|
33
|
+
Die.any_instance.stub(:roll).and_return(3)
|
|
34
|
+
@game.play(2)
|
|
35
|
+
@player.health.should == @initial_health
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "assigns a treasure for points during a player's turn" do
|
|
39
|
+
game = Game.new("Knuckleheads")
|
|
40
|
+
player = Player.new("moe")
|
|
41
|
+
|
|
42
|
+
game.add_player(player)
|
|
43
|
+
|
|
44
|
+
game.play(1)
|
|
45
|
+
|
|
46
|
+
player.points.should_not be_zero
|
|
47
|
+
|
|
48
|
+
# or use alternate expectation syntax:
|
|
49
|
+
# expect(player.points).not_to be_zero
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'studio_game/player'
|
|
2
|
+
require 'studio_game/treasure_trove'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
describe Player do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@initial_health = 150
|
|
10
|
+
@player = Player.new("harry", 150)
|
|
11
|
+
$stdout = StringIO.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "in a collection of players"
|
|
15
|
+
before do
|
|
16
|
+
@player1 = Player.new("moe", 100)
|
|
17
|
+
@player2 = Player.new("larry", 200)
|
|
18
|
+
@player3 = Player.new("curly", 300)
|
|
19
|
+
|
|
20
|
+
@players = [@player1, @player2, @player3]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "is sorted by decreasing score" do
|
|
24
|
+
@players.sort.should == [@player3, @player2, @player1]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
context "with a health of greater than 100" do
|
|
29
|
+
before do
|
|
30
|
+
@player = Player.new("harry", 150)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "is a strong player" do
|
|
34
|
+
expect(@player).to be_strong
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "with a health less than or equal to 100" do
|
|
39
|
+
before do
|
|
40
|
+
@player = Player.new("harry", 99)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "is a weak player" do
|
|
44
|
+
expect(@player).not_to be_strong
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "has a capitalized name" do
|
|
49
|
+
#@player.name.should == "Harry"
|
|
50
|
+
expect(@player.name).to eq("Harry")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "has an inital health" do
|
|
54
|
+
#@player.health.should == 100
|
|
55
|
+
expect(@player.health).to eq(150)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "has a string representation" do
|
|
59
|
+
#@player.to_s.should == "I'm Harry with a health of 100 and a score of 105."
|
|
60
|
+
@player.to_s.should == "I'm Harry with health = 150, points = 0, and score = 150."
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# it "has a score the sum of its health and name length" do
|
|
64
|
+
# expect(@player.score).to eq(@player.name.size + @player.health)
|
|
65
|
+
# end
|
|
66
|
+
|
|
67
|
+
it "increases health by 15 when w00ted!" do
|
|
68
|
+
@player.w00t
|
|
69
|
+
|
|
70
|
+
#@player.health.should == @initial_health + 15
|
|
71
|
+
expect(@player.health).to eq(@initial_health + 15)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "decreases health by 10 when blammed!" do
|
|
75
|
+
@player.blam
|
|
76
|
+
|
|
77
|
+
#@player.health.should == @initial_health - 10
|
|
78
|
+
expect(@player.health).to eq(@initial_health - 10)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "computes points as the sum of all treasure points" do
|
|
82
|
+
@player.points.should == 0
|
|
83
|
+
|
|
84
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
85
|
+
|
|
86
|
+
@player.points.should == 50
|
|
87
|
+
|
|
88
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
|
89
|
+
|
|
90
|
+
@player.points.should == 450
|
|
91
|
+
|
|
92
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
93
|
+
|
|
94
|
+
@player.points.should == 500
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "computes a score as the sum of its health and points" do
|
|
98
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
99
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
100
|
+
|
|
101
|
+
@player.score.should == 250
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
it "yields each found treasure and its total points" do
|
|
107
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
108
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
109
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
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
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
114
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
115
|
+
|
|
116
|
+
yielded = []
|
|
117
|
+
@player.each_found_treasure do |treasure|
|
|
118
|
+
yielded << treasure
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
yielded.should == [
|
|
122
|
+
Treasure.new(:skillet, 200),
|
|
123
|
+
Treasure.new(:hammer, 50),
|
|
124
|
+
Treasure.new(:bottle, 25)
|
|
125
|
+
]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "can be created from a CSV string" do
|
|
129
|
+
player = Player.from_csv("larry,150")
|
|
130
|
+
|
|
131
|
+
player.name.should == "Larry"
|
|
132
|
+
player.health.should == 150
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'treasure_trove'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
describe Player do
|
|
7
|
+
|
|
8
|
+
before do
|
|
9
|
+
@initial_health = 150
|
|
10
|
+
@player = Player.new("harry", 150)
|
|
11
|
+
$stdout = StringIO.new
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
context "in a collection of players"
|
|
15
|
+
before do
|
|
16
|
+
@player1 = Player.new("moe", 100)
|
|
17
|
+
@player2 = Player.new("larry", 200)
|
|
18
|
+
@player3 = Player.new("curly", 300)
|
|
19
|
+
|
|
20
|
+
@players = [@player1, @player2, @player3]
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it "is sorted by decreasing score" do
|
|
24
|
+
@players.sort.should == [@player3, @player2, @player1]
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
context "with a health of greater than 100" do
|
|
29
|
+
before do
|
|
30
|
+
@player = Player.new("harry", 150)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "is a strong player" do
|
|
34
|
+
expect(@player).to be_strong
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "with a health less than or equal to 100" do
|
|
39
|
+
before do
|
|
40
|
+
@player = Player.new("harry", 99)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "is a weak player" do
|
|
44
|
+
expect(@player).not_to be_strong
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "has a capitalized name" do
|
|
49
|
+
#@player.name.should == "Harry"
|
|
50
|
+
expect(@player.name).to eq("Harry")
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "has an inital health" do
|
|
54
|
+
#@player.health.should == 100
|
|
55
|
+
expect(@player.health).to eq(150)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "has a string representation" do
|
|
59
|
+
#@player.to_s.should == "I'm Harry with a health of 100 and a score of 105."
|
|
60
|
+
@player.to_s.should == "I'm Harry with health = 150, points = 0, and score = 150."
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# it "has a score the sum of its health and name length" do
|
|
64
|
+
# expect(@player.score).to eq(@player.name.size + @player.health)
|
|
65
|
+
# end
|
|
66
|
+
|
|
67
|
+
it "increases health by 15 when w00ted!" do
|
|
68
|
+
@player.w00t
|
|
69
|
+
|
|
70
|
+
#@player.health.should == @initial_health + 15
|
|
71
|
+
expect(@player.health).to eq(@initial_health + 15)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
it "decreases health by 10 when blammed!" do
|
|
75
|
+
@player.blam
|
|
76
|
+
|
|
77
|
+
#@player.health.should == @initial_health - 10
|
|
78
|
+
expect(@player.health).to eq(@initial_health - 10)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "computes points as the sum of all treasure points" do
|
|
82
|
+
@player.points.should == 0
|
|
83
|
+
|
|
84
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
85
|
+
|
|
86
|
+
@player.points.should == 50
|
|
87
|
+
|
|
88
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
|
89
|
+
|
|
90
|
+
@player.points.should == 450
|
|
91
|
+
|
|
92
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
93
|
+
|
|
94
|
+
@player.points.should == 500
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "computes a score as the sum of its health and points" do
|
|
98
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
99
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
100
|
+
|
|
101
|
+
@player.score.should == 250
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
it "yields each found treasure and its total points" do
|
|
107
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
108
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
109
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
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
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
114
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
115
|
+
|
|
116
|
+
yielded = []
|
|
117
|
+
@player.each_found_treasure do |treasure|
|
|
118
|
+
yielded << treasure
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
yielded.should == [
|
|
122
|
+
Treasure.new(:skillet, 200),
|
|
123
|
+
Treasure.new(:hammer, 50),
|
|
124
|
+
Treasure.new(:bottle, 25)
|
|
125
|
+
]
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
it "can be created from a CSV string" do
|
|
129
|
+
player = Player.from_csv("larry,150")
|
|
130
|
+
|
|
131
|
+
player.name.should == "Larry"
|
|
132
|
+
player.health.should == 150
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require 'studio_game/treasure_trove'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
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
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
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
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
|
metadata
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: studio_game_ar
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ana Rios
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-05-31 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
|
+
Players start with a given score. Throughout the game they can find treasures which increase their score. The object of the game is to accumulate as many points as possible as the rounds continue. Whoever has the highest amount of points wins.
|
|
29
|
+
email: anar@mygame.com
|
|
30
|
+
executables:
|
|
31
|
+
- studio_game
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- LICENSE
|
|
36
|
+
- README
|
|
37
|
+
- bin/high_scores.txt
|
|
38
|
+
- bin/player_health.csv
|
|
39
|
+
- bin/player_tennis.csv
|
|
40
|
+
- bin/players.csv
|
|
41
|
+
- bin/studio_game
|
|
42
|
+
- bin/studio_game.rb~
|
|
43
|
+
- bin/studio_game~
|
|
44
|
+
- lib/studio_game/auditable.rb
|
|
45
|
+
- lib/studio_game/berserk_player.rb
|
|
46
|
+
- lib/studio_game/clumsy_player.rb
|
|
47
|
+
- lib/studio_game/die.rb
|
|
48
|
+
- lib/studio_game/files.rb
|
|
49
|
+
- lib/studio_game/game.rb
|
|
50
|
+
- lib/studio_game/game_turn.rb
|
|
51
|
+
- lib/studio_game/iterators.rb
|
|
52
|
+
- lib/studio_game/loaded_die.rb
|
|
53
|
+
- lib/studio_game/playable.rb
|
|
54
|
+
- lib/studio_game/player.rb
|
|
55
|
+
- lib/studio_game/treasure_trove.rb
|
|
56
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
57
|
+
- spec/studio_game/berserk_player_spec.rb~
|
|
58
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
59
|
+
- spec/studio_game/clumsy_player_spec.rb~
|
|
60
|
+
- spec/studio_game/game_spec.rb
|
|
61
|
+
- spec/studio_game/game_spec.rb~
|
|
62
|
+
- spec/studio_game/player_spec.rb
|
|
63
|
+
- spec/studio_game/player_spec.rb~
|
|
64
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
65
|
+
- spec/studio_game/treasure_trove_spec.rb~
|
|
66
|
+
homepage: http://mygamear.com
|
|
67
|
+
licenses:
|
|
68
|
+
- MIT
|
|
69
|
+
metadata: {}
|
|
70
|
+
post_install_message:
|
|
71
|
+
rdoc_options: []
|
|
72
|
+
require_paths:
|
|
73
|
+
- lib
|
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '1.9'
|
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
80
|
+
requirements:
|
|
81
|
+
- - ">="
|
|
82
|
+
- !ruby/object:Gem::Version
|
|
83
|
+
version: '0'
|
|
84
|
+
requirements: []
|
|
85
|
+
rubyforge_project:
|
|
86
|
+
rubygems_version: 2.4.5.1
|
|
87
|
+
signing_key:
|
|
88
|
+
specification_version: 4
|
|
89
|
+
summary: Players find treasures and accumulate points
|
|
90
|
+
test_files:
|
|
91
|
+
- spec/studio_game/treasure_trove_spec.rb~
|
|
92
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
93
|
+
- spec/studio_game/berserk_player_spec.rb~
|
|
94
|
+
- spec/studio_game/game_spec.rb~
|
|
95
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
96
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
97
|
+
- spec/studio_game/player_spec.rb~
|
|
98
|
+
- spec/studio_game/player_spec.rb
|
|
99
|
+
- spec/studio_game/game_spec.rb
|
|
100
|
+
- spec/studio_game/clumsy_player_spec.rb~
|