ToccoStudioGame 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.txt +19 -0
- data/README.txt +3 -0
- data/bin/high_scores.txt +7 -0
- data/bin/players.txt +4 -0
- data/bin/tocco_studio_game +41 -0
- data/lib/tocco_studio_game/auditable.rb +8 -0
- data/lib/tocco_studio_game/berserk_player.rb +36 -0
- data/lib/tocco_studio_game/clumsy_player.rb +35 -0
- data/lib/tocco_studio_game/die.rb +14 -0
- data/lib/tocco_studio_game/game.rb +95 -0
- data/lib/tocco_studio_game/game_turn.rb +24 -0
- data/lib/tocco_studio_game/loaded_die.rb +14 -0
- data/lib/tocco_studio_game/playable.rb +21 -0
- data/lib/tocco_studio_game/player.rb +41 -0
- data/lib/tocco_studio_game/treasure_trove.rb +21 -0
- data/spec/tocco_studio_game/berserk_player_spec.rb +36 -0
- data/spec/tocco_studio_game/clumsy_player_spec.rb +32 -0
- data/spec/tocco_studio_game/game_spec.rb +40 -0
- data/spec/tocco_studio_game/movie_spec.rb +53 -0
- data/spec/tocco_studio_game/player_spec.rb +93 -0
- data/spec/tocco_studio_game/treasure_trove_spec.rb +55 -0
- metadata +85 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: df6563f7e5773b339c939d5397325a504a1d4efc
|
4
|
+
data.tar.gz: f248e50d3174b468bae6201a397a268b64d0879d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a42230e1593651d39c8da9852f4d93d9b382aa3855907a270ceeff8cebb8c58e82c695d15bde4fe1f8da9b1fc5b1df0d32bbf1afb1390d435b41ce5d59928b7
|
7
|
+
data.tar.gz: 806b3f1a4d232c35de229a673dbe94253d2ff00bc069a4de810c134a10bf2571191a4feb39ad44dadd3e4fdfcc4ac1d9699036cdf7690d6669b5cf207346ebce
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) <year> <copyright holders>
|
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.txt
ADDED
data/bin/high_scores.txt
ADDED
data/bin/players.txt
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/tocco_studio_game/game'
|
3
|
+
require_relative '../lib/tocco_studio_game/player'
|
4
|
+
require_relative '../lib/tocco_studio_game/clumsy_player'
|
5
|
+
require_relative '../lib/tocco_studio_game/berserk_player'
|
6
|
+
|
7
|
+
module ToccoStudioGame
|
8
|
+
=begin
|
9
|
+
player1 = Player.new("moe")
|
10
|
+
player2 = Player.new("larry", 60)
|
11
|
+
player3 = Player.new("curly", 125)
|
12
|
+
player4 = Player.new("shemp", 90)
|
13
|
+
players = [player1,player2,player3,player4]
|
14
|
+
=end
|
15
|
+
|
16
|
+
game1 = ToccoStudioGame::Game.new("Knuckleheads")
|
17
|
+
#players.each do |player|
|
18
|
+
#game1.add_player(player)
|
19
|
+
#end
|
20
|
+
#game1.play(100)
|
21
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.txt')
|
22
|
+
game1.load(ARGV.shift || default_player_file)
|
23
|
+
klutz = ClumsyPlayer.new("klutz",105)
|
24
|
+
game1.add_player(klutz)
|
25
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
26
|
+
game1.add_player(berserker)
|
27
|
+
loop do
|
28
|
+
puts "How many Rounds (Q to exit)?"
|
29
|
+
answer = gets.chomp.upcase
|
30
|
+
case answer
|
31
|
+
when /^\d+$/
|
32
|
+
"Playing #{answer} rounds"
|
33
|
+
game1.play(answer.to_i)
|
34
|
+
when 'Q'
|
35
|
+
break
|
36
|
+
else
|
37
|
+
puts "Enter a number or Quit"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
game1.save("high_scores.txt")
|
41
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
module ToccoStudioGame
|
3
|
+
class BerserkPlayer < Player
|
4
|
+
def initialize(name, health=100)
|
5
|
+
super(name, health)
|
6
|
+
@w00tCount = 0
|
7
|
+
end
|
8
|
+
|
9
|
+
def berserk?
|
10
|
+
if @w00tCount > 5
|
11
|
+
true
|
12
|
+
else
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def w00t
|
18
|
+
super
|
19
|
+
@w00tCount += 1
|
20
|
+
puts "#{@name} is berserk!" if berserk?
|
21
|
+
end
|
22
|
+
def blam
|
23
|
+
if berserk?
|
24
|
+
w00t
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
if __FILE__ == $0
|
30
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
31
|
+
6.times { berserker.w00t }
|
32
|
+
3.times {berserker.blam}
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
module ToccoStudioGame
|
3
|
+
class ClumsyPlayer < Player
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
def found_treasure(treasure)
|
8
|
+
treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
9
|
+
super(treasure)
|
10
|
+
end
|
11
|
+
def w00t
|
12
|
+
super
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
if __FILE__ == $0
|
18
|
+
clumsy = ClumsyPlayer.new("klutz")
|
19
|
+
|
20
|
+
hammer = Treasure.new(:hammer, 50)
|
21
|
+
clumsy.found_treasure(hammer)
|
22
|
+
clumsy.found_treasure(hammer)
|
23
|
+
clumsy.found_treasure(hammer)
|
24
|
+
|
25
|
+
crowbar = Treasure.new(:crowbar, 400)
|
26
|
+
clumsy.found_treasure(crowbar)
|
27
|
+
|
28
|
+
clumsy.each_found_treasure do |treasure|
|
29
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
30
|
+
end
|
31
|
+
puts "#{clumsy.points} grand total points"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'game_turn'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
module ToccoStudioGame
|
5
|
+
class Game
|
6
|
+
attr_reader :title
|
7
|
+
def initialize(title)
|
8
|
+
@title = title
|
9
|
+
@players = []
|
10
|
+
|
11
|
+
end
|
12
|
+
def load(file_name)
|
13
|
+
File.open(file_name) do |file|
|
14
|
+
file.each_line do |line|
|
15
|
+
player,health = line.split(/[\s,]/)
|
16
|
+
playerAdd = Player.new(player, Integer(health))
|
17
|
+
add_player(playerAdd)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def save(file_name = "high_scores.txt")
|
22
|
+
File.open(file_name, 'w') do |file|
|
23
|
+
file.puts "#{@title} High Scores:"
|
24
|
+
@players.sort.each do |player|
|
25
|
+
file.puts high_score_entry(player)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
def add_player(aPlayer)
|
33
|
+
@players << aPlayer
|
34
|
+
end
|
35
|
+
def high_score_entry(player)
|
36
|
+
"#{player.name} ....... #{player.score}"
|
37
|
+
end
|
38
|
+
def play(rounds)
|
39
|
+
winCheck = false
|
40
|
+
puts "There are #{@players.size} players in #{title}:"
|
41
|
+
@players.each do |player|
|
42
|
+
puts player
|
43
|
+
end
|
44
|
+
treasures = TreasureTrove::TREASURES
|
45
|
+
puts "There are #{treasures.length} treasures to be found."
|
46
|
+
treasures.each do |item|
|
47
|
+
puts "A #{item.name} is worth #{item.points} points"
|
48
|
+
end
|
49
|
+
rounds.times do |count|
|
50
|
+
puts "Round #{count+1} \n----------------------------------------"
|
51
|
+
@players.each do |player|
|
52
|
+
GameTurn.take_turn(player)
|
53
|
+
puts player
|
54
|
+
if player.score >= 500000
|
55
|
+
winCheck = true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
break if winCheck == true
|
59
|
+
end
|
60
|
+
print_stats
|
61
|
+
end
|
62
|
+
def print_stats
|
63
|
+
puts "#{@title} Statistics:"
|
64
|
+
strongPlayers = []
|
65
|
+
wimpyPlayers =[]
|
66
|
+
@players.each do |player|
|
67
|
+
if player.strong? == true
|
68
|
+
strongPlayers << "#{player.name}(#{player.health})"
|
69
|
+
else
|
70
|
+
wimpyPlayers << "#{player.name}(#{player.health})"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
puts "#{strongPlayers.length} Strong Players:"
|
74
|
+
puts strongPlayers
|
75
|
+
puts "#{wimpyPlayers.length} Wimpy Players"
|
76
|
+
puts wimpyPlayers
|
77
|
+
puts "#{title} High Scores:"
|
78
|
+
highScores = @players.sort
|
79
|
+
highScores.each do |player|
|
80
|
+
puts high_score_entry(player)
|
81
|
+
end
|
82
|
+
puts "\n"
|
83
|
+
@players.each do|player|
|
84
|
+
puts "#{player.name}'s Point Totals:"
|
85
|
+
player.each_found_treasure do |treasure|
|
86
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
87
|
+
end
|
88
|
+
puts "#{player.score} grand total points \n"
|
89
|
+
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'player'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
require_relative 'loaded_die'
|
5
|
+
module ToccoStudioGame
|
6
|
+
module GameTurn
|
7
|
+
def self.take_turn(player)
|
8
|
+
die = Die.new
|
9
|
+
numRolled = die.roll
|
10
|
+
puts "#{player.name} rolled a #{numRolled}"
|
11
|
+
case numRolled
|
12
|
+
when 1..2
|
13
|
+
player.blam
|
14
|
+
when 3..4
|
15
|
+
puts "Player Skipped"
|
16
|
+
else
|
17
|
+
player.w00t
|
18
|
+
end
|
19
|
+
foundTreasure = TreasureTrove.random
|
20
|
+
player.found_treasure(foundTreasure)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ToccoStudioGame
|
2
|
+
module Playable
|
3
|
+
def blam
|
4
|
+
@health -= 10
|
5
|
+
puts "#{@name} got blammed!"
|
6
|
+
end
|
7
|
+
def w00t
|
8
|
+
@health += 15
|
9
|
+
puts "#{@name} got w00ted"
|
10
|
+
end
|
11
|
+
|
12
|
+
def strong?
|
13
|
+
case health
|
14
|
+
when 0..99
|
15
|
+
false
|
16
|
+
else
|
17
|
+
true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
module ToccoStudioGame
|
4
|
+
class Player
|
5
|
+
include Playable
|
6
|
+
attr_reader :health
|
7
|
+
attr_accessor :name
|
8
|
+
def initialize(name,health=100)
|
9
|
+
@name = name.capitalize
|
10
|
+
@health = health
|
11
|
+
@found_treasures = Hash.new(0)
|
12
|
+
end
|
13
|
+
def to_s
|
14
|
+
"I'm #{@name} with health = #{@health}, points = #{points} and score = #{score}."
|
15
|
+
end
|
16
|
+
|
17
|
+
def score
|
18
|
+
@health + points
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def <=>(otherPlayer)
|
23
|
+
otherPlayer.score <=> score
|
24
|
+
end
|
25
|
+
def found_treasure(treasure)
|
26
|
+
@found_treasures[treasure.name] += treasure.points
|
27
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points"
|
28
|
+
puts "#{@name}'s Treasures: #{@found_treasures}"
|
29
|
+
end
|
30
|
+
def points
|
31
|
+
@found_treasures.values.reduce(0, :+)
|
32
|
+
end
|
33
|
+
def each_found_treasure
|
34
|
+
@found_treasures.each do |name,points|
|
35
|
+
treasure = Treasure.new(name,points)
|
36
|
+
yield(treasure)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module ToccoStudioGame
|
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
|
+
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'berserk_player'
|
2
|
+
module ToccoStudioGame
|
3
|
+
describe BerserkPlayer do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@initial_health = 50
|
7
|
+
@player = 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_false
|
14
|
+
|
15
|
+
# or if using Rspec 3.0:
|
16
|
+
# @player.berserk?.should be_falsey
|
17
|
+
end
|
18
|
+
|
19
|
+
it "goes berserk when w00ted more than 5 times" do
|
20
|
+
1.upto(6) { @player.w00t }
|
21
|
+
|
22
|
+
@player.berserk?.should be_true
|
23
|
+
|
24
|
+
# or if using Rspec 3.0:
|
25
|
+
# @player.berserk?.should be_truthy
|
26
|
+
end
|
27
|
+
|
28
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
29
|
+
1.upto(6) { @player.w00t }
|
30
|
+
1.upto(2) { @player.blam }
|
31
|
+
|
32
|
+
@player.health.should == @initial_health + (8 * 15)
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'clumsy_player'
|
2
|
+
module ToccoStudioGame
|
3
|
+
describe ClumsyPlayer do
|
4
|
+
before do
|
5
|
+
@player = 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 = 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 = 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 == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'game'
|
2
|
+
require 'player'
|
3
|
+
module ToccoStudioGame
|
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
|
+
@game.play(3)
|
18
|
+
@player.health.should == @initial_health + (15*3)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "passes the player if a medium number is rolled" do
|
22
|
+
Die.any_instance.stub(:roll).and_return(3)
|
23
|
+
@game.play(3)
|
24
|
+
@player.health.should == @initial_health
|
25
|
+
end
|
26
|
+
|
27
|
+
it "blams the player if a low number is rolled" do
|
28
|
+
Die.any_instance.stub(:roll).and_return(2)
|
29
|
+
@game.play(3)
|
30
|
+
@player.health.should == @initial_health - (10*3)
|
31
|
+
end
|
32
|
+
it "assigns a treasure for points during a player's turn" do
|
33
|
+
game = Game.new("Knuckleheads")
|
34
|
+
player = Player.new("moe")
|
35
|
+
game.add_player(player)
|
36
|
+
game.play(1)
|
37
|
+
player.points.should_not be_zero
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'movie'
|
2
|
+
module ToccoStudioGame
|
3
|
+
describe Movie do
|
4
|
+
before do
|
5
|
+
@movie = Movie.new("goonies", 10)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "has a capitalized title" do
|
9
|
+
@movie.title.should == "Goonies"
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has an initial rank" do
|
13
|
+
@movie.rank.should == 10
|
14
|
+
end
|
15
|
+
|
16
|
+
it "increases rank by one" do
|
17
|
+
@movie.thumbs_up.should == 11
|
18
|
+
end
|
19
|
+
|
20
|
+
it "decreases rank by one" do
|
21
|
+
@movie.thumbs_down.should == 9
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
context "created with a default rank" do
|
26
|
+
before do
|
27
|
+
@movie = Movie.new("goonies")
|
28
|
+
end
|
29
|
+
it "has a rank of 0" do
|
30
|
+
@movie.rank.should == 0
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "with a rank of at least 10" do
|
35
|
+
before do
|
36
|
+
@movie = Movie.new("goonies", 10)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "is a hit" do
|
40
|
+
@movie.hit?.should == true
|
41
|
+
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context "movie has a rank of less than 10" do
|
45
|
+
before do
|
46
|
+
@movie = Movie.new("goonies", 9)
|
47
|
+
end
|
48
|
+
it "is not a hit" do
|
49
|
+
@movie.hit?.should == false
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'player'
|
2
|
+
require 'treasure_trove'
|
3
|
+
module ToccoStudioGame
|
4
|
+
describe Player do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@initialHealth = 150
|
8
|
+
@player = Player.new("larry", @initialHealth)
|
9
|
+
end
|
10
|
+
it "has a capitalized name" do
|
11
|
+
@player.name.should == "Larry"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has an initial health" do
|
15
|
+
@player.health.should == @initialHealth
|
16
|
+
end
|
17
|
+
it "has a string representation" do
|
18
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
19
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
20
|
+
|
21
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100 and score = 250."
|
22
|
+
end
|
23
|
+
|
24
|
+
it "increases health by 15 when w00ted" do
|
25
|
+
@player.w00t
|
26
|
+
@player.health.should == @initialHealth + 15
|
27
|
+
end
|
28
|
+
it "decreases health by 10 when blammed" do
|
29
|
+
@player.blam
|
30
|
+
@player.health.should == @initialHealth - 10
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with a health of greater than 100" do
|
34
|
+
before do
|
35
|
+
@player = Player.new("larry", 150)
|
36
|
+
end
|
37
|
+
it "is strong" do
|
38
|
+
@player.should be_strong
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
context "with a health of less than 100" do
|
43
|
+
before do
|
44
|
+
@player = Player.new("larry", 90)
|
45
|
+
end
|
46
|
+
it "is wimpy" do
|
47
|
+
@player.should_not be_strong
|
48
|
+
end
|
49
|
+
end
|
50
|
+
it "computes points as the sum of all treasure points" do
|
51
|
+
@player.points.should == 0
|
52
|
+
|
53
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
54
|
+
|
55
|
+
@player.points.should == 50
|
56
|
+
|
57
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
58
|
+
|
59
|
+
@player.points.should == 450
|
60
|
+
|
61
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
62
|
+
|
63
|
+
@player.points.should == 500
|
64
|
+
end
|
65
|
+
it "computes a score as the sum of its health and points" do
|
66
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
67
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
68
|
+
|
69
|
+
@player.score.should == 250
|
70
|
+
end
|
71
|
+
it "yields each found treasure and its total points" do
|
72
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
73
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
74
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
75
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
76
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
77
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
78
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
79
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
80
|
+
|
81
|
+
yielded = []
|
82
|
+
@player.each_found_treasure do |treasure|
|
83
|
+
yielded << treasure
|
84
|
+
end
|
85
|
+
|
86
|
+
yielded.should == [
|
87
|
+
Treasure.new(:skillet, 200),
|
88
|
+
Treasure.new(:hammer, 50),
|
89
|
+
Treasure.new(:bottle, 25)
|
90
|
+
]
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'treasure_trove'
|
2
|
+
module ToccoStudioGame
|
3
|
+
describe Treasure do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@treasure = 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 TreasureTrove do
|
20
|
+
|
21
|
+
it "has six treasures" do
|
22
|
+
TreasureTrove::TREASURES.size.should == 6
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a pie worth 5 points" do
|
26
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a bottle worth 25 points" do
|
30
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has a hammer worth 50 points" do
|
34
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a skillet worth 100 points" do
|
38
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has a broomstick worth 200 points" do
|
42
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has a crowbar worth 400 points" do
|
46
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
47
|
+
end
|
48
|
+
it "returns a random treasure" do
|
49
|
+
treasure = TreasureTrove.random
|
50
|
+
|
51
|
+
TreasureTrove::TREASURES.should include(treasure)
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ToccoStudioGame
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Caleb Tocco
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-05-03 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: FUN GAME
|
28
|
+
email: caleb.tocco@radicalbear.com
|
29
|
+
executables:
|
30
|
+
- tocco_studio_game
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE.txt
|
35
|
+
- README.txt
|
36
|
+
- bin/high_scores.txt
|
37
|
+
- bin/players.txt
|
38
|
+
- bin/tocco_studio_game
|
39
|
+
- lib/tocco_studio_game/auditable.rb
|
40
|
+
- lib/tocco_studio_game/berserk_player.rb
|
41
|
+
- lib/tocco_studio_game/clumsy_player.rb
|
42
|
+
- lib/tocco_studio_game/die.rb
|
43
|
+
- lib/tocco_studio_game/game.rb
|
44
|
+
- lib/tocco_studio_game/game_turn.rb
|
45
|
+
- lib/tocco_studio_game/loaded_die.rb
|
46
|
+
- lib/tocco_studio_game/playable.rb
|
47
|
+
- lib/tocco_studio_game/player.rb
|
48
|
+
- lib/tocco_studio_game/treasure_trove.rb
|
49
|
+
- spec/tocco_studio_game/berserk_player_spec.rb
|
50
|
+
- spec/tocco_studio_game/clumsy_player_spec.rb
|
51
|
+
- spec/tocco_studio_game/game_spec.rb
|
52
|
+
- spec/tocco_studio_game/movie_spec.rb
|
53
|
+
- spec/tocco_studio_game/player_spec.rb
|
54
|
+
- spec/tocco_studio_game/treasure_trove_spec.rb
|
55
|
+
homepage: https://www.google.com
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.9'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 2.6.14
|
76
|
+
signing_key:
|
77
|
+
specification_version: 4
|
78
|
+
summary: Fun Game
|
79
|
+
test_files:
|
80
|
+
- spec/tocco_studio_game/clumsy_player_spec.rb
|
81
|
+
- spec/tocco_studio_game/treasure_trove_spec.rb
|
82
|
+
- spec/tocco_studio_game/berserk_player_spec.rb
|
83
|
+
- spec/tocco_studio_game/player_spec.rb
|
84
|
+
- spec/tocco_studio_game/movie_spec.rb
|
85
|
+
- spec/tocco_studio_game/game_spec.rb
|