studio_game_jb 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: 84fe51e9cdedc9f906cd585b84e0c27e93eadfcb
4
+ data.tar.gz: 34c23f8dec802b1badcd774b1690872b6a61015e
5
+ SHA512:
6
+ metadata.gz: dfb62e941f7bc24b5d3d0469b9e352036d3838b722145753fd64060e1cf7c0daf19bbb9be7f4ab528bd8dc573367051151b51fc22735fc810a1e9fe0c701f5da
7
+ data.tar.gz: 8bed8fddc6c1efb856ed980337c972fc8659621978a2a6bb8b5f49400298b86925dc6233a32f6a33d48ba864b0716ef45f8af365b65b99e38b3beab9ed073a4d
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+
2
+ Copyright (C) 2013 Jorge Alberto Borges Colina
3
+
4
+ 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:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ 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.md ADDED
@@ -0,0 +1,34 @@
1
+ # studio_game_jb
2
+
3
+ A simple CLI game made for the Pragmatic Studio Ruby course.
4
+
5
+ Install & Usage
6
+ --------
7
+
8
+ ```shell
9
+ gem install studio_game_jb
10
+ ```
11
+
12
+ Then, to run a game:
13
+
14
+ ```shell
15
+ studio_game_jb
16
+ ```
17
+
18
+ And input the number of rounds to play.
19
+
20
+ You may also load you own players by creating a CSV file (name, health) and passing it as a parameter:
21
+
22
+ ```shell
23
+ studio_game_jb my_players.csv
24
+ ```
25
+
26
+ More Information
27
+ ----------------
28
+
29
+ * [Pragmatic Studio Ruby Course](http://pragmaticstudio.com/ruby)
30
+
31
+ License
32
+ -------
33
+
34
+ studio_game_jb is Copyright © 2013 Jorge A. Borges Colina. It is free software, and may be redistributed under the terms specified in the [LICENSE](https://github.com/jorgeborges/studio_game_jb/blob/master/LICENSE) file.
data/bin/players.csv ADDED
@@ -0,0 +1,3 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/studio_game_jb/game'
3
+
4
+ knuckleheads = StudioGameJB::Game.new("Knuckleheads")
5
+ default_player_file = File.join(File.dirname(__FILE__), "players.csv")
6
+ knuckleheads.load_players ARGV.shift || default_player_file
7
+
8
+ klutz = StudioGameJB::ClumsyPlayer.new "ale", 105
9
+ knuckleheads.add_player klutz
10
+
11
+ berserker = StudioGameJB::BerserkPlayer.new("berserker", 50)
12
+ knuckleheads.add_player(berserker)
13
+
14
+ loop do
15
+ puts "\nHow many game rounds? ('quit' to exit)"
16
+ answer = gets.chomp.downcase
17
+ case answer
18
+ when /^\d+$/
19
+ knuckleheads.play answer.to_i do
20
+ knuckleheads.total_points >= 1000000
21
+ end
22
+ when 'quit', 'exit'
23
+ knuckleheads.print_stats
24
+ break
25
+ else
26
+ puts "\nPlease enter a number or 'quit'"
27
+ end
28
+ end
29
+
30
+ knuckleheads.save_high_scores
@@ -0,0 +1,7 @@
1
+ module StudioGameJB
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{number} (#{self.class})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGameJB
4
+ class BerserkPlayer < Player
5
+ def initialize(name, health = 100)
6
+ super name, health
7
+ @w00t_count = 0
8
+ end
9
+
10
+ def berserk?
11
+ @w00t_count > 5
12
+ end
13
+
14
+ def w00t
15
+ super
16
+ @w00t_count += 1
17
+ puts "Berserker is berserk!" if berserk?
18
+ end
19
+
20
+ def blam
21
+ berserk? ? w00t : super
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,20 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGameJB
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
+ super Treasure.new treasure.name, treasure.points / 2
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGameJB
4
+ class Dice
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,108 @@
1
+ require 'csv'
2
+
3
+ require_relative 'game_turn'
4
+ require_relative 'player'
5
+ require_relative 'clumsy_player'
6
+ require_relative 'berserk_player'
7
+ require_relative 'treasure_trove'
8
+
9
+ module StudioGameJB
10
+ class Game
11
+ attr_reader :title
12
+
13
+ def initialize(title)
14
+ @title = title
15
+ @players = []
16
+ end
17
+
18
+ def add_player(player)
19
+ @players << player
20
+ end
21
+
22
+ def load_players(from_file)
23
+ CSV.foreach(from_file) do |row|
24
+ player = Player.new(row[0], Integer(row[1]))
25
+ add_player player
26
+ end
27
+ end
28
+
29
+ def save_high_scores(to_file="high_scores.txt")
30
+ File.open(to_file, "w") do |file|
31
+ file.puts "#{@title} High Scores:"
32
+ @players.sort.each do |player|
33
+ file.puts high_score_entry(player)
34
+ end
35
+ end
36
+ end
37
+
38
+ def high_score_entry(player)
39
+ formatted_name = player.name.ljust(20, '.')
40
+ "#{formatted_name} #{player.score}"
41
+ end
42
+
43
+ def number_of_players
44
+ @players.size
45
+ end
46
+
47
+ def calculate_stats
48
+ @players.partition {|player| player.strong?}
49
+ end
50
+
51
+ def total_points
52
+ @players.reduce(0) {|sum, player| sum += player.points}
53
+ end
54
+
55
+ def play(rounds)
56
+ puts "There are #{@players.size} players in #{@title}.\n"
57
+
58
+ @players.each do |player|
59
+ puts player
60
+ end
61
+
62
+ treasures = TreasureTrove::TREASURES
63
+
64
+ puts "\nThere are #{treasures.size} treasures to be found:"
65
+ treasures.each do |treasure|
66
+ puts "A #{treasure.name} is worth #{treasure.points} points"
67
+ end
68
+
69
+ 1.upto rounds do |round|
70
+ break if block_given? and yield
71
+ puts "\nRound #{round}:"
72
+ @players.each do |player|
73
+ GameTurn.take_turn player
74
+ puts player
75
+ end
76
+ end
77
+ end
78
+
79
+ def print_stats
80
+ strong_players, wimpy_players = calculate_stats
81
+ puts "\n#{@title} Statistics:"
82
+
83
+ puts "\n#{strong_players.size} strong players:"
84
+ strong_players.each do |player|
85
+ puts player.print_name_and_health
86
+ end
87
+
88
+ puts "\n#{wimpy_players.size} wimpy players:"
89
+ wimpy_players.each do |player|
90
+ puts player.print_name_and_health
91
+ end
92
+
93
+ @players.each do |player|
94
+ puts "\n#{player.name}'s point totals:"
95
+ player.each_found_treasure do |treasure|
96
+ puts "#{treasure.points} total #{treasure.name} points"
97
+ end
98
+ puts "#{player.points} grand total points"
99
+ end
100
+ puts "\n#{total_points} total points from treasures found"
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,23 @@
1
+ require_relative 'dice'
2
+ require_relative 'loaded_dice'
3
+ require_relative 'player'
4
+ require_relative 'treasure_trove'
5
+
6
+ module StudioGameJB
7
+ module GameTurn
8
+ def self.take_turn(player)
9
+ dice = Dice.new
10
+
11
+ case dice.roll
12
+ when 1..2
13
+ player.blam
14
+ when 3..4
15
+ puts "#{player.name} was skipped."
16
+ else
17
+ player.w00t
18
+ end
19
+
20
+ player.found_treasure TreasureTrove.random
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGameJB
4
+ class LoadedDice
5
+ include Auditable
6
+
7
+ attr_reader :number
8
+
9
+ def roll
10
+ numbers = [1, 1, 2, 5, 6, 6]
11
+ @number = numbers.sample
12
+ audit
13
+ @number
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,17 @@
1
+ module StudioGameJB
2
+ module Playable
3
+ def w00t
4
+ self.health += 15
5
+ puts "#{self.name} got w00ted!"
6
+ end
7
+
8
+ def blam
9
+ self.health -= 10
10
+ puts "#{self.name} got blammed!"
11
+ end
12
+
13
+ def strong?
14
+ health > 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'playable'
2
+ require_relative 'treasure_trove'
3
+
4
+ module StudioGameJB
5
+ class Player
6
+ include Playable
7
+
8
+ attr_reader :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 <=>(other_player)
18
+ other_player.score <=> score
19
+ end
20
+
21
+ def name=(new_name)
22
+ @name = new_name.capitalize
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
+ puts "#{@name}'s treasures: #{@found_treasures}"
29
+ end
30
+
31
+ def points
32
+ @found_treasures.values.reduce 0, :+
33
+ end
34
+
35
+ def score
36
+ @health + points
37
+ end
38
+
39
+ def each_found_treasure
40
+ @found_treasures.each do |name, points|
41
+ yield Treasure.new(name, points)
42
+ end
43
+ end
44
+
45
+ def to_s
46
+ "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
47
+ end
48
+
49
+ def print_name_and_health
50
+ "#{@name} (#{@health})"
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,18 @@
1
+ module StudioGameJB
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_jb/berserk_player'
2
+
3
+ module StudioGameJB
4
+ describe BerserkPlayer do
5
+
6
+ before do
7
+ $stdout = StringIO.new
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,51 @@
1
+ require 'studio_game_jb/clumsy_player'
2
+
3
+ module StudioGameJB
4
+ describe ClumsyPlayer do
5
+ before do
6
+ $stdout = StringIO.new
7
+ @player = ClumsyPlayer.new("klutz")
8
+ end
9
+
10
+ it "only gets half the point value for each treasure" do
11
+ @player.points.should == 0
12
+
13
+ hammer = Treasure.new(:hammer, 50)
14
+ @player.found_treasure(hammer)
15
+ @player.found_treasure(hammer)
16
+ @player.found_treasure(hammer)
17
+
18
+ @player.points.should == 75
19
+
20
+ crowbar = Treasure.new(:crowbar, 400)
21
+ @player.found_treasure(crowbar)
22
+
23
+ @player.points.should == 275
24
+
25
+ yielded = []
26
+ @player.each_found_treasure do |treasure|
27
+ yielded << treasure
28
+ end
29
+
30
+ yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
31
+ end
32
+
33
+ context "with a boost factor" do
34
+ before do
35
+ @initial_health = 100
36
+ @boost_factor = 5
37
+ @player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
38
+ end
39
+
40
+ it "has a boost factor" do
41
+ @player.boost_factor.should == 5
42
+ end
43
+
44
+ it "gets boost factor number of w00ts when w00ted" do
45
+ @player.w00t
46
+
47
+ @player.health.should == @initial_health + (15 * @boost_factor)
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,16 @@
1
+ require 'studio_game_jb/dice'
2
+
3
+ module StudioGameJB
4
+ describe Dice do
5
+ it "should have a number between 1 and 6 assigned after creation" do
6
+ dice = Dice.new
7
+
8
+ dice.number.should be_between 1, 6
9
+ end
10
+ it "a roll should return a number between 1 and 6" do
11
+ dice = Dice.new
12
+
13
+ dice.roll.should be_between 1, 6
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,79 @@
1
+ require 'studio_game_jb/game'
2
+
3
+ module StudioGameJB
4
+ describe Game do
5
+ before do
6
+ $stdout = StringIO.new
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 "returns the number of players" do
16
+ @game.number_of_players.should == 1
17
+ end
18
+
19
+ it "adds a player to the game" do
20
+ @game.add_player Player.new "chester"
21
+ @game.number_of_players.should == 2
22
+ end
23
+
24
+ it "calculates the stats for all the players" do
25
+ player2 = Player.new "larry", 95
26
+ player3 = Player.new "chester", 80
27
+
28
+ @game.add_player player2
29
+ @game.add_player player3
30
+
31
+ Dice.any_instance.stub(:roll).and_return 5
32
+
33
+ @game.play 1
34
+
35
+ strong_players, winpy_players = @game.calculate_stats
36
+
37
+ strong_players.should have(2).items
38
+ winpy_players.should have(1).items
39
+ end
40
+
41
+ it "computes total points as the sum of all player points" do
42
+ game = Game.new("Knuckleheads")
43
+
44
+ player1 = Player.new("moe")
45
+ player2 = Player.new("larry")
46
+
47
+ game.add_player(player1)
48
+ game.add_player(player2)
49
+
50
+ player1.found_treasure(Treasure.new(:hammer, 50))
51
+ player1.found_treasure(Treasure.new(:hammer, 50))
52
+ player2.found_treasure(Treasure.new(:crowbar, 400))
53
+
54
+ game.total_points.should == 500
55
+ end
56
+
57
+ it "plays for the number of specified rounds when no conditional block is passed" do
58
+ Dice.any_instance.stub(:roll).and_return 3
59
+ @game.play 10
60
+ @player.health.should == @initial_health
61
+ end
62
+
63
+ it "plays until the conditional block is true and a winning criteria is met" do
64
+ Dice.any_instance.stub(:roll).and_return 5
65
+ TreasureTrove.stub(:random).and_return Treasure.new(:pie, 5)
66
+ @game.play 10 do
67
+ @game.total_points >= 10
68
+ end
69
+ @game.total_points.should == 10
70
+ @player.health.should == @initial_health + 30
71
+ end
72
+
73
+ it "loads players correctly from a CSV file" do
74
+ players_file = File.join(File.dirname(__FILE__), '../support/players.csv')
75
+ @game.load_players players_file
76
+ @game.number_of_players.should == 4
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,61 @@
1
+ require 'studio_game_jb/game_turn'
2
+
3
+ module StudioGameJB
4
+ describe GameTurn do
5
+ include GameTurn
6
+
7
+ before do
8
+ $stdout = StringIO.new
9
+ @initial_health = 120
10
+ @player = Player.new "larry", @initial_health
11
+ end
12
+
13
+ it "w00ts the player if a high number (5 or 6) is rolled" do
14
+ Dice.any_instance.stub(:roll).and_return 5
15
+
16
+ GameTurn.take_turn(@player)
17
+
18
+ @player.health.should == @initial_health + 15
19
+
20
+ Dice.any_instance.stub(:roll).and_return 6
21
+
22
+ GameTurn.take_turn(@player)
23
+
24
+ @player.health.should == @initial_health + 15 * 2
25
+ end
26
+
27
+ it "skips the player if a medium number (3 or 4) is rolled" do
28
+ Dice.any_instance.stub(:roll).and_return 3
29
+
30
+ GameTurn.take_turn(@player)
31
+
32
+ @player.health.should == @initial_health
33
+
34
+ Dice.any_instance.stub(:roll).and_return 4
35
+
36
+ GameTurn.take_turn(@player)
37
+
38
+ @player.health.should == @initial_health
39
+ end
40
+
41
+ it "blams the player if a low number (1 or 2) is rolled" do
42
+ Dice.any_instance.stub(:roll).and_return 1
43
+
44
+ GameTurn.take_turn(@player)
45
+
46
+ @player.health.should == @initial_health - 10
47
+
48
+ Dice.any_instance.stub(:roll).and_return 2
49
+
50
+ GameTurn.take_turn(@player)
51
+
52
+ @player.health.should == @initial_health - 10 * 2
53
+ end
54
+
55
+ it "assigns a treasure for points during a player's turn" do
56
+ GameTurn.take_turn(@player)
57
+
58
+ @player.points.should_not be_zero
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,117 @@
1
+ require 'studio_game_jb/player'
2
+
3
+ module StudioGameJB
4
+ describe Player do
5
+ before do
6
+ $stdout = StringIO.new
7
+ @initial_health = 150
8
+ @player = Player.new("larry", @initial_health)
9
+ end
10
+
11
+ it "has a capitalized name" do
12
+ @player.name.should == "Larry"
13
+ end
14
+
15
+ it "has an initial health" do
16
+ @player.health.should == 150
17
+ end
18
+
19
+ it "has a string representation" do
20
+ @player.found_treasure(Treasure.new(:hammer, 50))
21
+ @player.found_treasure(Treasure.new(:hammer, 50))
22
+ @player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
23
+ end
24
+
25
+ it "prints its name and health with format" do
26
+ @player.print_name_and_health.should == "#{@player.name} (#{@player.health})"
27
+ end
28
+
29
+ it "computes a score as the sum of its health and points" do
30
+ @player.found_treasure(Treasure.new(:hammer, 50))
31
+ @player.found_treasure(Treasure.new(:hammer, 50))
32
+ @player.score.should == @initial_health + 100
33
+ end
34
+
35
+ it "increases health by 15 when w00ted" do
36
+ @player.w00t
37
+ @player.health.should == @initial_health + 15
38
+ end
39
+
40
+ it "decreases health by 10 when blammed" do
41
+ @player.blam
42
+ @player.health.should == @initial_health - 10
43
+ end
44
+
45
+ it "yields each found treasure and its total points" do
46
+ @player.found_treasure(Treasure.new(:skillet, 100))
47
+ @player.found_treasure(Treasure.new(:skillet, 100))
48
+ @player.found_treasure(Treasure.new(:hammer, 50))
49
+ @player.found_treasure(Treasure.new(:bottle, 5))
50
+ @player.found_treasure(Treasure.new(:bottle, 5))
51
+ @player.found_treasure(Treasure.new(:bottle, 5))
52
+ @player.found_treasure(Treasure.new(:bottle, 5))
53
+ @player.found_treasure(Treasure.new(:bottle, 5))
54
+
55
+ yielded = []
56
+ @player.each_found_treasure do |treasure|
57
+ yielded << treasure
58
+ end
59
+
60
+ yielded.should == [
61
+ Treasure.new(:skillet, 200),
62
+ Treasure.new(:hammer, 50),
63
+ Treasure.new(:bottle, 25)
64
+ ]
65
+ end
66
+
67
+ it "computes points as the sum of all treasure points" do
68
+ @player.points.should == 0
69
+
70
+ @player.found_treasure(Treasure.new(:hammer, 50))
71
+
72
+ @player.points.should == 50
73
+
74
+ @player.found_treasure(Treasure.new(:crowbar, 400))
75
+
76
+ @player.points.should == 450
77
+
78
+ @player.found_treasure(Treasure.new(:hammer, 50))
79
+
80
+ @player.points.should == 500
81
+ end
82
+
83
+ context "with a health greater than 100" do
84
+ before do
85
+ @player = Player.new "larry", 150
86
+ end
87
+
88
+ it "is strong" do
89
+ @player.should be_strong
90
+ end
91
+ end
92
+
93
+ context "with a health of 100" do
94
+ before do
95
+ @player = Player.new "larry", 100
96
+ end
97
+
98
+ it "is not strong" do
99
+ @player.should_not be_strong
100
+ end
101
+ end
102
+
103
+ context "in a collection of players" do
104
+ before do
105
+ @player1 = Player.new("moe", 100)
106
+ @player2 = Player.new("larry", 200)
107
+ @player3 = Player.new("curly", 300)
108
+
109
+ @players = [@player1, @player2, @player3]
110
+ end
111
+
112
+ it "is sorted by decreasing score" do
113
+ @players.sort.should == [@player3, @player2, @player1]
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,53 @@
1
+ require 'studio_game_jb/treasure_trove'
2
+
3
+ module StudioGameJB
4
+ describe Treasure do
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
+ end
17
+
18
+ describe TreasureTrove do
19
+ it "has six treasures" do
20
+ TreasureTrove::TREASURES.size.should == 6
21
+ end
22
+
23
+ it "has a pie worth 5 points" do
24
+ TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
25
+ end
26
+
27
+ it "has a bottle worth 25 points" do
28
+ TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
29
+ end
30
+
31
+ it "has a hammer worth 50 points" do
32
+ TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
33
+ end
34
+
35
+ it "has a skillet worth 100 points" do
36
+ TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
37
+ end
38
+
39
+ it "has a broomstick worth 200 points" do
40
+ TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
41
+ end
42
+
43
+ it "has a crowbar worth 400 points" do
44
+ TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
45
+ end
46
+
47
+ it "returns a random treasure" do
48
+ treasure = TreasureTrove.random
49
+
50
+ TreasureTrove::TREASURES.should include(treasure)
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_jb
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jorge Alberto Borges Colina
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rspec
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ description: |
28
+ # studio_game_jb
29
+
30
+ A simple CLI game made for the Pragmatic Studio Ruby course.
31
+
32
+ Install & Usage
33
+ --------
34
+
35
+ ```shell
36
+ gem install studio_game_jb
37
+ ```
38
+
39
+ Then, to run a game:
40
+
41
+ ```shell
42
+ studio_game_jb
43
+ ```
44
+
45
+ And input the number of rounds to play.
46
+
47
+ You may also load you own players by creating a CSV file (name, health) and passing it as a parameter:
48
+
49
+ ```shell
50
+ studio_game_jb my_players.csv
51
+ ```
52
+
53
+ More Information
54
+ ----------------
55
+
56
+ * [Pragmatic Studio Ruby Course](http://pragmaticstudio.com/ruby)
57
+
58
+ License
59
+ -------
60
+
61
+ studio_game_jb is Copyright © 2013 Jorge A. Borges Colina. It is free software, and may be redistributed under the terms specified in the [LICENSE](https://github.com/jorgeborges/studio_game_jb/blob/master/LICENSE) file.
62
+ email: jborges82@gmail.com
63
+ executables:
64
+ - studio_game_jb
65
+ extensions: []
66
+ extra_rdoc_files: []
67
+ files:
68
+ - bin/studio_game_jb
69
+ - bin/players.csv
70
+ - lib/studio_game_jb/berserk_player.rb
71
+ - lib/studio_game_jb/game_turn.rb
72
+ - lib/studio_game_jb/dice.rb
73
+ - lib/studio_game_jb/game.rb
74
+ - lib/studio_game_jb/treasure_trove.rb
75
+ - lib/studio_game_jb/player.rb
76
+ - lib/studio_game_jb/clumsy_player.rb
77
+ - lib/studio_game_jb/loaded_dice.rb
78
+ - lib/studio_game_jb/auditable.rb
79
+ - lib/studio_game_jb/playable.rb
80
+ - spec/support/players.csv
81
+ - spec/studio_game_jb/berserk_player_spec.rb
82
+ - spec/studio_game_jb/treasure_trove_spec.rb
83
+ - spec/studio_game_jb/game_spec.rb
84
+ - spec/studio_game_jb/player_spec.rb
85
+ - spec/studio_game_jb/dice_spec.rb
86
+ - spec/studio_game_jb/game_turn_spec.rb
87
+ - spec/studio_game_jb/clumsy_player_spec.rb
88
+ - LICENSE
89
+ - README.md
90
+ homepage: https://github.com/jorgeborges/studio_game_jb
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '1.9'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.0.3
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: A simple CLI game made for the Pragmatic Studio Ruby course.
114
+ test_files:
115
+ - spec/support/players.csv
116
+ - spec/studio_game_jb/berserk_player_spec.rb
117
+ - spec/studio_game_jb/treasure_trove_spec.rb
118
+ - spec/studio_game_jb/game_spec.rb
119
+ - spec/studio_game_jb/player_spec.rb
120
+ - spec/studio_game_jb/dice_spec.rb
121
+ - spec/studio_game_jb/game_turn_spec.rb
122
+ - spec/studio_game_jb/clumsy_player_spec.rb