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