studio_game_railstar 0.0.01

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) <2013> <Inhabitants of the planet Earth>
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,15 @@
1
+ Welcome to the "Knuckleheads" game, a (slightly enhanced version of the) fully functional text driven game written in Ruby 1.9 and used as a teaching aid for the excellent web-based Ruby course administered by Pragmatic Studios. W00t! W00t!
2
+
3
+ Before playing, fill the default csv file "players.csv" with any number of players by putting the name of each followed by their initial health (an integer separated from the name by a comma). Each player must be on a new line. You may also create an alternate file formatted the same way with a different name. (A sample alternate player file called "more_nuts.csv" is provided as an example.) Invoke an alternate file simply by entering the file name when prompted. How fun is that!!
4
+
5
+ To start the game, start the Ruby file "studio_game.rb" in Ruby 1.9 (or later should work as well) and follow the directions.
6
+
7
+ By the way, there are two players added in hard code with modified behavior. One is "sandro" a LOSER or "clumsy" player who damages his treasure upon collecting it, resulting in the value of each treasure being worth only half of it's original value. What a klutz!
8
+
9
+ The other is a wild-ass player, "bright_eyes." He's a serious partyier! After every other player is spent, he "finds the last beer in the fridge" and can't help but w00t. Bright_eyes starts off just like everyone else. But after being w00ted six times he goes freak'n w00t-crazy and w00ts EVERY TIME! You better think long and hard before committing to joining Mr. bright_eyes. Legend has it that he eats the livers of his prey after he parties them to death, and in this way remains an immortal player!
10
+
11
+ Now fire up that command line for some outrageous fun! CAUTION: It is addictive. My cousin, Schneebo (the Schneebo on my Dad's side, NOT Schneebo Salifronski) once sat down and played Knuckleheads non-stop for 176.39 hours. It's the truth - you've been warned.
12
+
13
+ Oh, and by the way:
14
+
15
+ Three w00ts for Pragmatic Studios - woot, woot, h00ray! - woot, woot, h00ray! - woot, woot, h00ray!
@@ -0,0 +1,8 @@
1
+ Knuckleheads High Scores:
2
+ Bright_eyes......... 2695
3
+ Frabo............... 2435
4
+ Stip................ 2270
5
+ Little_who.......... 1985
6
+ Schneddie........... 1915
7
+ Sandro.............. 1197.5
8
+ Roggie.............. 1070
data/bin/more_nuts.csv ADDED
@@ -0,0 +1,7 @@
1
+ Glapknee,11
2
+ Slagnakook,47
3
+ onward_Christian_Soldier_Dude,125
4
+ Oven_Boy, 7010
5
+ Harry, 70
6
+ Trippy, 21
7
+ our_man_Flint,110
data/bin/players.csv ADDED
@@ -0,0 +1,5 @@
1
+ Schneddie,100
2
+ Frabo,60
3
+ Stip,125
4
+ Little_Who, 10
5
+ Roggie, 70
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/studio_game_railstar/game'
4
+ require_relative '../lib/studio_game_railstar/clumsy_player'
5
+ require_relative '../lib/studio_game_railstar/berserk_player'
6
+
7
+ puts "Wanna play Knuckleheads? Y/N"
8
+ answer1 = gets.chomp.downcase
9
+ if answer1 == 'y'
10
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
11
+ puts "Supply a file of players, please."
12
+ player_file = gets.chomp.downcase
13
+ if player_file == "" then player_file = "players.csv" end
14
+ default_player_file = File.join(File.dirname(__FILE__), player_file) #knuckleheads.load_players("players.csv") #(player_file)
15
+ knuckleheads.load_players(ARGV.shift || default_player_file)
16
+ clumsy = StudioGame::ClumsyPlayer.new("sandro", 105)
17
+ knuckleheads.add_player(clumsy)
18
+ berserk = StudioGame::BerserkPlayer.new("bright_eyes", 40)
19
+ knuckleheads.add_player(berserk)
20
+
21
+ loop do
22
+ puts "\nHow many game rounds? ('quit' to exit)"
23
+ answer2 = gets.chomp.downcase
24
+ case answer2
25
+ when /^\d+$/
26
+ knuckleheads.play(answer2.to_i)
27
+ when 'quit', 'exit'
28
+ knuckleheads.print_stats
29
+ knuckleheads.save_high_scores
30
+ puts "\nBye-Bye Now!"
31
+ break
32
+ else
33
+ puts "Please enter a number or 'quit'"
34
+ end
35
+ end
36
+ else
37
+ puts "\nBye-Bye Now!"
38
+ end
@@ -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,38 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class BerserkPlayer < Player
5
+ def initialize(name, health)
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
+
27
+ # or use the ternary operator:
28
+ # berserk? ? w00t : super
29
+ end
30
+ end
31
+ end
32
+
33
+ if __FILE__ == $0
34
+ berserker = StudioGame::BerserkPlayer.new("berserker", 50)
35
+ 6.times { berserker.w00t }
36
+ 2.times { berserker.blam }
37
+ puts berserker.health
38
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+ def found_treasure(treasure)
6
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
7
+ super(damaged_treasure)
8
+ end
9
+
10
+ # def found_treasure(treasure)
11
+ # points = treasure.points / 2
12
+ # @found_treasures[treasure.name] += points
13
+ # puts "#{@name} found a #{treasure.name} worth #{points} points."
14
+ # end
15
+ end
16
+ end
17
+
18
+ if __FILE__ == $0
19
+ clumsy = StudioGame::ClumsyPlayer.new("klutz")
20
+ hammer = StudioGame::Treasure.new(:hammer, 50)
21
+ clumsy.found_treasure(hammer)
22
+ clumsy.found_treasure(hammer)
23
+ clumsy.found_treasure(hammer)
24
+ crowbar = StudioGame::Treasure.new(:crowbar, 400)
25
+ clumsy.found_treasure(crowbar)
26
+ clumsy.each_found_treasure do |treasure|
27
+ puts "#{treasure.points} total #{treasure.name} points"
28
+ end
29
+ puts "#{clumsy.points} grand total points"
30
+ end
@@ -0,0 +1,26 @@
1
+ require_relative 'auditable'
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
20
+
21
+ if __FILE__ == $0
22
+ die = StudioGame::Die.new
23
+ puts die.roll
24
+ puts die.roll
25
+ puts die.roll
26
+ end
@@ -0,0 +1,101 @@
1
+ require_relative 'player'
2
+ require_relative 'game_turn'
3
+ require_relative 'treasure_trove'
4
+
5
+ module StudioGame
6
+
7
+ class Game
8
+
9
+ attr_accessor :title
10
+
11
+ def initialize(title)
12
+ @title = title
13
+ @players = []
14
+ end
15
+
16
+ def add_player(a_player)
17
+ #Two ways to add a player
18
+ @players << a_player
19
+ #@players.push(a_player) #This option (push) remarked out for now.
20
+ end
21
+
22
+ def play(rounds)
23
+ puts "\n\nThere are #{@players.size} turkeys playing #{@title}: \nWatch these turkeys play!\n\n"
24
+
25
+ @players.each do |player|
26
+ puts player
27
+ end
28
+
29
+ treasures = TreasureTrove::TREASURES
30
+ puts "\nThere are #{treasures.size} treasures to be found:"
31
+ treasures.each do |treasure|
32
+ puts "A #{treasure.name} is worth #{treasure.points} points"
33
+ end
34
+
35
+ 1.upto(rounds) do |round|
36
+ puts "\nRound #{round}:"
37
+ @players.each do |player|
38
+ GameTurn.take_turn(player)
39
+ end
40
+ end
41
+ end
42
+
43
+ def print_name_and_health(player)
44
+ puts "#{player.name} (#{player.health})"
45
+ end
46
+
47
+ def high_score_entry(player)
48
+ formatted_name = player.name.ljust(20, '.')
49
+ "#{formatted_name} #{player.score}"
50
+ end
51
+
52
+ def total_points
53
+ @players.reduce(0) { |sum, player| sum + player.points }
54
+ end
55
+
56
+ def print_stats
57
+ puts "\n#{@title} Statistics:"
58
+
59
+ strong_players, wimpy_players = @players.partition { |player| player.strong? }
60
+
61
+ puts "\n#{strong_players.size} strong players:"
62
+ strong_players.each do |player|
63
+ print_name_and_health(player)
64
+ end
65
+
66
+ puts "\n#{wimpy_players.size} wimpy players:"
67
+ wimpy_players.each do |player|
68
+ print_name_and_health(player)
69
+ end
70
+
71
+ puts "\n#{total_points} total points from treasures found"
72
+ @players.each do |player|
73
+ puts "\n#{player.name}'s point totals:"
74
+ player.each_found_treasure do |treasure|
75
+ puts "#{treasure.points} total #{treasure.name} points"
76
+ end
77
+ puts "#{player.points} grand total points"
78
+ end
79
+
80
+ puts "\n#{@title} High Scores:"
81
+ @players.sort.each do |player|
82
+ puts high_score_entry(player)
83
+ end
84
+ end
85
+
86
+ def load_players(from_file)
87
+ File.readlines(from_file).each do |line|
88
+ add_player(Player.from_csv(line))
89
+ end
90
+ end
91
+
92
+ def save_high_scores(to_file="high_scores.txt")
93
+ File.open(to_file, "w") do |file|
94
+ file.puts "#{@title} High Scores:"
95
+ @players.sort.each do |player|
96
+ file.puts high_score_entry(player)
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,28 @@
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
24
+
25
+ if __FILE__ == $0
26
+ player = StudioGame::Player.new("curly", 125)
27
+ StudioGame::GameTurn.take_turn(player)
28
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'auditable'
2
+
3
+ module StudioGame
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
17
+
18
+ if __FILE__ == $0
19
+ die = StudioGame::LoadedDie.new
20
+ puts die.roll
21
+ puts die.roll
22
+ puts die.roll
23
+ end
@@ -0,0 +1,33 @@
1
+ # module Playable
2
+ # def w00t
3
+ # @health += 15
4
+ # puts "#{@name} got w00ted!"
5
+ # end
6
+ #
7
+ # def blam
8
+ # @health -= 10
9
+ # puts "#{@name} got blammed!"
10
+ # end
11
+ #
12
+ # def strong?
13
+ # @health > 100
14
+ # end
15
+ # end
16
+
17
+ module StudioGame
18
+ module Playable
19
+ def w00t
20
+ self.health += 15
21
+ puts "#{name} got w00ted!"
22
+ end
23
+
24
+ def blam
25
+ self.health -= 10
26
+ puts "#{name} got blammed!"
27
+ end
28
+
29
+ def strong?
30
+ self.health > 100
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,59 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Player
6
+ include Playable
7
+
8
+ attr_accessor :name, :health
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 points
21
+ @found_treasures.values.reduce(0, :+)
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 each_found_treasure
30
+ @found_treasures.each do |name, points|
31
+ next_treasure = Treasure.new(name, points)
32
+ yield next_treasure
33
+ end
34
+ end
35
+
36
+ def <=>(other)
37
+ other.score <=> score
38
+ end
39
+
40
+ def to_s
41
+ "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
42
+ end
43
+
44
+ def self.from_csv(string)
45
+ name, health = string.split(',')
46
+ new(name, Integer(health))
47
+ end
48
+ end
49
+ end
50
+
51
+ if __FILE__ == $0
52
+ player = StudioGame::Player.new("moe")
53
+ puts player.name
54
+ puts player.health
55
+ player.w00t
56
+ puts player.health
57
+ player.blam
58
+ puts player.health
59
+ 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,33 @@
1
+ require 'studio_game_railstar/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
+
33
+ end
@@ -0,0 +1,32 @@
1
+ require 'studio_game_railstar/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
+ end
32
+ end
@@ -0,0 +1,69 @@
1
+ require 'studio_game_railstar/game'
2
+
3
+ module StudioGame
4
+ describe Game do
5
+ before do
6
+ @game = Game.new("Knuckleheads")
7
+
8
+ @initial_health = 100
9
+ @player = Player.new("moe", @initial_health)
10
+
11
+ @game.add_player(@player)
12
+ end
13
+
14
+ it "has a title" do
15
+ @game.title.should == "Knuckleheads"
16
+ end
17
+
18
+ it "w00ts the player if a high number is rolled" do
19
+ Die.any_instance.stub(:roll).and_return(5)
20
+
21
+ @game.play(2)
22
+
23
+ @player.health.should == @initial_health + (15 * 2)
24
+ end
25
+
26
+ it "skips the player if a medium number is rolled" do
27
+ Die.any_instance.stub(:roll).and_return(3)
28
+
29
+ @game.play(2)
30
+
31
+ @player.health.should == @initial_health
32
+ end
33
+
34
+ it "blams the player if a low number is rolled" do
35
+ Die.any_instance.stub(:roll).and_return(1)
36
+
37
+ @game.play(2)
38
+
39
+ @player.health.should == @initial_health - (10 * 2)
40
+ end
41
+
42
+ it "assigns a treasure for points during a player's turn" do
43
+ game = Game.new("Knuckleheads")
44
+ player = Player.new("moe")
45
+
46
+ game.add_player(player)
47
+
48
+ game.play(1)
49
+
50
+ player.points.should_not be_zero
51
+ end
52
+
53
+ it "computes total points as the sum of all player points" do
54
+ game = Game.new("Knuckleheads")
55
+
56
+ player1 = Player.new("moe")
57
+ player2 = Player.new("larry")
58
+
59
+ game.add_player(player1)
60
+ game.add_player(player2)
61
+
62
+ player1.found_treasure(Treasure.new(:hammer, 50))
63
+ player1.found_treasure(Treasure.new(:hammer, 50))
64
+ player2.found_treasure(Treasure.new(:crowbar, 400))
65
+
66
+ game.total_points.should == 500
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,133 @@
1
+ require 'studio_game_railstar/player'
2
+
3
+ module StudioGame
4
+ describe Player do
5
+ before do
6
+ @initial_health = 150
7
+ @player = Player.new("larry", @initial_health)
8
+ end
9
+
10
+ it "has a capitalized name" do
11
+ @player.name.should == "Larry"
12
+ end
13
+
14
+ it "has an initial health" do
15
+ @player.health.should == 150
16
+ end
17
+
18
+ it "has a string representation" do
19
+ @player.found_treasure(Treasure.new(:hammer, 50))
20
+ @player.found_treasure(Treasure.new(:hammer, 50))
21
+
22
+ @player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
23
+ end
24
+
25
+ it "increases health by 15 when w00ted" do
26
+ @player.w00t
27
+
28
+ @player.health.should == @initial_health + 15
29
+ end
30
+
31
+ it "decreases health by 10 when blammed" do
32
+ @player.blam
33
+
34
+ @player.health.should == @initial_health - 10
35
+ end
36
+
37
+ context "created with a default health" do
38
+ before do
39
+ @player = Player.new("larry")
40
+ end
41
+
42
+ it "has a health of 100" do
43
+ @player.health.should == 100
44
+ end
45
+ end
46
+
47
+ context "with a 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 "with a health of 100 or less" do
58
+ before do
59
+ @player = Player.new("larry", 100)
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
+
81
+ it "computes a score as the sum of its health and points" do
82
+ @player.found_treasure(Treasure.new(:hammer, 50))
83
+ @player.found_treasure(Treasure.new(:hammer, 50))
84
+
85
+ @player.score.should == 250
86
+ end
87
+
88
+ it "computes points as the sum of all treasure points" do
89
+ @player.points.should == 0
90
+
91
+ @player.found_treasure(Treasure.new(:hammer, 50))
92
+
93
+ @player.points.should == 50
94
+
95
+ @player.found_treasure(Treasure.new(:crowbar, 400))
96
+
97
+ @player.points.should == 450
98
+
99
+ @player.found_treasure(Treasure.new(:hammer, 50))
100
+
101
+ @player.points.should == 500
102
+ end
103
+
104
+ it "yields each found treasure and its total points" do
105
+ @player.found_treasure(Treasure.new(:skillet, 100))
106
+ @player.found_treasure(Treasure.new(:skillet, 100))
107
+ @player.found_treasure(Treasure.new(:hammer, 50))
108
+ @player.found_treasure(Treasure.new(:bottle, 5))
109
+ @player.found_treasure(Treasure.new(:bottle, 5))
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
+
114
+ yielded = []
115
+ @player.each_found_treasure do |treasure|
116
+ yielded << treasure
117
+ end
118
+
119
+ yielded.should == [
120
+ Treasure.new(:skillet, 200),
121
+ Treasure.new(:hammer, 50),
122
+ Treasure.new(:bottle, 25)
123
+ ]
124
+ end
125
+
126
+ it "can be created from a CSV string" do
127
+ player = Player.from_csv("larry,150")
128
+
129
+ player.name.should == "Larry"
130
+ player.health.should == 150
131
+ end
132
+ end
133
+ end
@@ -0,0 +1,53 @@
1
+ require 'studio_game_railstar/treasure_trove'
2
+
3
+ module StudioGame
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
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_railstar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.01
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kenny Von Subwoofer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &22626408 !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: *22626408
25
+ description: ! 'Welcome to the "Knuckleheads" game, a (slightly enhanced version of
26
+ the) fully functional text driven game written in Ruby 1.9 and used as a teaching
27
+ aid for the excellent web-based Ruby course administered by Pragmatic Studios. W00t! W00t!
28
+
29
+
30
+ Before playing, fill the default csv file "players.csv" with any number of players
31
+ by putting the name of each followed by their initial health (an integer separated
32
+ from the name by a comma). Each player must be on a new line. You may also create
33
+ an alternate file formatted the same way with a different name. (A sample alternate
34
+ player file called "more_nuts.csv" is provided as an example.) Invoke an alternate
35
+ file simply by entering the file name when prompted. How fun is that!!
36
+
37
+
38
+ To start the game, start the Ruby file "studio_game.rb" in Ruby 1.9 (or later should
39
+ work as well) and follow the directions.
40
+
41
+
42
+ By the way, there are two players added in hard code with modified behavior. One
43
+ is "sandro" a LOSER or "clumsy" player who damages his treasure upon collecting
44
+ it, resulting in the value of each treasure being worth only half of it''s original
45
+ value. What a klutz!
46
+
47
+
48
+ The other is a wild-ass player, "bright_eyes." He''s a serious partyier! After
49
+ every other player is spent, he "finds the last beer in the fridge" and can''t help
50
+ but w00t. Bright_eyes starts off just like everyone else. But after being w00ted
51
+ six times he goes freak''n w00t-crazy and w00ts EVERY TIME! You better think long
52
+ and hard before committing to joining Mr. bright_eyes. Legend has it that he eats
53
+ the livers of his prey after he parties them to death, and in this way remains an
54
+ immortal player!
55
+
56
+
57
+ Now fire up that command line for some outrageous fun! CAUTION: It is addictive. My
58
+ cousin, Schneebo (the Schneebo on my Dad''s side, NOT Schneebo Salifronski) once
59
+ sat down and played Knuckleheads non-stop for 176.39 hours. It''s the truth - you''ve
60
+ been warned.
61
+
62
+
63
+ Oh, and by the way:
64
+
65
+
66
+ Three w00ts for Pragmatic Studios - woot, woot, h00ray! - woot, woot, h00ray! -
67
+ woot, woot, h00ray!'
68
+ email: ken@railstarengineering.com
69
+ executables:
70
+ - studio_game_railstar
71
+ extensions: []
72
+ extra_rdoc_files: []
73
+ files:
74
+ - bin/high_scores.txt
75
+ - bin/more_nuts.csv
76
+ - bin/players.csv
77
+ - bin/studio_game_railstar
78
+ - lib/studio_game_railstar/auditable.rb
79
+ - lib/studio_game_railstar/berserk_player.rb
80
+ - lib/studio_game_railstar/clumsy_player.rb
81
+ - lib/studio_game_railstar/die.rb
82
+ - lib/studio_game_railstar/game.rb
83
+ - lib/studio_game_railstar/game_turn.rb
84
+ - lib/studio_game_railstar/loaded_die.rb
85
+ - lib/studio_game_railstar/playable.rb
86
+ - lib/studio_game_railstar/player.rb
87
+ - lib/studio_game_railstar/treasure_trove.rb
88
+ - spec/studio_game_railstar/berserk_player_spec.rb
89
+ - spec/studio_game_railstar/clumsy_player_spec.rb
90
+ - spec/studio_game_railstar/game_spec.rb
91
+ - spec/studio_game_railstar/player_spec.rb
92
+ - spec/studio_game_railstar/treasure_trove_spec.rb
93
+ - LICENSE
94
+ - README
95
+ homepage: http://pragmaticstudio.com
96
+ licenses: []
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ none: false
103
+ requirements:
104
+ - - ! '>='
105
+ - !ruby/object:Gem::Version
106
+ version: '1.9'
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 1.8.16
116
+ signing_key:
117
+ specification_version: 3
118
+ summary: A (slightly enhanced version of the) highly acclaimed game Knuckleheads
119
+ test_files:
120
+ - spec/studio_game_railstar/berserk_player_spec.rb
121
+ - spec/studio_game_railstar/clumsy_player_spec.rb
122
+ - spec/studio_game_railstar/game_spec.rb
123
+ - spec/studio_game_railstar/player_spec.rb
124
+ - spec/studio_game_railstar/treasure_trove_spec.rb