studio_game_oas 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ Copyright (C) 2012 <copyright holders (see below)>
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
+
9
+ (taken from http://en.wikipedia.org/wiki/MIT_License)
10
+
11
+ NB: I wrote this code under the direction of an online course in ruby programming. As such, one could argue that I didn't actually *write* the code so much as *recreate* code originally written by the course instructors. That makes me wonder who actually does hold the copyright for this code and whether I actually have any authority at all to assign permission. Bear that in mind if you do anything with this code.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ Simple game simulation Ruby program written for the online Ruby Programming course from The Pragmatic Studio.
2
+
3
+ Create a csv file (or use the provided file 'players.csv') that contains the player names and their initial health, and give that file as an argument to bin/studio_game. The game simulation will add two specialized players and then run a user-specified numbers of rounds, randomly assigning, or inflicting, game events on the various players, printing individual round results and a final summary at the end.
data/bin/players.csv ADDED
@@ -0,0 +1,3 @@
1
+ moe,100
2
+ larry,60
3
+ curly,125
data/bin/studio_game ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/studio_game_oas/game'
4
+ require_relative '../lib/studio_game_oas/clumsy_player'
5
+ require_relative '../lib/studio_game_oas/berserk_player'
6
+
7
+ knuckleheads = StudioGameOAS::Game.new("Knuckleheads")
8
+
9
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
10
+ knuckleheads.load_players_csv(ARGV.shift || default_player_file)
11
+
12
+ clumsyPlayer = StudioGameOAS::ClumsyPlayer.new("klutz", 105, 5)
13
+ knuckleheads.add_player(clumsyPlayer)
14
+
15
+ berserkPlayer = StudioGameOAS::BerserkPlayer.new("berserker", 50)
16
+ knuckleheads.add_player(berserkPlayer)
17
+
18
+ loop do
19
+ puts "\nHow many game rounds? ('quit' to exit)"
20
+ answer = gets.chomp.downcase
21
+ case answer
22
+ when /^\d+$/
23
+ knuckleheads.play(Integer(answer))
24
+ when 'quit', 'exit'
25
+ knuckleheads.print_stats
26
+ break
27
+ else
28
+ puts "Please enter a number or 'quit'"
29
+ end
30
+ end
31
+
32
+ knuckleheads.save_high_scores
@@ -0,0 +1,7 @@
1
+ module StudioGameOAS
2
+ module Auditable
3
+ def audit
4
+ puts "Rolled a #{self.number} (#{self.class})"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,42 @@
1
+ module StudioGameOAS
2
+ require_relative 'player'
3
+
4
+ class BerserkPlayer < Player
5
+
6
+ def initialize(name, health=100)
7
+ super(name, health)
8
+ @w00t_count = 0
9
+ end
10
+
11
+
12
+ def berserk?
13
+ @w00t_count > 5
14
+ end
15
+
16
+
17
+ def w00t
18
+ super
19
+ @w00t_count += 1
20
+ puts "#{@name} is berserk!" if berserk?
21
+ end
22
+
23
+
24
+ def blam
25
+ if berserk?
26
+ w00t
27
+ else
28
+ super
29
+ end
30
+ # berserk? ? w00t : super
31
+ end
32
+
33
+ end
34
+
35
+
36
+ if __FILE__ == $0
37
+ berserker = BerserkPlayer.new("berserker", 50)
38
+ 6.times { berserker.w00t }
39
+ 2.times { berserker.blam }
40
+ puts berserker.health
41
+ end
42
+ end
@@ -0,0 +1,47 @@
1
+ module StudioGameOAS
2
+ require_relative 'player'
3
+ require_relative 'treasure_trove'
4
+
5
+ class ClumsyPlayer < Player
6
+
7
+
8
+ def initialize(name, health=100, boost_factor=1)
9
+ super(name, health)
10
+ @boost_factor = boost_factor
11
+ end
12
+
13
+
14
+ def boost_factor
15
+ @boost_factor
16
+ end
17
+
18
+ def w00t
19
+ @boost_factor.times { super }
20
+ end
21
+
22
+
23
+ def found_treasure(treasure)
24
+ broken_treasure = Treasure.new(treasure.name, treasure.points / 2)
25
+ super(broken_treasure)
26
+ end
27
+ end
28
+
29
+
30
+
31
+ if __FILE__ == $0
32
+ clumsy = ClumsyPlayer.new("klutz")
33
+
34
+ hammer = Treasure.new(:hammer, 50)
35
+ clumsy.found_treasure(hammer)
36
+ clumsy.found_treasure(hammer)
37
+ clumsy.found_treasure(hammer)
38
+
39
+ crowbar = Treasure.new(:crowbar, 400)
40
+ clumsy.found_treasure(crowbar)
41
+
42
+ clumsy.each_found_treasure do |treasure|
43
+ puts "#{treasure.points} total #{treasure.name} points"
44
+ end
45
+ puts "#{clumsy.points} grand total points"
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ module StudioGameOAS
2
+ require_relative 'auditable'
3
+
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
+
19
+ end
20
+ end
@@ -0,0 +1,122 @@
1
+ module StudioGameOAS
2
+
3
+ require_relative 'game_turn'
4
+ require 'csv'
5
+
6
+ class Game
7
+ attr_reader :title
8
+
9
+ def initialize(title)
10
+ @title = title
11
+ @players = []
12
+ end
13
+
14
+ def load_players(name)
15
+ lines = File.readlines(name)
16
+ lines.each do |line|
17
+ player = Player.parse_player(line)
18
+ add_player(player)
19
+ end
20
+ end
21
+
22
+ def load_players_csv(name)
23
+ CSV.foreach(name, converters: :numeric) do |row|
24
+ add_player(Player.new(row[0], row[1]))
25
+ end
26
+ end
27
+
28
+ def add_player(player)
29
+ @players << player
30
+ end
31
+
32
+ def play(rounds)
33
+
34
+ puts("There are #{@players.length} players in #{@title}:")
35
+ @players.each do |player|
36
+ puts player
37
+ end
38
+
39
+ treasures = TreasureTrove::TREASURES
40
+ puts("\nThere are #{treasures.length} treasures to be found:")
41
+ treasures.each do |treasure|
42
+ puts "A #{treasure.name} is worth #{treasure.points} points"
43
+ end
44
+
45
+ 1.upto(rounds) do |round|
46
+ if block_given?
47
+ break if yield
48
+ end
49
+ puts("\nRound #{round}:")
50
+ @players.each do |player|
51
+ GameTurn.take_turn(player)
52
+ end
53
+ end
54
+
55
+ end
56
+
57
+
58
+ def print_stats
59
+ puts "\n#{@title} Statstics:"
60
+
61
+ strong_players, weak_players = @players.partition { |player| player.strong? }
62
+
63
+ puts "\n#{strong_players.count} strong players:"
64
+ strong_players.each do |player|
65
+ print_name_and_health(player)
66
+ end
67
+
68
+ puts "\n#{weak_players.count} wimpy players"
69
+ weak_players.each do |player|
70
+ print_name_and_health(player)
71
+ end
72
+
73
+ @players.each do |player|
74
+ puts "\n#{player.name}'s point totals:"
75
+
76
+ player.each_found_treasure do |treasure|
77
+ puts "#{treasure.points} total #{treasure.name} points"
78
+ end
79
+
80
+ puts "#{player.points} grand total points"
81
+ end
82
+
83
+ puts "\n#{total_points} total points from treasures found"
84
+
85
+ puts "\n#{@title} High Scores:"
86
+ @players.sort.each do |player|
87
+ puts(format_high_score(player))
88
+ end
89
+ end
90
+
91
+
92
+ def total_points
93
+ @players.inject(0) { |sum, player| sum + player.points }
94
+ end
95
+
96
+
97
+ def print_players(players)
98
+ players.each { |player| puts "#{player.name} (#{player.health})" }
99
+ end
100
+
101
+
102
+ def print_name_and_health(player)
103
+ puts "#{player.name} (#{player.health})"
104
+ end
105
+
106
+ def save_high_scores(out_file="high_scores.txt")
107
+ File.open(out_file, "w") do |file|
108
+ file.puts "#{@title} High Scores:"
109
+ @players.sort.each do |player|
110
+ file.puts(format_high_score(player))
111
+ end
112
+ end
113
+ end
114
+
115
+ def format_high_score(player)
116
+ formatted_name = player.name.ljust(20, '.')
117
+ "#{formatted_name} #{player.score}"
118
+ end
119
+
120
+ end
121
+ end
122
+
@@ -0,0 +1,36 @@
1
+ module StudioGameOAS
2
+
3
+ require_relative 'player'
4
+ require_relative 'die'
5
+ #require_relative 'loaded_die'
6
+ require_relative 'treasure_trove'
7
+
8
+ module GameTurn
9
+ def self.take_turn(player)
10
+ die = Die.new
11
+ # die = LoadedDie.new
12
+
13
+ case die.roll
14
+ when 1..2
15
+ player.blam
16
+ when 3..4
17
+ puts "#{player.name} was skipped"
18
+ else
19
+ player.w00t
20
+ end
21
+
22
+ treasure = TreasureTrove.random
23
+ player.found_treasure(treasure)
24
+ end
25
+
26
+ end
27
+
28
+
29
+ if __FILE__ == $0
30
+ p = Player.new("moe")
31
+ puts p
32
+ GameTurn.take_turn(p)
33
+ puts p
34
+ end
35
+ end
36
+
@@ -0,0 +1,16 @@
1
+ module StudioGameOAS
2
+ require_relative 'auditable'
3
+
4
+ class LoadedDie
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 StudioGameOAS
2
+ module Playable
3
+ def blam
4
+ self.health -= 10
5
+ puts "#{name} got blammed!"
6
+ end
7
+
8
+ def w00t
9
+ self.health += 15
10
+ puts "#{name} got w00ted!"
11
+ end
12
+
13
+ def strong?
14
+ self.health > 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,61 @@
1
+ module StudioGameOAS
2
+ require_relative 'playable'
3
+
4
+ class Player
5
+ include Playable
6
+
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 score
17
+ @health + points
18
+ end
19
+
20
+ def to_s
21
+ "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
22
+ end
23
+
24
+ def found_treasure(treasure)
25
+ @found_treasures[treasure.name] += treasure.points
26
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
27
+ end
28
+
29
+ def points
30
+ @found_treasures.values.inject(0, :+)
31
+ end
32
+
33
+ def <=>(other)
34
+ other.score <=> score
35
+ end
36
+
37
+ def each_found_treasure
38
+ @found_treasures.each do |name, points|
39
+ yield Treasure.new(name, points)
40
+ end
41
+ end
42
+
43
+ # parse player fields from a csv file
44
+ def self.parse_player(entry)
45
+ name, health = entry.split(',')
46
+ new(name, Integer(health))
47
+ end
48
+ end
49
+
50
+
51
+
52
+ if __FILE__ == $0
53
+ player = Player.new("moe")
54
+ puts player.name
55
+ puts player.health
56
+ player.w00t
57
+ puts player.health
58
+ player.blam
59
+ puts player.health
60
+ end
61
+ end
@@ -0,0 +1,20 @@
1
+ module StudioGameOAS
2
+ Treasure = Struct.new(:name, :points)
3
+
4
+
5
+ module TreasureTrove
6
+ TREASURES = [
7
+ Treasure.new(:pie, 5),
8
+ Treasure.new(:bottle, 25),
9
+ Treasure.new(:hammer, 50),
10
+ Treasure.new(:skillet, 100),
11
+ Treasure.new(:broomstick, 200),
12
+ Treasure.new(:crowbar, 400)
13
+ ]
14
+
15
+
16
+ def self.random
17
+ TREASURES.sample
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,30 @@
1
+ module StudioGameOAS
2
+
3
+ require 'studio_game_oas/berserk_player'
4
+
5
+ describe BerserkPlayer do
6
+ before do
7
+ @initial_health = 50
8
+ @player = BerserkPlayer.new("berserker", @initial_health)
9
+ end
10
+
11
+ it "does not go berserk when w00ted up to 5 times" do
12
+ 1.upto(5) { @player.w00t }
13
+
14
+ @player.berserk?.should be_false
15
+ end
16
+
17
+ it "goes berserk when w00ted more than 5 times" do
18
+ 1.upto(6) { @player.w00t }
19
+
20
+ @player.berserk?.should be_true
21
+ end
22
+
23
+ it "gets w00ted instead of blammed when it's gone berserk" do
24
+ 1.upto(6) { @player.w00t }
25
+ 1.upto(2) { @player.blam }
26
+
27
+ @player.health.should == @initial_health + (8 * 15)
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,54 @@
1
+ module StudioGameOAS
2
+
3
+ require 'studio_game_oas/clumsy_player'
4
+ require 'studio_game_oas/treasure_trove'
5
+
6
+ describe ClumsyPlayer do
7
+ before do
8
+ @player = ClumsyPlayer.new("klutz")
9
+ end
10
+
11
+ it "only gets half the point value for each treasure" do
12
+ @player.points.should == 0
13
+
14
+ hammer = Treasure.new(:hammer, 50)
15
+ @player.found_treasure(hammer)
16
+ @player.found_treasure(hammer)
17
+ @player.found_treasure(hammer)
18
+
19
+ @player.points.should == 75
20
+
21
+ crowbar = Treasure.new(:crowbar, 400)
22
+ @player.found_treasure(crowbar)
23
+
24
+ @player.points.should == 275
25
+
26
+ yielded = []
27
+ @player.each_found_treasure do |treasure|
28
+ yielded << treasure
29
+ end
30
+
31
+ yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
32
+
33
+ end
34
+
35
+ context "with a boost factor" do
36
+ before do
37
+ @initial_health = 100
38
+ @boost_factor = 10
39
+ @player = ClumsyPlayer.new("booster", @initial_health, @boost_factor)
40
+ end
41
+
42
+ it "has a boost factor" do
43
+ @player.boost_factor.should == @boost_factor
44
+ end
45
+
46
+ it "gets w00ted boost factor times each w00t" do
47
+ @player.w00t
48
+
49
+ @player.health.should == @initial_health + (15 * @boost_factor)
50
+ end
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,66 @@
1
+ module StudioGameOAS
2
+ require 'studio_game_oas/game'
3
+
4
+ describe Game do
5
+ before(:each) do
6
+ @game = Game.new("knuckleheads")
7
+
8
+ @initial_health = 100
9
+ @rounds = 2
10
+
11
+ @player = Player.new("moe", @initial_health)
12
+ @game.add_player(@player)
13
+ end
14
+
15
+ it "w00ts the player on a high roll" do
16
+ Die.any_instance.stub(:roll).and_return(5)
17
+
18
+ @game.play(@rounds)
19
+
20
+ @player.health.should == @initial_health + (15 * @rounds)
21
+ end
22
+
23
+ it "skips the player on a medium roll" do
24
+ Die.any_instance.stub(:roll).and_return(3)
25
+
26
+ @game.play(@rounds)
27
+
28
+ @player.health.should == @initial_health
29
+ end
30
+
31
+ it "blams the player on a low roll" do
32
+ Die.any_instance.stub(:roll).and_return(1)
33
+
34
+ @game.play(@rounds)
35
+
36
+ @player.health.should == @initial_health - (10 * @rounds)
37
+ end
38
+
39
+ # TODO - this and the next test should either use the game set up in before (adding
40
+ # larry in the second one) or set up a new context
41
+ it "assigns a treasure for points during a player's turn" do
42
+ game = Game.new("Knuckleheads")
43
+ player = Player.new("moe")
44
+ game.add_player(player)
45
+
46
+ game.play(1)
47
+
48
+ player.points.should_not be_zero
49
+ end
50
+
51
+ it "computes total points as the sum of all player points" do
52
+ game = Game.new("Knuckleheads")
53
+
54
+ player1 = Player.new("moe")
55
+ player2 = Player.new("larry")
56
+ 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,138 @@
1
+ module StudioGameOAS
2
+ require 'studio_game_oas/player'
3
+ require 'studio_game_oas/treasure_trove'
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 "computes a score as the sum of its health and its points" do
28
+ @player.found_treasure(Treasure.new(:hammer, 50))
29
+ @player.found_treasure(Treasure.new(:hammer, 50))
30
+
31
+ @player.score.should == 250
32
+ # @player.score.should == @player.health + @player.points
33
+ end
34
+
35
+ it "increases health by 15 when w00ted" do
36
+ @player.w00t
37
+
38
+ @player.health.should == @initial_health + 15
39
+ end
40
+
41
+ it "decreases health by 10 when blammed" do
42
+ @player.blam
43
+
44
+ @player.health.should == @initial_health - 10
45
+ end
46
+
47
+
48
+ it "computes points as the sum of all treasure points" do
49
+ @player.points.should == 0
50
+
51
+ @player.found_treasure(Treasure.new(:hammer, 50))
52
+
53
+ @player.points.should == 50
54
+
55
+ @player.found_treasure(Treasure.new(:crowbar, 400))
56
+
57
+ @player.points.should == 450
58
+
59
+ @player.found_treasure(Treasure.new(:hammer, 50))
60
+
61
+ @player.points.should == 500
62
+ end
63
+
64
+
65
+ it "yields each found treasure and its total points" do
66
+ @player.found_treasure(Treasure.new(:skillet, 100))
67
+ @player.found_treasure(Treasure.new(:skillet, 100))
68
+ @player.found_treasure(Treasure.new(:hammer, 50))
69
+ @player.found_treasure(Treasure.new(:bottle, 5))
70
+ @player.found_treasure(Treasure.new(:bottle, 5))
71
+ @player.found_treasure(Treasure.new(:bottle, 5))
72
+ @player.found_treasure(Treasure.new(:bottle, 5))
73
+ @player.found_treasure(Treasure.new(:bottle, 5))
74
+
75
+ yielded = []
76
+ @player.each_found_treasure do |treasure|
77
+ yielded << treasure
78
+ end
79
+
80
+ yielded.should == [
81
+ Treasure.new(:skillet, 200),
82
+ Treasure.new(:hammer, 50),
83
+ Treasure.new(:bottle, 25)
84
+ ]
85
+ end
86
+
87
+ context "with a health greater than 100" do
88
+
89
+ before do
90
+ @player = Player.new("larry", 150)
91
+ end
92
+
93
+ it "is strong" do
94
+ # @player.strong?.should == true
95
+ @player.strong?.should be_true
96
+ # @player.should be_strong
97
+ end
98
+
99
+ end
100
+
101
+ context "with a health less than or equal to 100" do
102
+
103
+ before do
104
+ @player = Player.new("larry", 100)
105
+ end
106
+
107
+ it "is wimpy" do
108
+ # @player.strong?.should_not == true
109
+ # @player.strong?.should_not be_true
110
+ @player.should_not be_strong
111
+ end
112
+ end
113
+
114
+ context "in a collection of players" do
115
+ before do
116
+ @player1 = Player.new("moe", 100)
117
+ @player2 = Player.new("larry", 200)
118
+ @player3 = Player.new("curly", 300)
119
+
120
+ @players = [@player1, @player2, @player3]
121
+ end
122
+
123
+ it "is sorted by decreasing score" do
124
+ @players.sort.should == [@player3, @player2, @player1]
125
+ end
126
+ end
127
+
128
+ context "from a csv file" do
129
+ it "can parse name,health into a player" do
130
+ @player = Player.parse_player("moe,200")
131
+
132
+ @player.name.should == "Moe"
133
+ @player.health.should == 200
134
+ end
135
+ end
136
+
137
+ end
138
+ end
@@ -0,0 +1,57 @@
1
+ module StudioGameOAS
2
+ require 'studio_game_oas/treasure_trove'
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
+
56
+ end
57
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_oas
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - OAS
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-20 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: ! 'Simple game simulation Ruby program written for the online Ruby Programming
31
+ course from The Pragmatic Studio.
32
+
33
+
34
+ Create a csv file (or use the provided file ''players.csv'') that contains the player
35
+ names and their initial health, and give that file as an argument to bin/studio_game.
36
+ The game simulation will add two specialized players and then run a user-specified
37
+ numbers of rounds, randomly assigning, or inflicting, game events on the various
38
+ players, printing individual round results and a final summary at the end.'
39
+ email: bwv564pub@verizon.net
40
+ executables:
41
+ - studio_game
42
+ extensions: []
43
+ extra_rdoc_files: []
44
+ files:
45
+ - bin/players.csv
46
+ - bin/studio_game
47
+ - lib/studio_game_oas/auditable.rb
48
+ - lib/studio_game_oas/berserk_player.rb
49
+ - lib/studio_game_oas/clumsy_player.rb
50
+ - lib/studio_game_oas/die.rb
51
+ - lib/studio_game_oas/game.rb
52
+ - lib/studio_game_oas/game_turn.rb
53
+ - lib/studio_game_oas/loaded_die.rb
54
+ - lib/studio_game_oas/playable.rb
55
+ - lib/studio_game_oas/player.rb
56
+ - lib/studio_game_oas/treasure_trove.rb
57
+ - spec/studio_game_oas/berserk_player_spec.rb
58
+ - spec/studio_game_oas/clumsy_player_spec.rb
59
+ - spec/studio_game_oas/game_spec.rb
60
+ - spec/studio_game_oas/player_spec.rb
61
+ - spec/studio_game_oas/treasure_trove_spec.rb
62
+ - LICENSE
63
+ - README
64
+ homepage: ''
65
+ licenses: []
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '1.9'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Simple, slightly random, gameplay
88
+ test_files:
89
+ - spec/studio_game_oas/berserk_player_spec.rb
90
+ - spec/studio_game_oas/clumsy_player_spec.rb
91
+ - spec/studio_game_oas/game_spec.rb
92
+ - spec/studio_game_oas/player_spec.rb
93
+ - spec/studio_game_oas/treasure_trove_spec.rb