murdoks_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 +19 -0
- data/README +1 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +27 -0
- data/lib/studio_game/auditable.rb +5 -0
- data/lib/studio_game/berserk_player.rb +24 -0
- data/lib/studio_game/clumsy_player.rb +38 -0
- data/lib/studio_game/die.rb +19 -0
- data/lib/studio_game/game.rb +100 -0
- data/lib/studio_game/game_turn.rb +22 -0
- data/lib/studio_game/high_scores.txt +4 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +15 -0
- data/lib/studio_game/player.rb +63 -0
- data/lib/studio_game/treasure_trove.rb +20 -0
- data/spec/studio_game/berserk_player_spec.rb +30 -0
- data/spec/studio_game/clumsy_player_spec.rb +50 -0
- data/spec/studio_game/game_spec.rb +66 -0
- data/spec/studio_game/player_spec.rb +127 -0
- data/spec/studio_game/spec_helper.rb +8 -0
- data/spec/studio_game/treasure_trove_spec.rb +56 -0
- metadata +91 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8ac69a6528f667b2c1919b41766cb42c6f4c715ff471800d8f189b13428fb7f4
|
4
|
+
data.tar.gz: 392d71de4703d6b56e0ae5534af8e7ff698dd086754dfb51be9f2bd7ea901f00
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66458f6149e3ce49aed5f835d8525147c4c612a82ddfeb33bfe0a859af624cc5b05346ab3f4bd794d6856dd9aafa175a9f97dc1b27df23fd317b9c3d4856f57f
|
7
|
+
data.tar.gz: 3f6feb664cfb9ba9a3f02709100f00e0ff2724e099b1da2c9830ad4d72fcc8120d119b478cd522e13ba7aaef200e8261e87c3a5808a91e7e9e7d00908e42d45c
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2020 cjilbert504
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
This gem is designed to be a stand alone game or the modules can be used to extend functionality into your program.
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/studio_game/player'
|
4
|
+
require_relative '../lib/studio_game/game'
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
6
|
+
|
7
|
+
game = StudioGame::Game.new("Knuckleheads")
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
9
|
+
game.load_players(ARGV.shift || default_player_file)
|
10
|
+
|
11
|
+
loop do
|
12
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
13
|
+
answer = gets.chomp.downcase
|
14
|
+
case answer
|
15
|
+
when /^\d+$/
|
16
|
+
game.play(answer.to_i) do
|
17
|
+
game.total_points >= 2000
|
18
|
+
end
|
19
|
+
when "quit", "exit"
|
20
|
+
game.print_stats
|
21
|
+
break
|
22
|
+
else
|
23
|
+
puts "Please enter a number or 'quit'"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
game.save_high_scores
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
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
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require_relative "player"
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
attr_reader :boost_factor
|
6
|
+
|
7
|
+
def initialize(name, health=100, boost_factor=1)
|
8
|
+
super(name, health)
|
9
|
+
@boost_factor = boost_factor
|
10
|
+
end
|
11
|
+
|
12
|
+
def w00t
|
13
|
+
@boost_factor.times { 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
|
+
end
|
22
|
+
|
23
|
+
if __FILE__ == $0
|
24
|
+
clumsy = ClumsyPlayer.new("klutz")
|
25
|
+
|
26
|
+
hammer = Treasure.new(:hammer, 50)
|
27
|
+
clumsy.found_treasure(hammer)
|
28
|
+
clumsy.found_treasure(hammer)
|
29
|
+
clumsy.found_treasure(hammer)
|
30
|
+
|
31
|
+
crowbar = Treasure.new(:crowbar, 400)
|
32
|
+
clumsy.found_treasure(crowbar)
|
33
|
+
|
34
|
+
clumsy.each_found_treasure do |treasure|
|
35
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
36
|
+
end
|
37
|
+
puts "#{clumsy.points} grand total points"
|
38
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require_relative "player"
|
2
|
+
require_relative "die"
|
3
|
+
require_relative "game_turn"
|
4
|
+
require_relative "treasure_trove"
|
5
|
+
require "csv"
|
6
|
+
|
7
|
+
module StudioGame
|
8
|
+
class Game
|
9
|
+
attr_reader :title
|
10
|
+
|
11
|
+
def initialize(title)
|
12
|
+
@title = title
|
13
|
+
@players = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_player(player)
|
17
|
+
@players << player
|
18
|
+
end
|
19
|
+
|
20
|
+
def play(rounds)
|
21
|
+
puts "There are #{@players.size} players in #{@title}: "
|
22
|
+
|
23
|
+
@players.each do |player|
|
24
|
+
puts player
|
25
|
+
end
|
26
|
+
|
27
|
+
treasures = TreasureTrove::TREASURES
|
28
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
29
|
+
treasures.each do |treasure|
|
30
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
31
|
+
end
|
32
|
+
|
33
|
+
1.upto(rounds) do |round|
|
34
|
+
if block_given?
|
35
|
+
break if yield
|
36
|
+
end
|
37
|
+
puts "\nRound #{round}:"
|
38
|
+
@players.each do |player|
|
39
|
+
GameTurn.take_turn(player)
|
40
|
+
puts player
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def print_name_and_health(player)
|
46
|
+
puts "#{player.name} (#{player.health})"
|
47
|
+
end
|
48
|
+
|
49
|
+
def print_stats
|
50
|
+
strong, wimpy = @players.partition { |player| player.strong? }
|
51
|
+
puts "\n#{title} Statistics:"
|
52
|
+
|
53
|
+
puts "\n#{strong.size} strong players:"
|
54
|
+
strong.each { |player| print_name_and_health(player) }
|
55
|
+
|
56
|
+
puts "\n#{wimpy.size} wimpy players:"
|
57
|
+
wimpy.each { |player| print_name_and_health(player) }
|
58
|
+
|
59
|
+
puts "\n#{title} High Scores:"
|
60
|
+
@players.sort.each do |player|
|
61
|
+
puts high_score_entry(player)
|
62
|
+
end
|
63
|
+
|
64
|
+
@players.sort.each do |player|
|
65
|
+
puts "\n#{player.name}'s point totals:"
|
66
|
+
player.each_found_treasure do |treasure|
|
67
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
68
|
+
end
|
69
|
+
puts "#{player.points} grand total points"
|
70
|
+
end
|
71
|
+
|
72
|
+
puts "#{total_points} total points from treasures found"
|
73
|
+
end
|
74
|
+
|
75
|
+
def total_points
|
76
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
77
|
+
end
|
78
|
+
|
79
|
+
def load_players(from_file)
|
80
|
+
CSV.foreach(from_file) do |row|
|
81
|
+
player = Player.new(row[0], row[1].to_i)
|
82
|
+
add_player(player)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def save_high_scores(to_file="high_scores.txt")
|
87
|
+
File.open(to_file, "w") do |file|
|
88
|
+
file.puts "#{@title} High Scores:"
|
89
|
+
@players.sort.each do |player|
|
90
|
+
file.puts high_score_entry(player)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def high_score_entry(player)
|
96
|
+
formatted_name = player.name.ljust(20, '.')
|
97
|
+
"#{formatted_name} #{player.score}"
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative "die"
|
2
|
+
require_relative "treasure_trove"
|
3
|
+
require_relative "loaded_die"
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
module GameTurn
|
7
|
+
def self.take_turn(player)
|
8
|
+
die = Die.new
|
9
|
+
number_rolled = die.roll
|
10
|
+
case die.roll
|
11
|
+
when 5..6
|
12
|
+
player.w00t
|
13
|
+
when 3..4
|
14
|
+
puts "#{player.name} was skipped."
|
15
|
+
else
|
16
|
+
player.blam
|
17
|
+
end
|
18
|
+
treasure = TreasureTrove.random
|
19
|
+
player.found_treasure(treasure)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
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
|
9
|
+
attr_reader :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 name=(new_name)
|
18
|
+
@name = new_name.capitalize
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
23
|
+
end
|
24
|
+
|
25
|
+
def score
|
26
|
+
@health + points
|
27
|
+
end
|
28
|
+
|
29
|
+
def <=>(other)
|
30
|
+
other.score <=> score
|
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
|
+
end
|
37
|
+
|
38
|
+
def points
|
39
|
+
@found_treasures.values.reduce(0, :+)
|
40
|
+
end
|
41
|
+
|
42
|
+
def each_found_treasure
|
43
|
+
@found_treasures.each do |name, points|
|
44
|
+
yield(Treasure.new(name, points))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.from_csv(string)
|
49
|
+
name, health = string.split(',')
|
50
|
+
Player.new(name, Integer(health))
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
if __FILE__ == $0
|
56
|
+
player = Player.new("moe")
|
57
|
+
puts player.name
|
58
|
+
puts player.health
|
59
|
+
player.w00t
|
60
|
+
puts player.health
|
61
|
+
player.blam
|
62
|
+
puts player.health
|
63
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
|
2
|
+
module StudioGame
|
3
|
+
Treasure = Struct.new(:name, :points)
|
4
|
+
|
5
|
+
module TreasureTrove
|
6
|
+
|
7
|
+
TREASURES = [
|
8
|
+
Treasure.new(:pie, 5),
|
9
|
+
Treasure.new(:bottle, 25),
|
10
|
+
Treasure.new(:hammer, 50),
|
11
|
+
Treasure.new(:skillet, 100),
|
12
|
+
Treasure.new(:broomstick, 200),
|
13
|
+
Treasure.new(:crowbar, 400)
|
14
|
+
]
|
15
|
+
|
16
|
+
def self.random
|
17
|
+
TREASURES.sample
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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 be_falsey
|
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 be_truthy
|
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
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
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
|
+
context "with a boost factor" do
|
33
|
+
before do
|
34
|
+
@initial_health = 100
|
35
|
+
@boost_factor = 5
|
36
|
+
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a boost factor" do
|
40
|
+
@player.boost_factor.should == 5
|
41
|
+
end
|
42
|
+
|
43
|
+
it "gets boost factor number of w00ts when w00ted" do
|
44
|
+
@player.w00t
|
45
|
+
|
46
|
+
@player.health.should == @initial_health + (15 * @boost_factor)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Game do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@game = Game.new("Knuckleheads")
|
8
|
+
|
9
|
+
@initial_health = 100
|
10
|
+
@player = Player.new("moe", @initial_health)
|
11
|
+
|
12
|
+
@game.add_player(@player)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "w00ts the player if a high number is rolled" do
|
16
|
+
Die.any_instance.stub(:roll).and_return(5)
|
17
|
+
|
18
|
+
@game.play(2)
|
19
|
+
|
20
|
+
expect(@player.health).to eq(@initial_health + (15 * 2))
|
21
|
+
end
|
22
|
+
|
23
|
+
it "skips the player if a medium number is rolled" do
|
24
|
+
Die.any_instance.stub(:roll).and_return(3)
|
25
|
+
|
26
|
+
@game.play(2)
|
27
|
+
|
28
|
+
expect(@player.health).to eq(@initial_health)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "blams the player if a low number is rolled" do
|
32
|
+
Die.any_instance.stub(:roll).and_return(1)
|
33
|
+
|
34
|
+
@game.play(2)
|
35
|
+
|
36
|
+
expect(@player.health).to eq(@initial_health - (10 * 2))
|
37
|
+
end
|
38
|
+
|
39
|
+
it "assigns a treasure for points during a player's turn" do
|
40
|
+
game = Game.new("Knuckleheads")
|
41
|
+
player = Player.new("moe")
|
42
|
+
|
43
|
+
game.add_player(player)
|
44
|
+
|
45
|
+
game.play(1)
|
46
|
+
|
47
|
+
player.points.should_not be_zero
|
48
|
+
end
|
49
|
+
|
50
|
+
it "computes total points as the sum of all player points" do
|
51
|
+
game = Game.new("Knuckleheads")
|
52
|
+
|
53
|
+
player1 = Player.new("moe")
|
54
|
+
player2 = Player.new("larry")
|
55
|
+
|
56
|
+
game.add_player(player1)
|
57
|
+
game.add_player(player2)
|
58
|
+
|
59
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
60
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
61
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
62
|
+
|
63
|
+
game.total_points.should == 500
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
describe Player do
|
6
|
+
before do
|
7
|
+
$stdout = StringIO.new
|
8
|
+
@initial_health = 150
|
9
|
+
@player = Player.new("larry", @initial_health)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a capitalized name" do
|
13
|
+
expect(@player.name).to eq("Larry")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has an initial health" do
|
17
|
+
expect(@player.health).to eq(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 Larry with health = 150, points = 100, and score = 250."
|
25
|
+
end
|
26
|
+
|
27
|
+
it "computes a score as the sum of its health and points" do
|
28
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
29
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
30
|
+
|
31
|
+
@player.score.should == 250
|
32
|
+
end
|
33
|
+
|
34
|
+
it "increases health by 15 when w00ted" do
|
35
|
+
@player.w00t
|
36
|
+
|
37
|
+
expect(@player.health).to eq(@initial_health + 15)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "decreases health by 10 when blammed" do
|
41
|
+
@player.blam
|
42
|
+
|
43
|
+
expect(@player.health).to eq(@initial_health - 10)
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with a health greater than 100" do
|
47
|
+
before do
|
48
|
+
$stdout = StringIO.new
|
49
|
+
@player = Player.new("larry", 150)
|
50
|
+
end
|
51
|
+
|
52
|
+
it "is a strong player" do
|
53
|
+
expect(@player).to be_strong
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "with a health less than or equal to 100" do
|
58
|
+
before do
|
59
|
+
$stdout = StringIO.new
|
60
|
+
@player = Player.new("larry", 100)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "is a weak player" do
|
64
|
+
expect(@player).not_to be_strong
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
context "in a collection of players" do
|
69
|
+
before do
|
70
|
+
@player1 = Player.new("moe", 100)
|
71
|
+
@player2 = Player.new("larry", 200)
|
72
|
+
@player3 = Player.new("curly", 300)
|
73
|
+
|
74
|
+
@players = [@player1, @player2, @player3]
|
75
|
+
end
|
76
|
+
|
77
|
+
it "is sorted by decreasing score" do
|
78
|
+
@players.sort.should == [@player3, @player2, @player1]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
it "computes points as the sum of all treasure points" do
|
83
|
+
@player.points.should == 0
|
84
|
+
|
85
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
86
|
+
|
87
|
+
@player.points.should == 50
|
88
|
+
|
89
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
90
|
+
|
91
|
+
@player.points.should == 450
|
92
|
+
|
93
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
94
|
+
|
95
|
+
@player.points.should == 500
|
96
|
+
end
|
97
|
+
|
98
|
+
it "yields each found treasure and its total points" do
|
99
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
100
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
101
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
102
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
103
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
104
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
105
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
106
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
107
|
+
|
108
|
+
yielded = []
|
109
|
+
@player.each_found_treasure do |treasure|
|
110
|
+
yielded << treasure
|
111
|
+
end
|
112
|
+
|
113
|
+
yielded.should == [
|
114
|
+
Treasure.new(:skillet, 200),
|
115
|
+
Treasure.new(:hammer, 50),
|
116
|
+
Treasure.new(:bottle, 25)
|
117
|
+
]
|
118
|
+
end
|
119
|
+
|
120
|
+
it "can be created from a CSV string" do
|
121
|
+
player = Player.from_csv("larry,150")
|
122
|
+
|
123
|
+
player.name.should == "Larry"
|
124
|
+
player.health.should == 150
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'studio_game/treasure_trove'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe Treasure do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@treasure = Treasure.new(:hammer, 50)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a name attribute" do
|
11
|
+
@treasure.name.should == :hammer
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a points attribute" do
|
15
|
+
@treasure.points.should == 50
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe TreasureTrove do
|
21
|
+
|
22
|
+
it "has six treasures" do
|
23
|
+
TreasureTrove::TREASURES.size.should == 6
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a pie worth 5 points" do
|
27
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a bottle worth 25 points" do
|
31
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a hammer worth 50 points" do
|
35
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a skillet worth 100 points" do
|
39
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a broomstick worth 200 points" do
|
43
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a crowbar worth 400 points" do
|
47
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a random treasure" do
|
51
|
+
treasure = TreasureTrove.random
|
52
|
+
|
53
|
+
TreasureTrove::TREASURES.should include(treasure)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: murdoks_studio_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Collin Jilbert
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-11 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: 2.8.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.8'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.8'
|
33
|
+
description: This gem is designed to be a stand alone game or the modules can be used
|
34
|
+
to extend functionality into your program.
|
35
|
+
email: cjilbert504@gmail.com
|
36
|
+
executables:
|
37
|
+
- studio_game
|
38
|
+
extensions: []
|
39
|
+
extra_rdoc_files: []
|
40
|
+
files:
|
41
|
+
- LICENSE
|
42
|
+
- README
|
43
|
+
- bin/players.csv
|
44
|
+
- bin/studio_game
|
45
|
+
- lib/studio_game/auditable.rb
|
46
|
+
- lib/studio_game/berserk_player.rb
|
47
|
+
- lib/studio_game/clumsy_player.rb
|
48
|
+
- lib/studio_game/die.rb
|
49
|
+
- lib/studio_game/game.rb
|
50
|
+
- lib/studio_game/game_turn.rb
|
51
|
+
- lib/studio_game/high_scores.txt
|
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/clumsy_player_spec.rb
|
58
|
+
- spec/studio_game/game_spec.rb
|
59
|
+
- spec/studio_game/player_spec.rb
|
60
|
+
- spec/studio_game/spec_helper.rb
|
61
|
+
- spec/studio_game/treasure_trove_spec.rb
|
62
|
+
homepage: https://github.com/cjilbert504/studio_game
|
63
|
+
licenses:
|
64
|
+
- MIT
|
65
|
+
metadata: {}
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.9'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubygems_version: 3.0.8
|
82
|
+
signing_key:
|
83
|
+
specification_version: 4
|
84
|
+
summary: Fun little ruby game
|
85
|
+
test_files:
|
86
|
+
- spec/studio_game/spec_helper.rb
|
87
|
+
- spec/studio_game/clumsy_player_spec.rb
|
88
|
+
- spec/studio_game/treasure_trove_spec.rb
|
89
|
+
- spec/studio_game/berserk_player_spec.rb
|
90
|
+
- spec/studio_game/player_spec.rb
|
91
|
+
- spec/studio_game/game_spec.rb
|