studio_game_vinhtran 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 +0 -0
- data/README +0 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +47 -0
- data/lib/studio_game/auditable.rb +5 -0
- data/lib/studio_game/berserk_player.rb +31 -0
- data/lib/studio_game/clumsy_player.rb +27 -0
- data/lib/studio_game/die.rb +15 -0
- data/lib/studio_game/game.rb +93 -0
- data/lib/studio_game/game_turn.rb +26 -0
- data/lib/studio_game/loaded_die.rb +15 -0
- data/lib/studio_game/playable.rb +20 -0
- data/lib/studio_game/player.rb +59 -0
- data/lib/studio_game/treasure_trove.rb +18 -0
- data/spec/studio_game/berserk_player_spec.rb +29 -0
- data/spec/studio_game/clumsy_player_spec.rb +31 -0
- data/spec/studio_game/game_spec.rb +48 -0
- data/spec/studio_game/player_spec.rb +139 -0
- data/spec/studio_game/treasure_trove_spec.rb +57 -0
- metadata +82 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 9d13dad0bd5532ceadba43485a9dec6633b8a84f
|
|
4
|
+
data.tar.gz: 1827965ee5d9ef6508857dc71cb2cdf374007b81
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 1f46e136a87ce7badbece004fc76681bcc2397fdb65dc1e7f293f08f40292da533b14f9722fe20bda658bb381aeb5d994f1e5e7d1b4644a4248ae7163ecac127
|
|
7
|
+
data.tar.gz: 7303f28a334cc7ccfd0f6de404ef81cf2147cc17bab2339e279ead57b2a37529b271e1b37d2decce77c948f8b86313a477aebba5b595e7eca98994b952b508ad
|
data/LICENSE
ADDED
|
File without changes
|
data/README
ADDED
|
File without changes
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/game'
|
|
4
|
+
require_relative '../lib/studio_game/player'
|
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
|
6
|
+
require_relative '../lib/studio_game/berserk_player'
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
|
10
|
+
|
|
11
|
+
player1 = StudioGame::Player.new("moe")
|
|
12
|
+
player2 = StudioGame::Player.new("larry", 60)
|
|
13
|
+
player3 = StudioGame::Player.new("curly", 125)
|
|
14
|
+
|
|
15
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
|
16
|
+
knuckleheads.add_player(player1)
|
|
17
|
+
knuckleheads.add_player(player2)
|
|
18
|
+
knuckleheads.add_player(player3)
|
|
19
|
+
# knuckleheads.play(3)
|
|
20
|
+
# knuckleheads.print_stats
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
|
|
25
|
+
knuckleheads.add_player(klutz)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
29
|
+
knuckleheads.add_player(berserker)
|
|
30
|
+
|
|
31
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
|
32
|
+
|
|
33
|
+
loop do |variable|
|
|
34
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
|
35
|
+
answer = gets.chomp.downcase
|
|
36
|
+
case answer
|
|
37
|
+
when /^\d+$/
|
|
38
|
+
knuckleheads.play(answer.to_i)
|
|
39
|
+
when 'quit', 'exit'
|
|
40
|
+
knuckleheads.print_stats
|
|
41
|
+
break
|
|
42
|
+
else
|
|
43
|
+
puts "Please enter a number or 'quit'"
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
knuckleheads.save_high_scores()
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class BerserkPlayer < Player
|
|
5
|
+
def initialize(name, health)
|
|
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
|
+
if __FILE__ == $0
|
|
26
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
27
|
+
6.times { berserker.w00t }
|
|
28
|
+
2.times { berserker.blam }
|
|
29
|
+
puts berserker.health
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
def found_treasure(treasure)
|
|
6
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
|
7
|
+
super(damaged_treasure)
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
if __FILE__ == $0
|
|
13
|
+
clumsy = StudioGame::ClumsyPlayer.new("klutz")
|
|
14
|
+
|
|
15
|
+
hammer = StudioGame::Treasure.new(:hammer, 50)
|
|
16
|
+
clumsy.found_treasure(hammer)
|
|
17
|
+
clumsy.found_treasure(hammer)
|
|
18
|
+
clumsy.found_treasure(hammer)
|
|
19
|
+
|
|
20
|
+
crowbar = StudioGame::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
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'game_turn'
|
|
3
|
+
require_relative 'treasure_trove'
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
class Game
|
|
7
|
+
attr_reader :title
|
|
8
|
+
|
|
9
|
+
def initialize(title)
|
|
10
|
+
@title = title.capitalize
|
|
11
|
+
@players = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_player(player)
|
|
15
|
+
@players << player
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def play(rounds)
|
|
19
|
+
puts "There are #{@players.size} players in #{title}:"
|
|
20
|
+
puts @players
|
|
21
|
+
|
|
22
|
+
treasures = TreasureTrove::TREASURES
|
|
23
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
|
24
|
+
treasures.each do |t|
|
|
25
|
+
puts "A #{t.name} is worth #{t.points} points"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
1.upto(rounds) do |round|
|
|
29
|
+
puts "\nRound #{round}:"
|
|
30
|
+
@players.each do |player|
|
|
31
|
+
GameTurn.take_turn(player)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def print_stats
|
|
37
|
+
strong_players, wimpy_players = @players.partition { |p| p.strong? }
|
|
38
|
+
sorted_players = @players.sort
|
|
39
|
+
|
|
40
|
+
puts "Knuckleheads Stats:\n"
|
|
41
|
+
puts "#{strong_players.size} strong players:"
|
|
42
|
+
strong_players.each do |player|
|
|
43
|
+
print_name_and_health(player)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
puts ""
|
|
47
|
+
puts "#{wimpy_players.size} wimpy players:"
|
|
48
|
+
wimpy_players.each do |player|
|
|
49
|
+
print_name_and_health(player)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
puts ""
|
|
53
|
+
puts "Knuckleheads High Scores:"
|
|
54
|
+
sorted_players.each do |player|
|
|
55
|
+
puts high_score_entry(player)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
@players.sort.each do |player|
|
|
59
|
+
puts "\n#{player.name}'s point totals:"
|
|
60
|
+
player.each_found_treasure do |treasure|
|
|
61
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
62
|
+
end
|
|
63
|
+
puts "#{player.points} grand total points"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def print_name_and_health(player)
|
|
68
|
+
puts "#{player.name} (#{player.health})"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def load_players(from_file)
|
|
72
|
+
File.readlines(from_file).each do |line|
|
|
73
|
+
# name, health = line.split(",")
|
|
74
|
+
# health = health.to_i
|
|
75
|
+
add_player(Player.from_csv(line))
|
|
76
|
+
# add_player(Player.new(name, health))
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
def save_high_scores(to_file = "high_scores.txt")
|
|
81
|
+
File.open(to_file, "w") do |file|
|
|
82
|
+
file.puts "#{@title} High Scores:"
|
|
83
|
+
@players.sort.each do |player|
|
|
84
|
+
file.puts high_score_entry(player)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def high_score_entry(player)
|
|
90
|
+
"#{player.name}".ljust(20, ".") + " #{player.score}"
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'treasure_trove'
|
|
3
|
+
require_relative 'die'
|
|
4
|
+
require_relative 'loaded_die'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
module GameTurn
|
|
8
|
+
def self.take_turn(player)
|
|
9
|
+
case Die.new.roll
|
|
10
|
+
when 1, 2
|
|
11
|
+
player.blam
|
|
12
|
+
when 3, 4
|
|
13
|
+
puts "#{player.name} was skipped"
|
|
14
|
+
when 5, 6
|
|
15
|
+
player.w00t
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
treasure = TreasureTrove.random
|
|
19
|
+
player.found_treasure(treasure)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def self.roll
|
|
23
|
+
@number = rand(1..6)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
require_relative 'playable'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
class Player
|
|
6
|
+
include Playable
|
|
7
|
+
attr_accessor :name
|
|
8
|
+
attr_reader :health
|
|
9
|
+
|
|
10
|
+
def initialize(name, health = 100)
|
|
11
|
+
@name = name.capitalize
|
|
12
|
+
@health = health
|
|
13
|
+
@found_treasures = Hash.new(0)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def to_s
|
|
17
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def each_found_treasure
|
|
21
|
+
@found_treasures.each do |name, points|
|
|
22
|
+
yield(Treasure.new(name, points))
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def found_treasure(treasure)
|
|
27
|
+
@found_treasures[treasure.name] += treasure.points
|
|
28
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def points
|
|
32
|
+
@found_treasures.values.reduce(0, :+)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def time
|
|
36
|
+
current_time = Time.new
|
|
37
|
+
current_time.strftime("%I:%M:%S")
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def <=>(other_player)
|
|
41
|
+
other_player.score <=> score
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def self.from_csv(formated_player)
|
|
45
|
+
name, health = formated_player.split(",")
|
|
46
|
+
Player.new(name, health.to_i)
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if __FILE__ == $PROGRAM_NAME
|
|
51
|
+
player = Player.new("moe")
|
|
52
|
+
puts player.name
|
|
53
|
+
puts player.health
|
|
54
|
+
player.w00t
|
|
55
|
+
puts player.health
|
|
56
|
+
player.blam
|
|
57
|
+
puts player.health
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
Treasure = Struct.new(:name, :points)
|
|
3
|
+
|
|
4
|
+
module TreasureTrove
|
|
5
|
+
TREASURES = [
|
|
6
|
+
Treasure.new(:pie, 5),
|
|
7
|
+
Treasure.new(:bottle, 25),
|
|
8
|
+
Treasure.new(:hammer, 50),
|
|
9
|
+
Treasure.new(:skillet, 100),
|
|
10
|
+
Treasure.new(:broomstick, 200),
|
|
11
|
+
Treasure.new(:crowbar, 400)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def self.random
|
|
15
|
+
TREASURES.sample
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'studio_game/berserk_player'
|
|
2
|
+
|
|
3
|
+
describe StudioGame::BerserkPlayer do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@initial_health = 50
|
|
7
|
+
@player = StudioGame::BerserkPlayer.new("berserker", @initial_health)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
it "does not go berserk when w00ted up to 5 times" do
|
|
11
|
+
1.upto(5) { @player.w00t }
|
|
12
|
+
|
|
13
|
+
@player.berserk?.should be_falsey
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "goes berserk when w00ted more than 5 times" do
|
|
17
|
+
1.upto(6) { @player.w00t }
|
|
18
|
+
|
|
19
|
+
@player.berserk?.should be_truthy
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
|
23
|
+
1.upto(6) { @player.w00t }
|
|
24
|
+
1.upto(2) { @player.blam }
|
|
25
|
+
|
|
26
|
+
@player.health.should == @initial_health + (8 * 15)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'studio_game/clumsy_player'
|
|
2
|
+
|
|
3
|
+
describe StudioGame::ClumsyPlayer do
|
|
4
|
+
before do
|
|
5
|
+
@player = StudioGame::ClumsyPlayer.new("klutz")
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
it "only gets half the point value for each treasure" do
|
|
9
|
+
@player.points.should == 0
|
|
10
|
+
|
|
11
|
+
hammer = StudioGame::Treasure.new(:hammer, 50)
|
|
12
|
+
@player.found_treasure(hammer)
|
|
13
|
+
@player.found_treasure(hammer)
|
|
14
|
+
@player.found_treasure(hammer)
|
|
15
|
+
|
|
16
|
+
@player.points.should == 75
|
|
17
|
+
|
|
18
|
+
crowbar = StudioGame::Treasure.new(:crowbar, 400)
|
|
19
|
+
@player.found_treasure(crowbar)
|
|
20
|
+
|
|
21
|
+
@player.points.should == 275
|
|
22
|
+
|
|
23
|
+
yielded = []
|
|
24
|
+
@player.each_found_treasure do |treasure|
|
|
25
|
+
yielded << treasure
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
yielded.should == [StudioGame::Treasure.new(:hammer, 75), StudioGame::Treasure.new(:crowbar, 200)]
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require 'studio_game/game'
|
|
2
|
+
|
|
3
|
+
describe StudioGame::Game do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@game = StudioGame::Game.new("Knuckleheads")
|
|
7
|
+
|
|
8
|
+
@initial_health = 100
|
|
9
|
+
@player = StudioGame::Player.new("moe", @initial_health)
|
|
10
|
+
|
|
11
|
+
@game.add_player(@player)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "w00ts the player if a high number is rolled" do
|
|
15
|
+
allow_any_instance_of(StudioGame::Die).to receive(:roll).and_return(5)
|
|
16
|
+
|
|
17
|
+
@game.play(2)
|
|
18
|
+
|
|
19
|
+
@player.health.should == @initial_health + 30
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
it "skips the player if a medium number is rolled" do
|
|
23
|
+
allow_any_instance_of(StudioGame::Die).to receive(:roll).and_return(3)
|
|
24
|
+
|
|
25
|
+
@game.play(2)
|
|
26
|
+
|
|
27
|
+
@player.health.should == @initial_health
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "blams the player if a low number is rolled" do
|
|
31
|
+
allow_any_instance_of(StudioGame::Die).to receive(:roll).and_return(1)
|
|
32
|
+
|
|
33
|
+
@game.play(2)
|
|
34
|
+
|
|
35
|
+
@player.health.should == @initial_health - (10 * 2)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "assigns a treasure for points during a player's turn" do
|
|
39
|
+
game = StudioGame::Game.new("Knuckleheads")
|
|
40
|
+
player = StudioGame::Player.new("moe")
|
|
41
|
+
|
|
42
|
+
game.add_player(player)
|
|
43
|
+
|
|
44
|
+
game.play(1)
|
|
45
|
+
|
|
46
|
+
player.points.should_not be_zero
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
require 'studio_game/player'
|
|
2
|
+
require 'studio_game/treasure_trove'
|
|
3
|
+
|
|
4
|
+
describe StudioGame::Player do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@initial_health = 150
|
|
8
|
+
@player = StudioGame::Player.new("larry", @initial_health)
|
|
9
|
+
$stdout = StringIO.new
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "has a capitalized name" do
|
|
13
|
+
@player.name.should == "Larry"
|
|
14
|
+
end
|
|
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(StudioGame::Treasure.new(:hammer, 50))
|
|
22
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
|
23
|
+
|
|
24
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "computes a score as the sum of its health and length of name" do
|
|
28
|
+
@player.score.should == 150
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it "increases health by 15 when w00ted" do
|
|
32
|
+
@player.w00t
|
|
33
|
+
|
|
34
|
+
@player.health.should == @initial_health + 15
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "decreases health by 10 when blammed" do
|
|
38
|
+
@player.blam
|
|
39
|
+
|
|
40
|
+
@player.health.should == @initial_health - 10
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "computes points as the sum of all treasure points" do
|
|
44
|
+
@player.points.should == 0
|
|
45
|
+
|
|
46
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
|
47
|
+
|
|
48
|
+
@player.points.should == 50
|
|
49
|
+
|
|
50
|
+
@player.found_treasure(StudioGame::Treasure.new(:crowbar, 400))
|
|
51
|
+
|
|
52
|
+
@player.points.should == 450
|
|
53
|
+
|
|
54
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
|
55
|
+
|
|
56
|
+
@player.points.should == 500
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
it "computes a score as the sum of its health and points" do
|
|
60
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
|
61
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
|
62
|
+
|
|
63
|
+
@player.score.should == 250
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it "yields each found treasure and its total points" do
|
|
67
|
+
@player.found_treasure(StudioGame::Treasure.new(:skillet, 100))
|
|
68
|
+
@player.found_treasure(StudioGame::Treasure.new(:skillet, 100))
|
|
69
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
|
70
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
|
71
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
|
72
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
|
73
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
|
74
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
|
75
|
+
|
|
76
|
+
yielded = []
|
|
77
|
+
@player.each_found_treasure do |treasure|
|
|
78
|
+
yielded << treasure
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
yielded.should == [
|
|
82
|
+
StudioGame::Treasure.new(:skillet, 200),
|
|
83
|
+
StudioGame::Treasure.new(:hammer, 50),
|
|
84
|
+
StudioGame::Treasure.new(:bottle, 25)
|
|
85
|
+
]
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
it "can be created from a CSV string" do
|
|
89
|
+
player = StudioGame::Player.from_csv("larry,150")
|
|
90
|
+
|
|
91
|
+
player.name.should == "Larry"
|
|
92
|
+
player.health.should == 150
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context "created with a default health" do
|
|
96
|
+
before do
|
|
97
|
+
@player = StudioGame::Player.new("larry")
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it "has a health of 100" do
|
|
101
|
+
@player.health.should == 100
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
context "created with an intial health of 150" do
|
|
106
|
+
before do
|
|
107
|
+
@player = StudioGame::Player.new("larry", 150)
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
it "is strong" do
|
|
111
|
+
expect(@player.strong?).to eq(true)
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
context "created with an intial health of 100" do
|
|
117
|
+
before do
|
|
118
|
+
@player = StudioGame::Player.new("larry", 100)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "is strong" do
|
|
122
|
+
expect(@player.strong?).to eq(false)
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "in a collection of players" do
|
|
127
|
+
before do
|
|
128
|
+
@player1 = StudioGame::Player.new("moe", 100)
|
|
129
|
+
@player2 = StudioGame::Player.new("larry", 200)
|
|
130
|
+
@player3 = StudioGame::Player.new("curly", 300)
|
|
131
|
+
|
|
132
|
+
@players = [@player1, @player2, @player3]
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
it "is sorted by decreasing score" do
|
|
136
|
+
@players.sort.should == [@player3, @player2, @player1]
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'studio_game/treasure_trove'
|
|
2
|
+
|
|
3
|
+
describe StudioGame::Treasure do
|
|
4
|
+
|
|
5
|
+
before do
|
|
6
|
+
@treasure = StudioGame::Treasure.new(:hammer, 50)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "has a name attribute" do
|
|
10
|
+
@treasure.name.should == :hammer
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it "has a points attribute" do
|
|
14
|
+
@treasure.points.should == 50
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
describe StudioGame::TreasureTrove do
|
|
20
|
+
|
|
21
|
+
it "has six treasures" do
|
|
22
|
+
StudioGame::TreasureTrove::TREASURES.size.should == 6
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it "has a pie worth 5 points" do
|
|
26
|
+
StudioGame::TreasureTrove::TREASURES[0].should == StudioGame::Treasure.new(:pie, 5)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it "has a bottle worth 25 points" do
|
|
30
|
+
StudioGame::TreasureTrove::TREASURES[1].should == StudioGame::Treasure.new(:bottle, 25)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "has a hammer worth 50 points" do
|
|
34
|
+
StudioGame::TreasureTrove::TREASURES[2].should == StudioGame::Treasure.new(:hammer, 50)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "has a skillet worth 100 points" do
|
|
38
|
+
StudioGame::TreasureTrove::TREASURES[3].should == StudioGame::Treasure.new(:skillet, 100)
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "has a broomstick worth 200 points" do
|
|
42
|
+
StudioGame::TreasureTrove::TREASURES[4].should == StudioGame::Treasure.new(:broomstick, 200)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "has a crowbar worth 400 points" do
|
|
46
|
+
StudioGame::TreasureTrove::TREASURES[5].should == StudioGame::Treasure.new(:crowbar, 400)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "returns a random treasure" do
|
|
50
|
+
treasure = StudioGame::TreasureTrove.random
|
|
51
|
+
|
|
52
|
+
StudioGame::TreasureTrove::TREASURES.should include(treasure)
|
|
53
|
+
|
|
54
|
+
# or use alternate expectation syntax:
|
|
55
|
+
# expect(TreasureTrove::TREASURES).to include(treasure)
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: studio_game_vinhtran
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Vinh Tran
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - ">="
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ">="
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: ''
|
|
28
|
+
email: me@vinhtran.tech
|
|
29
|
+
executables:
|
|
30
|
+
- studio_game
|
|
31
|
+
extensions: []
|
|
32
|
+
extra_rdoc_files: []
|
|
33
|
+
files:
|
|
34
|
+
- LICENSE
|
|
35
|
+
- README
|
|
36
|
+
- bin/players.csv
|
|
37
|
+
- bin/studio_game
|
|
38
|
+
- lib/studio_game/auditable.rb
|
|
39
|
+
- lib/studio_game/berserk_player.rb
|
|
40
|
+
- lib/studio_game/clumsy_player.rb
|
|
41
|
+
- lib/studio_game/die.rb
|
|
42
|
+
- lib/studio_game/game.rb
|
|
43
|
+
- lib/studio_game/game_turn.rb
|
|
44
|
+
- lib/studio_game/loaded_die.rb
|
|
45
|
+
- lib/studio_game/playable.rb
|
|
46
|
+
- lib/studio_game/player.rb
|
|
47
|
+
- lib/studio_game/treasure_trove.rb
|
|
48
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
49
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
50
|
+
- spec/studio_game/game_spec.rb
|
|
51
|
+
- spec/studio_game/player_spec.rb
|
|
52
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
53
|
+
homepage: http://vinhtran.tech
|
|
54
|
+
licenses:
|
|
55
|
+
- MIT
|
|
56
|
+
metadata: {}
|
|
57
|
+
post_install_message:
|
|
58
|
+
rdoc_options: []
|
|
59
|
+
require_paths:
|
|
60
|
+
- lib
|
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
62
|
+
requirements:
|
|
63
|
+
- - ">="
|
|
64
|
+
- !ruby/object:Gem::Version
|
|
65
|
+
version: '2.0'
|
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
|
+
requirements:
|
|
68
|
+
- - ">="
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '0'
|
|
71
|
+
requirements: []
|
|
72
|
+
rubyforge_project:
|
|
73
|
+
rubygems_version: 2.6.12
|
|
74
|
+
signing_key:
|
|
75
|
+
specification_version: 4
|
|
76
|
+
summary: Game created in Pragmatic Studio Class
|
|
77
|
+
test_files:
|
|
78
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
79
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
80
|
+
- spec/studio_game/game_spec.rb
|
|
81
|
+
- spec/studio_game/player_spec.rb
|
|
82
|
+
- spec/studio_game/treasure_trove_spec.rb
|