studio_fame_game 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +7 -0
- data/README +6 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +42 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +29 -0
- data/lib/studio_game/clumsy_player.rb +22 -0
- data/lib/studio_game/die.rb +20 -0
- data/lib/studio_game/game.rb +98 -0
- data/lib/studio_game/game_turn.rb +23 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +50 -0
- data/lib/studio_game/treasure_trove.rb +18 -0
- data/spec/studio_game/berserk_player_spec.rb +32 -0
- data/spec/studio_game/clumsy_player_spec.rb +33 -0
- data/spec/studio_game/game_spec.rb +72 -0
- data/spec/studio_game/player_spec.rb +136 -0
- data/spec/studio_game/treasure_trove_spec.rb +56 -0
- metadata +100 -0
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2013 Blair anderson
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
Description:
|
2
|
+
Studio_game is a practice application from the pragmatic studio ruby lessons. they walk you through the creation of creating a video game while teaching you the basics of learning ruby. It includes Numbers and Strings, Variables and Objects, Self, Methods, Classes, Attributes, Arrays, Objects Interacting, Separate Source Files, Unit Testing, Conditionals and TDD, Modules, Blocks, Symbols and Structs, Hashes, Custom Iterators, Input/Output, Inheritance, Mixins, and Distribution.
|
3
|
+
|
4
|
+
How To:
|
5
|
+
Gem Install StudioGame
|
6
|
+
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,42 @@
|
|
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
|
+
require_relative '../lib/studio_game/berserk_player'
|
7
|
+
|
8
|
+
module StudioGame
|
9
|
+
|
10
|
+
klutz = ClumsyPlayer.new("klutz", 105)
|
11
|
+
berserker = BerserkPlayer.new("berserk",50)
|
12
|
+
|
13
|
+
player1 = Player.new("moe")
|
14
|
+
player2 = Player.new("larry", 60)
|
15
|
+
player3 = Player.new("curly", 125)
|
16
|
+
|
17
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
18
|
+
knuckleheads.add_player(klutz)
|
19
|
+
knuckleheads.add_player(berserker)
|
20
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
21
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
22
|
+
|
23
|
+
# knuckleheads.add_player(player3)
|
24
|
+
# knuckleheads.add_player(player2)
|
25
|
+
# knuckleheads.add_player(player1)
|
26
|
+
|
27
|
+
loop do
|
28
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
29
|
+
answer = gets.chomp.downcase
|
30
|
+
case answer
|
31
|
+
when /^\d+$/
|
32
|
+
knuckleheads.play(answer.to_i)
|
33
|
+
when 'quit', 'exit'
|
34
|
+
knuckleheads.print_stats
|
35
|
+
break
|
36
|
+
else
|
37
|
+
puts "Please enter a number or 'quit'"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
knuckleheads.save_high_scores
|
42
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
module StudioGame
|
3
|
+
class BerserkPlayer < Player
|
4
|
+
|
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
|
+
if berserk?
|
22
|
+
w00t
|
23
|
+
else
|
24
|
+
super
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
|
6
|
+
def initialize(name, health=100)
|
7
|
+
super(name,health)
|
8
|
+
@boost_factor = 10
|
9
|
+
end
|
10
|
+
|
11
|
+
def found_treasure(treasure)
|
12
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points/2.0)
|
13
|
+
super(damaged_treasure)
|
14
|
+
end
|
15
|
+
|
16
|
+
def w00t
|
17
|
+
@health += @boost_factor
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'game_turn'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
class Game
|
7
|
+
|
8
|
+
attr_accessor :title
|
9
|
+
|
10
|
+
def initialize(title)
|
11
|
+
@title = title
|
12
|
+
@players = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_player(a_player)
|
16
|
+
@players.push(a_player)
|
17
|
+
end
|
18
|
+
|
19
|
+
def play(rounds)
|
20
|
+
puts "There are #{@players.size} players in #{@title}: "
|
21
|
+
|
22
|
+
@players.each do |player|
|
23
|
+
puts player
|
24
|
+
end
|
25
|
+
|
26
|
+
treasures = TreasureTrove::TREASURES
|
27
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
28
|
+
treasures.each do |treasure|
|
29
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
30
|
+
end
|
31
|
+
|
32
|
+
1.upto(rounds) do |round|
|
33
|
+
puts "\nRound #{round}:"
|
34
|
+
@players.each do |player|
|
35
|
+
GameTurn.take_turn(player)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def print_name_and_health(player)
|
41
|
+
puts "#{player.name} (#{player.health})"
|
42
|
+
end
|
43
|
+
|
44
|
+
def high_score_entry(player)
|
45
|
+
formatted_name = player.name.ljust(20, '.')
|
46
|
+
"#{formatted_name} #{player.score}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def total_points
|
50
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
51
|
+
end
|
52
|
+
|
53
|
+
def print_stats
|
54
|
+
puts "\n#{@title} Statistics:"
|
55
|
+
|
56
|
+
strong_players, wimpy_players = @players.partition { |player| player.strong? }
|
57
|
+
|
58
|
+
puts "\n#{strong_players.size} strong players:"
|
59
|
+
strong_players.each do |player|
|
60
|
+
print_name_and_health(player)
|
61
|
+
end
|
62
|
+
|
63
|
+
puts "\n#{wimpy_players.size} wimpy players:"
|
64
|
+
wimpy_players.each do |player|
|
65
|
+
print_name_and_health(player)
|
66
|
+
end
|
67
|
+
|
68
|
+
puts "\n#{total_points} total points from treasures found"
|
69
|
+
@players.each do |player|
|
70
|
+
puts "\n#{player.name}'s point totals:"
|
71
|
+
player.each_found_treasure do |treasure|
|
72
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
73
|
+
end
|
74
|
+
puts "#{player.points} grand total points"
|
75
|
+
end
|
76
|
+
|
77
|
+
puts "\n#{@title} High Scores:"
|
78
|
+
@players.sort.each do |player|
|
79
|
+
puts high_score_entry(player)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def load_players(from_file)
|
84
|
+
File.readlines(from_file).each do |line|
|
85
|
+
add_player(Player.from_csv(line))
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def save_high_scores(to_file="high_scores.txt")
|
90
|
+
File.open(to_file, "w") do |file|
|
91
|
+
file.puts "#{@title} High Scores:"
|
92
|
+
@players.sort.each do |player|
|
93
|
+
file.puts high_score_entry(player)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'loaded_die'
|
4
|
+
require_relative 'treasure_trove'
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
module GameTurn
|
8
|
+
def self.take_turn(player)
|
9
|
+
die = Die.new
|
10
|
+
case die.roll
|
11
|
+
when 1..2
|
12
|
+
player.blam
|
13
|
+
when 3..4
|
14
|
+
puts "#{player.name} was skipped."
|
15
|
+
else
|
16
|
+
player.w00t
|
17
|
+
end
|
18
|
+
|
19
|
+
treasure = TreasureTrove.random
|
20
|
+
player.found_treasure(treasure)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
include Playable
|
7
|
+
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :health
|
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 score
|
18
|
+
@health + points
|
19
|
+
end
|
20
|
+
|
21
|
+
def points
|
22
|
+
@found_treasures.values.reduce(0, :+)
|
23
|
+
end
|
24
|
+
|
25
|
+
def found_treasure(treasure)
|
26
|
+
@found_treasures[treasure.name] += treasure.points
|
27
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
28
|
+
end
|
29
|
+
|
30
|
+
def each_found_treasure
|
31
|
+
@found_treasures.each do |name, points|
|
32
|
+
next_treasure = Treasure.new(name, points)
|
33
|
+
yield next_treasure
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def <=>(other)
|
38
|
+
other.score <=> score
|
39
|
+
end
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.from_csv(string)
|
46
|
+
name, health = string.split(',')
|
47
|
+
new(name, Integer(health))
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module StudioGame
|
2
|
+
Treasure = Struct.new(:name, :points)
|
3
|
+
|
4
|
+
module TreasureTrove
|
5
|
+
TREASURES = [
|
6
|
+
Treasure.new(:pie, 5),
|
7
|
+
Treasure.new(:bottle, 25),
|
8
|
+
Treasure.new(:hammer, 50),
|
9
|
+
Treasure.new(:skillet, 100),
|
10
|
+
Treasure.new(:broomstick, 200),
|
11
|
+
Treasure.new(:crowbar, 400)
|
12
|
+
]
|
13
|
+
|
14
|
+
def self.random
|
15
|
+
TREASURES.sample
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe BerserkPlayer do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@initial_health = 50
|
9
|
+
@player = BerserkPlayer.new("berserker", @initial_health)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "does not go berserk when w00ted up to 5 times" do
|
13
|
+
1.upto(5) { @player.w00t }
|
14
|
+
|
15
|
+
@player.berserk?.should be_false
|
16
|
+
end
|
17
|
+
|
18
|
+
it "goes berserk when w00ted more than 5 times" do
|
19
|
+
1.upto(6) { @player.w00t }
|
20
|
+
|
21
|
+
@player.berserk?.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
25
|
+
1.upto(6) { @player.w00t }
|
26
|
+
1.upto(2) { @player.blam }
|
27
|
+
|
28
|
+
@player.health.should == @initial_health + (8 * 15)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe Game do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@game = Game.new("Knuckleheads")
|
9
|
+
|
10
|
+
@initial_health = 100
|
11
|
+
@player = Player.new("moe", @initial_health)
|
12
|
+
|
13
|
+
@game.add_player(@player)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has a title" do
|
17
|
+
@game.title.should == "Knuckleheads"
|
18
|
+
end
|
19
|
+
|
20
|
+
it "w00ts the player if a high number is rolled" do
|
21
|
+
Die.any_instance.stub(:roll).and_return(5)
|
22
|
+
|
23
|
+
@game.play(2)
|
24
|
+
|
25
|
+
@player.health.should == @initial_health + (15 * 2)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "skips the player if a medium number is rolled" do
|
29
|
+
Die.any_instance.stub(:roll).and_return(3)
|
30
|
+
|
31
|
+
@game.play(2)
|
32
|
+
|
33
|
+
@player.health.should == @initial_health
|
34
|
+
end
|
35
|
+
|
36
|
+
it "blams the player if a low number is rolled" do
|
37
|
+
Die.any_instance.stub(:roll).and_return(1)
|
38
|
+
|
39
|
+
@game.play(2)
|
40
|
+
|
41
|
+
@player.health.should == @initial_health - (10 * 2)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "assigns a treasure for points during a player's turn" do
|
45
|
+
game = Game.new("Knuckleheads")
|
46
|
+
player = Player.new("moe")
|
47
|
+
|
48
|
+
game.add_player(player)
|
49
|
+
|
50
|
+
game.play(1)
|
51
|
+
|
52
|
+
player.points.should_not be_zero
|
53
|
+
end
|
54
|
+
|
55
|
+
it "computes total points as the sum of all player points" do
|
56
|
+
game = Game.new("Knuckleheads")
|
57
|
+
|
58
|
+
player1 = Player.new("moe")
|
59
|
+
player2 = Player.new("larry")
|
60
|
+
|
61
|
+
game.add_player(player1)
|
62
|
+
game.add_player(player2)
|
63
|
+
|
64
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
65
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
66
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
67
|
+
|
68
|
+
game.total_points.should == 500
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
|
5
|
+
describe Player do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@initial_health = 150
|
9
|
+
@player = Player.new("larry", @initial_health)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "has a capitalized name" do
|
13
|
+
@player.name.should == "Larry"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "has an initial health" do
|
17
|
+
@player.health.should == 150
|
18
|
+
end
|
19
|
+
|
20
|
+
it "has a string representation" do
|
21
|
+
@player.found_treasure(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 "increases health by 15 when w00ted" do
|
28
|
+
@player.w00t
|
29
|
+
|
30
|
+
@player.health.should == @initial_health + 15
|
31
|
+
end
|
32
|
+
|
33
|
+
it "decreases health by 10 when blammed" do
|
34
|
+
@player.blam
|
35
|
+
|
36
|
+
@player.health.should == @initial_health - 10
|
37
|
+
end
|
38
|
+
|
39
|
+
context "created with a default health" do
|
40
|
+
before do
|
41
|
+
@player = Player.new("larry")
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has a health of 100" do
|
45
|
+
@player.health.should == 100
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "with a health greater than 100" do
|
50
|
+
before do
|
51
|
+
@player = Player.new("larry", 150)
|
52
|
+
end
|
53
|
+
|
54
|
+
it "is strong" do
|
55
|
+
@player.should be_strong
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context "with a health of 100 or less" do
|
60
|
+
before do
|
61
|
+
@player = Player.new("larry", 100)
|
62
|
+
end
|
63
|
+
|
64
|
+
it "is wimpy" do
|
65
|
+
@player.should_not be_strong
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context "in a collection of players" do
|
70
|
+
before do
|
71
|
+
@player1 = Player.new("moe", 100)
|
72
|
+
@player2 = Player.new("larry", 200)
|
73
|
+
@player3 = Player.new("curly", 300)
|
74
|
+
|
75
|
+
@players = [@player1, @player2, @player3]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "is sorted by decreasing score" do
|
79
|
+
@players.sort.should == [@player3, @player2, @player1]
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
it "computes a score as the sum of its health and points" do
|
84
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
85
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
86
|
+
|
87
|
+
@player.score.should == 250
|
88
|
+
end
|
89
|
+
|
90
|
+
it "computes points as the sum of all treasure points" do
|
91
|
+
@player.points.should == 0
|
92
|
+
|
93
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
94
|
+
|
95
|
+
@player.points.should == 50
|
96
|
+
|
97
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
98
|
+
|
99
|
+
@player.points.should == 450
|
100
|
+
|
101
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
102
|
+
|
103
|
+
@player.points.should == 500
|
104
|
+
end
|
105
|
+
|
106
|
+
it "yields each found treasure and its total points" do
|
107
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
108
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
109
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
110
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
111
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
112
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
113
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
114
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
115
|
+
|
116
|
+
yielded = []
|
117
|
+
@player.each_found_treasure do |treasure|
|
118
|
+
yielded << treasure
|
119
|
+
end
|
120
|
+
|
121
|
+
yielded.should == [
|
122
|
+
Treasure.new(:skillet, 200),
|
123
|
+
Treasure.new(:hammer, 50),
|
124
|
+
Treasure.new(:bottle, 25)
|
125
|
+
]
|
126
|
+
end
|
127
|
+
|
128
|
+
it "can be created from a CSV string" do
|
129
|
+
player = Player.from_csv("larry,150")
|
130
|
+
|
131
|
+
player.name.should == "Larry"
|
132
|
+
player.health.should == 150
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'studio_game/treasure_trove'
|
2
|
+
module StudioGame
|
3
|
+
|
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,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio_fame_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Blair Anderson
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-28 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: ! 'Description:
|
31
|
+
|
32
|
+
Studio_game is a practice application from the pragmatic studio ruby lessons. they
|
33
|
+
walk you through the creation of creating a video game while teaching you the basics
|
34
|
+
of learning ruby. It includes Numbers and Strings, Variables and Objects, Self,
|
35
|
+
Methods, Classes, Attributes, Arrays, Objects Interacting, Separate Source Files,
|
36
|
+
Unit Testing, Conditionals and TDD, Modules, Blocks, Symbols and Structs, Hashes,
|
37
|
+
Custom Iterators, Input/Output, Inheritance, Mixins, and Distribution.
|
38
|
+
|
39
|
+
|
40
|
+
How To:
|
41
|
+
|
42
|
+
Gem Install StudioGame
|
43
|
+
|
44
|
+
|
45
|
+
'
|
46
|
+
email: blair81@gmail.com
|
47
|
+
executables:
|
48
|
+
- studio_game
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- bin/players.csv
|
53
|
+
- bin/studio_game
|
54
|
+
- lib/studio_game/auditable.rb
|
55
|
+
- lib/studio_game/berserk_player.rb
|
56
|
+
- lib/studio_game/clumsy_player.rb
|
57
|
+
- lib/studio_game/die.rb
|
58
|
+
- lib/studio_game/game.rb
|
59
|
+
- lib/studio_game/game_turn.rb
|
60
|
+
- lib/studio_game/loaded_die.rb
|
61
|
+
- lib/studio_game/playable.rb
|
62
|
+
- lib/studio_game/player.rb
|
63
|
+
- lib/studio_game/treasure_trove.rb
|
64
|
+
- spec/studio_game/berserk_player_spec.rb
|
65
|
+
- spec/studio_game/clumsy_player_spec.rb
|
66
|
+
- spec/studio_game/game_spec.rb
|
67
|
+
- spec/studio_game/player_spec.rb
|
68
|
+
- spec/studio_game/treasure_trove_spec.rb
|
69
|
+
- LICENSE
|
70
|
+
- README
|
71
|
+
homepage: http://www.blairbuilds.com
|
72
|
+
licenses: []
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.9'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ! '>='
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
requirements: []
|
90
|
+
rubyforge_project:
|
91
|
+
rubygems_version: 1.8.24
|
92
|
+
signing_key:
|
93
|
+
specification_version: 3
|
94
|
+
summary: A silly game against a klutz and berserker
|
95
|
+
test_files:
|
96
|
+
- spec/studio_game/berserk_player_spec.rb
|
97
|
+
- spec/studio_game/clumsy_player_spec.rb
|
98
|
+
- spec/studio_game/game_spec.rb
|
99
|
+
- spec/studio_game/player_spec.rb
|
100
|
+
- spec/studio_game/treasure_trove_spec.rb
|