chipmunk_treasure_island 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.
- data/LICENSE +21 -0
- data/README +1 -0
- data/bin/my_favorite_players.csv +3 -0
- data/bin/new_game +35 -0
- data/bin/players.csv +3 -0
- data/lib/new_game/auditable.rb +7 -0
- data/lib/new_game/berserk_player.rb +37 -0
- data/lib/new_game/clumsy_player.rb +34 -0
- data/lib/new_game/die.rb +19 -0
- data/lib/new_game/game.rb +108 -0
- data/lib/new_game/game_turn.rb +25 -0
- data/lib/new_game/loaded_die.rb +16 -0
- data/lib/new_game/playable.rb +18 -0
- data/lib/new_game/player.rb +63 -0
- data/lib/new_game/treasure_trove.rb +19 -0
- data/spec/new_game/berserk_player_spec.rb +30 -0
- data/spec/new_game/clumsy_player_spec.rb +33 -0
- data/spec/new_game/game_spec.rb +67 -0
- data/spec/new_game/player_spec.rb +133 -0
- data/spec/new_game/treasure_trove_spec.rb +56 -0
- metadata +88 -0
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2012 The Pragmatic Studio
|
|
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
|
+
- You may not use this Software in other training contexts.
|
|
11
|
+
|
|
12
|
+
- The above copyright notice and this permission notice shall be
|
|
13
|
+
included in all 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
|
|
21
|
+
THE SOFTWARE.
|
data/README
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
This is a simple text based Game written in Ruby. It allows the user to create a random action that will affect the players health as well as collecting treasures each round. The highest points after x amount of rounds win.
|
data/bin/new_game
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/new_game/game'
|
|
4
|
+
require_relative '../lib/new_game/clumsy_player'
|
|
5
|
+
require_relative '../lib/new_game/berserk_player'
|
|
6
|
+
|
|
7
|
+
module NewGame
|
|
8
|
+
klutz = ClumsyPlayer.new("klutz", 105)
|
|
9
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
10
|
+
knuckleheads = NewGame::Game.new("Knuckleheads")
|
|
11
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
|
12
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
|
13
|
+
knuckleheads.add_player(klutz)
|
|
14
|
+
knuckleheads.add_player(berserker)
|
|
15
|
+
|
|
16
|
+
loop do
|
|
17
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
|
18
|
+
answer = gets.chomp.downcase
|
|
19
|
+
case answer
|
|
20
|
+
when /^\d+$/
|
|
21
|
+
knuckleheads.play(answer.to_i) do
|
|
22
|
+
knuckleheads.total_points >= 2000
|
|
23
|
+
end
|
|
24
|
+
when 'quit' , 'exit'
|
|
25
|
+
knuckleheads.print_stats
|
|
26
|
+
break
|
|
27
|
+
else
|
|
28
|
+
puts "Please enter a number or 'quit'"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
knuckleheads.save_high_scores
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
data/bin/players.csv
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module NewGame
|
|
4
|
+
class BerserkPlayer < Player
|
|
5
|
+
|
|
6
|
+
def initialize(name, health=100)
|
|
7
|
+
super(name, health)
|
|
8
|
+
@w00t_count = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def berserk?
|
|
12
|
+
@w00t_count > 5
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def w00t
|
|
16
|
+
super
|
|
17
|
+
@w00t_count += 1
|
|
18
|
+
puts "#{@name} is berserk!" if berserk?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def blam
|
|
22
|
+
case berserk?
|
|
23
|
+
when true
|
|
24
|
+
w00t
|
|
25
|
+
when false
|
|
26
|
+
super
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if __FILE__ == $0
|
|
33
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
34
|
+
6.times { berserker.w00t }
|
|
35
|
+
2.times { berserker.blam }
|
|
36
|
+
puts berserker.health
|
|
37
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module NewGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
|
|
6
|
+
def found_treasure(treasure)
|
|
7
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2)
|
|
8
|
+
super damaged_treasure
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
if __FILE__ == $0
|
|
20
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
21
|
+
|
|
22
|
+
hammer = Treasure.new(:hammer, 50)
|
|
23
|
+
clumsy.found_treasure(hammer)
|
|
24
|
+
clumsy.found_treasure(hammer)
|
|
25
|
+
clumsy.found_treasure(hammer)
|
|
26
|
+
|
|
27
|
+
crowbar = Treasure.new(:crowbar, 400)
|
|
28
|
+
clumsy.found_treasure(crowbar)
|
|
29
|
+
|
|
30
|
+
clumsy.each_found_treasure do |treasure|
|
|
31
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
32
|
+
end
|
|
33
|
+
puts "#{clumsy.points} grand total points"
|
|
34
|
+
end
|
data/lib/new_game/die.rb
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'game_turn'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
require 'csv'
|
|
6
|
+
|
|
7
|
+
module NewGame
|
|
8
|
+
class Game
|
|
9
|
+
|
|
10
|
+
attr_reader :title
|
|
11
|
+
|
|
12
|
+
def initialize(title)
|
|
13
|
+
@title = title
|
|
14
|
+
@players = []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def add_player(a_player)
|
|
18
|
+
@players.push(a_player)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def load_players(from_file)
|
|
22
|
+
CSV.foreach(from_file) do |row|
|
|
23
|
+
player = Player.new(row[0], row[1].to_i)
|
|
24
|
+
add_player(player)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def high_score_entry(player)
|
|
29
|
+
formatted_name = player.name.ljust(20, '.')
|
|
30
|
+
"#{formatted_name} #{player.score}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def save_high_scores(to_file="high_score.txt")
|
|
34
|
+
File.open(to_file, "w") do |file|
|
|
35
|
+
file.puts "#{@title} High Scores:"
|
|
36
|
+
@players.sort.each do |player|
|
|
37
|
+
file.puts high_score_entry(player)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def play(rounds)
|
|
43
|
+
puts "There are #{@players.size} in #{@title}."
|
|
44
|
+
|
|
45
|
+
@players.each do |player|
|
|
46
|
+
puts player
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
treasures = TreasureTrove::TREASURES
|
|
50
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
|
51
|
+
treasures.each do |treasure|
|
|
52
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
|
53
|
+
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
1.upto(rounds) do |round|
|
|
57
|
+
if block_given?
|
|
58
|
+
break if yield
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
puts "\nRound #{round}:"
|
|
62
|
+
@players.each do |player|
|
|
63
|
+
GameTurn.take_turn(player)
|
|
64
|
+
puts player
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def print_name_and_health(player)
|
|
70
|
+
puts "#{player.name} (#{player.health})"
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def total_points
|
|
74
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def print_stats
|
|
78
|
+
puts "\n#{@title} Statistics:"
|
|
79
|
+
|
|
80
|
+
strong_players, wimpy_players = @players.partition{ |player| player.strong?}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
puts "\n#{strong_players.size} strong players:"
|
|
84
|
+
strong_players.each do |player|
|
|
85
|
+
print_name_and_health(player)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
puts "\n#{wimpy_players.size} wimpy players:"
|
|
89
|
+
wimpy_players.each do |player|
|
|
90
|
+
print_name_and_health(player)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
puts "\n#{total_points} total points from treasures found"
|
|
94
|
+
@players.sort.each do |player|
|
|
95
|
+
puts "\n#{player.name}'s point totals:"
|
|
96
|
+
player.each_found_treasure do |treasure|
|
|
97
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
98
|
+
end
|
|
99
|
+
puts "#{player.points} grand total points"
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
puts "\n#{@title} High Scores:"
|
|
103
|
+
@players.sort.each do |player|
|
|
104
|
+
puts high_score_entry(player)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'loaded_die'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
|
|
6
|
+
module NewGame
|
|
7
|
+
module GameTurn
|
|
8
|
+
def self.take_turn (player)
|
|
9
|
+
|
|
10
|
+
die = Die.new
|
|
11
|
+
case die.roll
|
|
12
|
+
|
|
13
|
+
when 1..2
|
|
14
|
+
player.blam
|
|
15
|
+
when 3..4
|
|
16
|
+
puts "#{player.name} was skipped"
|
|
17
|
+
else
|
|
18
|
+
player.w00t
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
treasure = TreasureTrove.random
|
|
22
|
+
player.found_treasure(treasure)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
require_relative 'playable'
|
|
3
|
+
|
|
4
|
+
module NewGame
|
|
5
|
+
class Player
|
|
6
|
+
|
|
7
|
+
include Playable
|
|
8
|
+
|
|
9
|
+
attr_accessor :name
|
|
10
|
+
attr_accessor :health
|
|
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 score
|
|
19
|
+
@health + points
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def to_s
|
|
23
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def <=>(other)
|
|
27
|
+
other.score <=> score
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def found_treasure(treasure)
|
|
31
|
+
@found_treasures[treasure.name] += treasure.points
|
|
32
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
|
33
|
+
puts "#{@name}'s treasures: #{@found_treasures}"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def points
|
|
37
|
+
@found_treasures.values.reduce(0, :+)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def each_found_treasure
|
|
41
|
+
@found_treasures.each do |name, points|
|
|
42
|
+
treasure = Treasure.new(name, points)
|
|
43
|
+
yield treasure
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.from_csv(string)
|
|
48
|
+
name, health = string.split(',')
|
|
49
|
+
new(name, Integer(health))
|
|
50
|
+
end
|
|
51
|
+
|
|
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,19 @@
|
|
|
1
|
+
module NewGame
|
|
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
|
+
|
|
15
|
+
def self.random
|
|
16
|
+
TREASURES.sample
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'new_game/berserk_player'
|
|
2
|
+
|
|
3
|
+
module NewGame
|
|
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_false
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "goes berserk when w00ted more than 5 times" do
|
|
18
|
+
1.upto(6) { @player.w00t }
|
|
19
|
+
|
|
20
|
+
@player.berserk?.should 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
|
+
@player.health.should == @initial_health + (8 * 15)
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'new_game/clumsy_player'
|
|
2
|
+
|
|
3
|
+
module NewGame
|
|
4
|
+
describe ClumsyPlayer do
|
|
5
|
+
before do
|
|
6
|
+
@player = ClumsyPlayer.new("klutz")
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it "only gets half the point value for each treasure" do
|
|
10
|
+
@player.points.should == 0
|
|
11
|
+
|
|
12
|
+
hammer = Treasure.new(:hammer, 50)
|
|
13
|
+
@player.found_treasure(hammer)
|
|
14
|
+
@player.found_treasure(hammer)
|
|
15
|
+
@player.found_treasure(hammer)
|
|
16
|
+
|
|
17
|
+
@player.points.should == 75
|
|
18
|
+
|
|
19
|
+
crowbar = Treasure.new(:crowbar, 400)
|
|
20
|
+
@player.found_treasure(crowbar)
|
|
21
|
+
|
|
22
|
+
@player.points.should == 275
|
|
23
|
+
|
|
24
|
+
yielded = []
|
|
25
|
+
@player.each_found_treasure do |treasure|
|
|
26
|
+
yielded << treasure
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
require 'new_game/game'
|
|
2
|
+
|
|
3
|
+
module NewGame
|
|
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
|
+
|
|
16
|
+
it "woots a player if a high number is rolled" do
|
|
17
|
+
Die.any_instance.stub(:roll).and_return(5)
|
|
18
|
+
|
|
19
|
+
@game.play(2)
|
|
20
|
+
|
|
21
|
+
@player.health.should == @initial_health + (15 * 2)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "skips a player if a medium number is rolled" do
|
|
25
|
+
Die.any_instance.stub(:roll).and_return(3)
|
|
26
|
+
|
|
27
|
+
@game.play(2)
|
|
28
|
+
|
|
29
|
+
@player.health.should == @initial_health
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it "blams a player if a low number is rolled" do
|
|
33
|
+
Die.any_instance.stub(:roll).and_return(1)
|
|
34
|
+
|
|
35
|
+
@game.play(2)
|
|
36
|
+
|
|
37
|
+
@player.health.should == @initial_health - (10 * 2)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "assigns a treasure for points during a player's turn" do
|
|
41
|
+
game = Game.new("Knuckleheads")
|
|
42
|
+
player = Player.new("moe")
|
|
43
|
+
|
|
44
|
+
game.add_player(player)
|
|
45
|
+
|
|
46
|
+
game.play(1)
|
|
47
|
+
|
|
48
|
+
player.points.should_not be_zero
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it "computes total points as the sum of all player points" do
|
|
52
|
+
game = Game.new("Knuckleheads")
|
|
53
|
+
|
|
54
|
+
player1 = Player.new("moe")
|
|
55
|
+
player2 = Player.new("larry")
|
|
56
|
+
|
|
57
|
+
game.add_player(player1)
|
|
58
|
+
game.add_player(player2)
|
|
59
|
+
|
|
60
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
|
61
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
|
62
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
|
63
|
+
|
|
64
|
+
game.total_points.should == 500
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
require 'new_game/player'
|
|
2
|
+
require 'new_game/treasure_trove'
|
|
3
|
+
|
|
4
|
+
module NewGame
|
|
5
|
+
describe Player do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@initial_health = 150
|
|
9
|
+
@player = Player.new("larry", @initial_health)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
before do
|
|
13
|
+
$stdout = StringIO.new
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "has a capitalized name" do
|
|
17
|
+
|
|
18
|
+
@player.name.should == "Larry"
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it "has an initial health" do
|
|
22
|
+
|
|
23
|
+
@player.health.should == @initial_health
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "has a string representation" do
|
|
27
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
28
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
29
|
+
|
|
30
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
it "computes a score as the sum of its health and points" do
|
|
34
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
35
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
36
|
+
|
|
37
|
+
@player.score.should == 250
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
it "increases health by 15 when w00ted" do
|
|
42
|
+
|
|
43
|
+
@player.w00t
|
|
44
|
+
@player.health.should == @initial_health + 15
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "decreases health by 10 when blammed" do
|
|
48
|
+
|
|
49
|
+
@player.blam
|
|
50
|
+
@player.health.should == @initial_health - 10
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "can be created from a CSV string" do
|
|
54
|
+
player = Player.from_csv("larry,150")
|
|
55
|
+
|
|
56
|
+
player.name.should == "Larry"
|
|
57
|
+
player.health.should == 150
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "computes points as the sum of all treasure points" do
|
|
61
|
+
@player.points.should == 0
|
|
62
|
+
|
|
63
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
64
|
+
|
|
65
|
+
@player.points.should == 50
|
|
66
|
+
|
|
67
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
|
68
|
+
|
|
69
|
+
@player.points.should == 450
|
|
70
|
+
|
|
71
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
72
|
+
|
|
73
|
+
@player.points.should == 500
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
it "yields each found treasure and its total points" do
|
|
77
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
78
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
79
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
80
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
81
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
82
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
83
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
84
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
85
|
+
|
|
86
|
+
yielded = []
|
|
87
|
+
@player.each_found_treasure do |treasure|
|
|
88
|
+
yielded << treasure
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
yielded.should == [
|
|
92
|
+
Treasure.new(:skillet, 200),
|
|
93
|
+
Treasure.new(:hammer, 50),
|
|
94
|
+
Treasure.new(:bottle, 25)
|
|
95
|
+
]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
context "has a health greater than 100" do
|
|
99
|
+
before do
|
|
100
|
+
@player = Player.new("moe", 150)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
it "is a strong player" do
|
|
104
|
+
@player.should be_strong
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "has a health of 100 or less" do
|
|
109
|
+
before do
|
|
110
|
+
@player = Player.new("moe", 100)
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "is a weak player" do
|
|
114
|
+
@player.should_not be_strong
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
context "in a collection of players" do
|
|
119
|
+
before do
|
|
120
|
+
@player1 = Player.new("moe", 100)
|
|
121
|
+
@player2 = Player.new("larry", 200)
|
|
122
|
+
@player3 = Player.new("curly", 300)
|
|
123
|
+
|
|
124
|
+
@players = [@player1, @player2, @player3]
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
it "is sorted by decreasing score" do
|
|
128
|
+
@players.sort.should == [@player3, @player2, @player1]
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'new_game/treasure_trove'
|
|
2
|
+
|
|
3
|
+
module NewGame
|
|
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,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: chipmunk_treasure_island
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Gabriel Lafontant
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-04-26 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rspec
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ! '>='
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '0'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ! '>='
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '0'
|
|
30
|
+
description: ! 'This is a simple text based Game written in Ruby. It allows the user
|
|
31
|
+
to create a random action that will affect the players health as well as collecting
|
|
32
|
+
treasures each round. The highest points after x amount of rounds win. '
|
|
33
|
+
email: glafonta@gmail.com
|
|
34
|
+
executables:
|
|
35
|
+
- new_game
|
|
36
|
+
extensions: []
|
|
37
|
+
extra_rdoc_files: []
|
|
38
|
+
files:
|
|
39
|
+
- bin/my_favorite_players.csv
|
|
40
|
+
- bin/new_game
|
|
41
|
+
- bin/players.csv
|
|
42
|
+
- lib/new_game/auditable.rb
|
|
43
|
+
- lib/new_game/berserk_player.rb
|
|
44
|
+
- lib/new_game/clumsy_player.rb
|
|
45
|
+
- lib/new_game/die.rb
|
|
46
|
+
- lib/new_game/game.rb
|
|
47
|
+
- lib/new_game/game_turn.rb
|
|
48
|
+
- lib/new_game/loaded_die.rb
|
|
49
|
+
- lib/new_game/playable.rb
|
|
50
|
+
- lib/new_game/player.rb
|
|
51
|
+
- lib/new_game/treasure_trove.rb
|
|
52
|
+
- spec/new_game/berserk_player_spec.rb
|
|
53
|
+
- spec/new_game/clumsy_player_spec.rb
|
|
54
|
+
- spec/new_game/game_spec.rb
|
|
55
|
+
- spec/new_game/player_spec.rb
|
|
56
|
+
- spec/new_game/treasure_trove_spec.rb
|
|
57
|
+
- LICENSE
|
|
58
|
+
- README
|
|
59
|
+
homepage: http://pragmaticstudio.com
|
|
60
|
+
licenses: []
|
|
61
|
+
post_install_message:
|
|
62
|
+
rdoc_options: []
|
|
63
|
+
require_paths:
|
|
64
|
+
- lib
|
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
none: false
|
|
67
|
+
requirements:
|
|
68
|
+
- - ! '>='
|
|
69
|
+
- !ruby/object:Gem::Version
|
|
70
|
+
version: '1.9'
|
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
72
|
+
none: false
|
|
73
|
+
requirements:
|
|
74
|
+
- - ! '>='
|
|
75
|
+
- !ruby/object:Gem::Version
|
|
76
|
+
version: '0'
|
|
77
|
+
requirements: []
|
|
78
|
+
rubyforge_project:
|
|
79
|
+
rubygems_version: 1.8.24
|
|
80
|
+
signing_key:
|
|
81
|
+
specification_version: 3
|
|
82
|
+
summary: A fun, and entirely random, text-based game
|
|
83
|
+
test_files:
|
|
84
|
+
- spec/new_game/berserk_player_spec.rb
|
|
85
|
+
- spec/new_game/clumsy_player_spec.rb
|
|
86
|
+
- spec/new_game/game_spec.rb
|
|
87
|
+
- spec/new_game/player_spec.rb
|
|
88
|
+
- spec/new_game/treasure_trove_spec.rb
|