tobimoku_studio_game 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2000514eb00146bba9c5a0ae87d5dab95fd9b069
4
+ data.tar.gz: f09d1b74d2f66024f050aa6a8bdd07875bd860c8
5
+ SHA512:
6
+ metadata.gz: 521ac8aeacc8e16d338db9e89c820624b766dd0d6307da60746091ac5f544f00080e3d3b3c40ba05384e534a5e384f0a0a1df9a8c54d837cf96f5b8526df28a0
7
+ data.tar.gz: 0193aad61fec954477f5d984da9beeab25d65281957c68429d85049810e5dc365ceb6c41e49d65fe511cd55a1e95842e72ba819da086076d957001a7a2773b7f
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright (C) <2014> <Tobimoku>
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.
8
+
data/README ADDED
@@ -0,0 +1,19 @@
1
+ This is the game I made following the exercises in the Pragmatic Studios Ruby Course.
2
+
3
+ Run studio_game to play a silly game.
4
+
5
+ You can add your own players to the game by creating a CSV file.
6
+ Each line of the file should contain the player's name and starting health like so :
7
+ Alvin,100
8
+ Simon,60
9
+ Theo,125
10
+
11
+ studio_game "YOUR_PLAYER_FILE_NAME.csv" without the quotes will load your players, otherwise the default "players.csv"" is used.
12
+
13
+ When you quit the game, the players scores are written in the high_scores.txt file.
14
+
15
+ Thanks to Mike and Nicole Clark at Pragmatic Studios for putting together such a great course.
16
+
17
+ All typos and bugs are mine
18
+
19
+ KP
data/bin/players.csv ADDED
@@ -0,0 +1,9 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
4
+ Huey,50
5
+ Dewey,100
6
+ Louey,75
7
+ Wiley,80
8
+ Fred,150
9
+ Barney,100
data/bin/studio_game ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/studio_game/player'
3
+ require_relative '../lib/studio_game/game'
4
+ require_relative '../lib/studio_game/clumsy_player'
5
+ require_relative '../lib/studio_game/berserker_player'
6
+
7
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
8
+
9
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
10
+ knuckleheads.load_players(ARGV.shift || default_player_file)
11
+
12
+ klutz = StudioGame::ClumsyPlayer.new("klutz",105)
13
+ bzerk = StudioGame::BerserkerPlayer.new("Bzerk",50)
14
+
15
+ knuckleheads.add_player(klutz)
16
+ knuckleheads.add_player(bzerk)
17
+
18
+
19
+ loop do
20
+ puts "\nHow many game rounds? ('quit' to exit)"
21
+ answer = gets.chomp.downcase
22
+ case answer
23
+ when /^\d+$/
24
+ knuckleheads.play(answer.to_i)
25
+ when 'quit', 'exit'
26
+ knuckleheads.print_stats
27
+ break
28
+ else
29
+ puts "Please enter a number or 'quit' "
30
+ end
31
+ end
32
+
33
+ knuckleheads.save_high_scores
34
+
35
+
36
+
@@ -0,0 +1,7 @@
1
+ module StudioGame
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{self.number} (#{self.class})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,35 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+
5
+ class BerserkerPlayer < Player
6
+
7
+ def initialize(name,health)
8
+ super(name,health)
9
+ @w00t_count = 0
10
+ end
11
+
12
+ def berserk?
13
+ @w00t_count > 5
14
+ end
15
+
16
+ def w00t
17
+ super
18
+ @w00t_count += 1
19
+ puts "#{@name} is beserk!" if berserk?
20
+ end
21
+
22
+ def blam
23
+ berserk? ? w00t : super
24
+ end
25
+ end
26
+
27
+
28
+ if __FILE__ == $0
29
+ berserker = BerserkerPlayer.new("berserker", 50)
30
+ 6.times { berserker.w00t }
31
+ 2.times { berserker.blam }
32
+ puts berserker.health
33
+ end
34
+
35
+ end
@@ -0,0 +1,41 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+ attr_reader :boost_factor
6
+
7
+ def initialize(name, health=100, boost_factor=1)
8
+ super(name,health)
9
+ @boost_factor = boost_factor
10
+ end
11
+
12
+ def w00t
13
+ @boost_factor.times { super }
14
+ end
15
+
16
+ def found_treasure(treasure)
17
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
18
+ super(damaged_treasure)
19
+ end
20
+
21
+
22
+ end
23
+
24
+
25
+ if __FILE__ == $0
26
+ clumsy = ClumsyPlayer.new("klutz")
27
+
28
+ hammer = Treasure.new(:hammer, 50)
29
+ clumsy.found_treasure(hammer)
30
+ clumsy.found_treasure(hammer)
31
+ clumsy.found_treasure(hammer)
32
+
33
+ crowbar = Treasure.new(:crowbar, 400)
34
+ clumsy.found_treasure(crowbar)
35
+
36
+ clumsy.each_found_treasure do |treasure|
37
+ puts "#{treasure.points} total #{treasure.name} points"
38
+ end
39
+ puts "#{clumsy.points} grand total points"
40
+ end
41
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'auditable.rb'
2
+
3
+ module StudioGame
4
+ class Die
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def initialize
10
+ roll
11
+ end
12
+
13
+ def roll
14
+ @number=rand(1..6)
15
+ audit
16
+ @number
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,107 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game_turn'
4
+ require_relative 'treasure_trove'
5
+ require 'csv'
6
+
7
+ module StudioGame
8
+
9
+ class Game
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 << 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 save_high_scores(to_file="high_scores.txt")
29
+ File.open(to_file, "w") do |file|
30
+ file.puts "#{@title} High Scores:"
31
+ @players.sort.each do |player|
32
+ file.puts high_score_entry(player)
33
+ end
34
+ end
35
+ end
36
+
37
+ def high_score_entry(player)
38
+ formatted_name = player.name.ljust(50,'.')
39
+ "#{formatted_name} #{player.score}"
40
+ end
41
+
42
+
43
+
44
+ def print_name_and_health(player)
45
+ puts "#{player.name.ljust(50,'.')} #{player.health}"
46
+ end
47
+
48
+ def print_stats
49
+ puts "\n #{@title} Statistics"
50
+
51
+ strong_players,wimpy_players=@players.partition {|strong| strong.strong?}
52
+
53
+ puts "\n#{strong_players.size} strong players:"
54
+ strong_players.each do |player|
55
+ print_name_and_health(player)
56
+ end
57
+
58
+ puts "\n#{wimpy_players.size} wimpy players:"
59
+ wimpy_players.each do |player|
60
+ print_name_and_health(player)
61
+ end
62
+
63
+ puts "\nPoints from Treasure by Player:"
64
+ @players.each do |player|
65
+ puts "\n#{player.name} point totals:"
66
+ player.each_found_treasure do |treasure|
67
+ puts "#{treasure.points} total #{treasure.name} points"
68
+ end
69
+ puts "#{player.points} grand total points"
70
+ end
71
+
72
+ puts "\nGrand Total Treasure Points:#{total_points}"
73
+ puts "\n#{@title} High Scores:"
74
+ @players.sort.each do |player|
75
+ puts high_score_entry(player)
76
+ end
77
+
78
+ end
79
+
80
+ def total_points
81
+ @players.each.reduce(0) do |sum,player|
82
+ sum + player.points
83
+ end
84
+ end
85
+
86
+ def play(rounds)
87
+ puts "There are #{@players.size} players in #{@title}"
88
+
89
+ @players.each do |player|
90
+ puts player
91
+ end
92
+
93
+ treasures = TreasureTrove::TREASURES
94
+ puts "\nThere are #{treasures.size} treasures to be found"
95
+ treasures.each do |treasure|
96
+ puts "A #{treasure.name} is worth #{treasure.points} points"
97
+ end
98
+
99
+ 1.upto(rounds) do |round|
100
+ puts "\nRound #{round}:"
101
+ @players.each do |player|
102
+ GameTurn.take_turn(player)
103
+ end
104
+ end
105
+ end
106
+ end
107
+ end
@@ -0,0 +1,22 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'treasure_trove'
4
+ module StudioGame
5
+ module GameTurn
6
+ def self.take_turn(player)
7
+ die = Die.new
8
+ case die.roll
9
+ when 1..2
10
+ player.blam
11
+ when 3..4
12
+ puts "#{player.name} was skipped."
13
+ else
14
+ player.w00t
15
+ end
16
+
17
+ treasure = TreasureTrove.random
18
+ player.found_treasure(treasure)
19
+
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,6 @@
1
+ Knuckleheads High Scores:
2
+ Theo.............................................. 540
3
+ Bzerk............................................. 465
4
+ Simon............................................. 150
5
+ Klutz............................................. 130.0
6
+ Alvin............................................. 95
@@ -0,0 +1,14 @@
1
+ require_relative 'auditable'
2
+
3
+ Module StudioGame
4
+ class LoadedDie
5
+ include Auditable
6
+ attr_reader :number
7
+ def roll
8
+ umbers = [1,1,2,5,6,6]
9
+ @number = numbers.sample
10
+ audit
11
+ @number
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+
2
+ module StudioGame
3
+
4
+ module Playable
5
+
6
+ def blam
7
+ self.health -= 10
8
+ puts "#{name} got blammed!"
9
+ end
10
+
11
+ def w00t
12
+ self.health += 15
13
+ puts "#{name} got w00ted!"
14
+ end
15
+
16
+ def strong?
17
+ self.health > 100
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,68 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Player
6
+ include Playable
7
+ attr_accessor :health
8
+ attr_accessor :name
9
+
10
+ def initialize(name,health=100)
11
+ @name = name.capitalize
12
+ @health = health
13
+ @found_treasures =Hash.new(0)
14
+ end
15
+
16
+ def self.from_csv(string)
17
+ name,health = string.split(',')
18
+ Player.new(name,Integer(health))
19
+
20
+ end
21
+
22
+ def each_found_treasure
23
+ @found_treasures.each do |name, points|
24
+ yield Treasure.new(name,points)
25
+ end
26
+ end
27
+
28
+
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 <=> (other)
37
+ other.score <=> score
38
+ end
39
+
40
+ def name=(new_name)
41
+ @name = new_name.capitalize
42
+ end
43
+
44
+ def points
45
+ @found_treasures.values.reduce(0,:+)
46
+ end
47
+
48
+ def score
49
+ @health + points
50
+ end
51
+
52
+ def to_s
53
+ "I'm #{@name} with a health = #{@health}, points = #{points}, and score = #{score}."
54
+ end
55
+
56
+ end
57
+
58
+ if __FILE__ == $0
59
+ player = Player.new("moe")
60
+ puts player.name
61
+ puts player.health
62
+ player.w00t
63
+ puts player.health
64
+ player.blam
65
+ puts player.health
66
+ end
67
+
68
+ end
@@ -0,0 +1,24 @@
1
+ module StudioGame
2
+
3
+ Treasure = Struct.new(:name, :points)
4
+
5
+
6
+ def self.random
7
+ TREASURES.sample
8
+ end
9
+
10
+ module TreasureTrove
11
+ TREASURES = [
12
+ Treasure.new(:pie, 5),
13
+ Treasure.new(:bottle, 25),
14
+ Treasure.new(:hammer, 50),
15
+ Treasure.new(:skillet, 100),
16
+ Treasure.new(:broomstick, 200),
17
+ Treasure.new(:crowbar, 400)
18
+ ]
19
+
20
+ def self.random
21
+ TREASURES.sample
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,36 @@
1
+ require 'studio_game/berserker_player'
2
+ module StudioGame
3
+ describe BerserkerPlayer do
4
+
5
+ before do
6
+ @initial_health = 50
7
+ @player = BerserkerPlayer.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_falsey
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_truthy
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,51 @@
1
+ require 'studio_game/clumsy_player'
2
+ module StudioGame
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
+ context "with boost factor" do
32
+ before do
33
+ @initial_health = 100
34
+ @boost_factor = 3
35
+ @player = ClumsyPlayer.new("booster",@initial_health,@boost_factor)
36
+ end
37
+
38
+ it "has boost factor" do
39
+ expect(@player.boost_factor).to eq(3)
40
+ end
41
+
42
+ it "gets wooted number of booster_factor times" do
43
+ @player.w00t
44
+
45
+ expect(@player.health).to eq(@initial_health + (@boost_factor * 15))
46
+ end
47
+ end
48
+
49
+
50
+ end
51
+ end
@@ -0,0 +1,66 @@
1
+ require'studio_game/game'
2
+ module StudioGame
3
+ describe Game do
4
+ before do
5
+ @game = Game.new("Knuckleheads")
6
+
7
+ @initial_health = 100
8
+ @player = Player.new("moe", @initial_health)
9
+
10
+ @game.add_player(@player)
11
+ end
12
+
13
+ it "woot if high number rolled " do
14
+
15
+
16
+ allow_any_instance_of(Die).to receive(:roll).and_return(5)
17
+ @game.play(2)
18
+
19
+ expect(@player.health).to eq(@initial_health + (15 * 2))
20
+ end
21
+
22
+ it "skip if a medium number is rolled" do
23
+ allow_any_instance_of(Die).to receive(:roll).and_return(3)
24
+
25
+ @game.play(2)
26
+
27
+ @player.health.should == @initial_health
28
+ end
29
+ it "blam if a low number is rolled" do
30
+ allow_any_instance_of(Die).to receive(:roll).and_return(1)
31
+
32
+ @game.play(2)
33
+
34
+ @player.health.should == @initial_health - (10 * 2)
35
+ end
36
+
37
+ it "assigns a treasure for points during a player's turn" do
38
+ game = Game.new("Knuckleheads")
39
+ player = Player.new("moe")
40
+
41
+ game.add_player(player)
42
+
43
+ game.play(1)
44
+
45
+ player.points.should_not be_zero
46
+
47
+ # or use alternate expectation syntax:
48
+ # expect(player.points).not_to be_zero
49
+ end
50
+ it "computes total points as the sum of all player points" do
51
+ game = Game.new("Knuckleheads")
52
+
53
+ player1 = Player.new("moe")
54
+ player2 = Player.new("larry")
55
+
56
+ game.add_player(player1)
57
+ game.add_player(player2)
58
+
59
+ player1.found_treasure(Treasure.new(:hammer, 50))
60
+ player1.found_treasure(Treasure.new(:hammer, 50))
61
+ player2.found_treasure(Treasure.new(:crowbar, 400))
62
+
63
+ game.total_points.should == 500
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,131 @@
1
+ require 'studio_game/spec_helper'
2
+ require 'studio_game/player'
3
+ require 'studio_game/treasure_trove'
4
+
5
+ module StudioGame
6
+ describe Player do
7
+ before do
8
+ @initial_health = 150
9
+ @player = Player.new("larry", @initial_health)
10
+ $stdout = StringIO.new
11
+ end
12
+
13
+ it "has a capitalized name" do
14
+ #rspec 3 style
15
+ expect(@player.name).to eq("Larry")
16
+ end
17
+
18
+ it "has an initial health" do
19
+ #rsec 3 style
20
+ expect(@player.health).to eq(150)
21
+ end
22
+
23
+ it "has a string representation" do
24
+ @player.found_treasure(Treasure.new(:hammer, 50))
25
+ @player.found_treasure(Treasure.new(:hammer, 50))
26
+
27
+ @player.to_s.should == "I'm Larry with a health = 150, points = 100, and score = 250."
28
+ end
29
+
30
+ it "computes a score as the sum of its health and points" do
31
+ @player.found_treasure(Treasure.new(:hammer, 50))
32
+ @player.found_treasure(Treasure.new(:hammer, 50))
33
+
34
+ @player.score.should == 250
35
+ end
36
+
37
+ it "increases health by 15 when w00ted" do
38
+ @player.w00t == 170
39
+ end
40
+
41
+ it "decreases health by 10 when blammed" do
42
+ @player.blam == 140
43
+ end
44
+
45
+
46
+
47
+ context "health greater than 100" do
48
+ before do
49
+ @player = Player.new("larry", 150)
50
+ end
51
+
52
+ it "is strong " do
53
+ @player.should be_strong
54
+ end
55
+ end
56
+
57
+ context "health less than 100" do
58
+ before do
59
+ @player = Player.new("larry", 90)
60
+ end
61
+
62
+ it "is wimpy " do
63
+ @player.should_not be_strong
64
+ end
65
+ end
66
+
67
+ context "in a collection of players" do
68
+ before do
69
+ @player1 = Player.new("moe", 100)
70
+ @player2 = Player.new("larry", 200)
71
+ @player3 = Player.new("curly", 300)
72
+
73
+ @players = [@player1, @player2, @player3]
74
+ end
75
+
76
+ it "is sorted by decreasing score" do
77
+ @players.sort.should == [@player3, @player2, @player1]
78
+ end
79
+ end
80
+ it "computes points as the sum of all treasure points" do
81
+ @player.points.should == 0
82
+
83
+ @player.found_treasure(Treasure.new(:hammer, 50))
84
+
85
+ @player.points.should == 50
86
+
87
+ @player.found_treasure(Treasure.new(:crowbar, 400))
88
+
89
+ @player.points.should == 450
90
+
91
+ @player.found_treasure(Treasure.new(:hammer, 50))
92
+
93
+ @player.points.should == 500
94
+ end
95
+
96
+ it "yields each found treasure and its total points" do
97
+ @player.found_treasure(Treasure.new(:skillet, 100))
98
+ @player.found_treasure(Treasure.new(:skillet, 100))
99
+ @player.found_treasure(Treasure.new(:hammer, 50))
100
+ @player.found_treasure(Treasure.new(:bottle, 5))
101
+ @player.found_treasure(Treasure.new(:bottle, 5))
102
+ @player.found_treasure(Treasure.new(:bottle, 5))
103
+ @player.found_treasure(Treasure.new(:bottle, 5))
104
+ @player.found_treasure(Treasure.new(:bottle, 5))
105
+
106
+ yielded = []
107
+ @player.each_found_treasure do |treasure|
108
+ yielded << treasure
109
+ end
110
+
111
+ yielded.should == [
112
+ Treasure.new(:skillet, 200),
113
+ Treasure.new(:hammer, 50),
114
+ Treasure.new(:bottle, 25)
115
+ ]
116
+ end
117
+
118
+ it "creates player from CSV string" do
119
+ player = Player.from_csv("Alvin, 111")
120
+
121
+ expect(player.name).to eq("Alvin")
122
+ expect(player.health).to eq(111)
123
+
124
+
125
+ end
126
+
127
+ end
128
+ end
129
+
130
+
131
+
@@ -0,0 +1,8 @@
1
+ RSpec.configure do |config|
2
+ config.expect_with :rspec do |c|
3
+ c.syntax = [:should, :expect]
4
+ end
5
+ config.mock_with :rspec do |c|
6
+ c.syntax = [:should, :expect]
7
+ end
8
+ end
@@ -0,0 +1,59 @@
1
+
2
+ require 'studio_game/treasure_trove'
3
+ module StudioGame
4
+ describe Treasure do
5
+
6
+ before do
7
+ @treasure = Treasure.new(:hammer, 50)
8
+ end
9
+
10
+ it "has a name attribute" do
11
+ @treasure.name.should == :hammer
12
+ end
13
+
14
+ it "has a points attribute" do
15
+ @treasure.points.should == 50
16
+ end
17
+
18
+ end
19
+
20
+ describe TreasureTrove do
21
+
22
+ it "has six treasures" do
23
+ TreasureTrove::TREASURES.size.should == 6
24
+ end
25
+
26
+ it "has a pie worth 5 points" do
27
+ TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
28
+ end
29
+
30
+ it "has a bottle worth 25 points" do
31
+ TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
32
+ end
33
+
34
+ it "has a hammer worth 50 points" do
35
+ TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
36
+ end
37
+
38
+ it "has a skillet worth 100 points" do
39
+ TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
40
+ end
41
+
42
+ it "has a broomstick worth 200 points" do
43
+ TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
44
+ end
45
+
46
+ it "has a crowbar worth 400 points" do
47
+ TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
48
+ end
49
+
50
+ it "returns a random treasure" do
51
+ treasure = TreasureTrove.random
52
+ TreasureTrove::TREASURES.should include(treasure)
53
+
54
+ # or use alternate expectation syntax:
55
+ # expect(TreasureTrove::TREASURES).to include(treasure)
56
+ end
57
+
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tobimoku_studio_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ken Payne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-31 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: "This is the game I made following the exercises in the Pragmatic Studios
28
+ Ruby Course. \n\nRun studio_game to play a silly game.\n\nYou can add your own players
29
+ to the game by creating a CSV file. \nEach line of the file should contain the player's
30
+ name and starting health like so :\nAlvin,100\nSimon,60\nTheo,125\n\nstudio_game
31
+ \"YOUR_PLAYER_FILE_NAME.csv\" without the quotes will load your players, otherwise
32
+ the default \"players.csv\"\" is used.\n\nWhen you quit the game, the players scores
33
+ are written in the high_scores.txt file.\n\nThanks to Mike and Nicole Clark at Pragmatic
34
+ Studios for putting together such a great course.\n\nAll typos and bugs are mine\n\nKP"
35
+ email: tobimoku@gmail.com
36
+ executables:
37
+ - studio_game
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - LICENSE
42
+ - README
43
+ - bin/players.csv
44
+ - bin/studio_game
45
+ - lib/studio_game/auditable.rb
46
+ - lib/studio_game/berserker_player.rb
47
+ - lib/studio_game/clumsy_player.rb
48
+ - lib/studio_game/die.rb
49
+ - lib/studio_game/game.rb
50
+ - lib/studio_game/game_turn.rb
51
+ - lib/studio_game/high_scores.txt
52
+ - lib/studio_game/loaded_die.rb
53
+ - lib/studio_game/playable.rb
54
+ - lib/studio_game/player.rb
55
+ - lib/studio_game/treasure_trove.rb
56
+ - spec/studio_game/berserker_player_spec.rb
57
+ - spec/studio_game/clumsy_player_spec.rb
58
+ - spec/studio_game/game_spec.rb
59
+ - spec/studio_game/player_spec.rb
60
+ - spec/studio_game/spec_helper.rb
61
+ - spec/studio_game/treasure_trove_spec.rb
62
+ homepage:
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '1.9'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.2.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Game made following the exercises for Pragmatic Studio Ruby Course
86
+ test_files:
87
+ - spec/studio_game/berserker_player_spec.rb
88
+ - spec/studio_game/clumsy_player_spec.rb
89
+ - spec/studio_game/game_spec.rb
90
+ - spec/studio_game/player_spec.rb
91
+ - spec/studio_game/spec_helper.rb
92
+ - spec/studio_game/treasure_trove_spec.rb
93
+ has_rdoc: