gameology 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ N2Y2YTg0NTcyMmM2M2Q5MDdlOWMyYzA5YWUwMDUxZDM4MWZmNjU3Zg==
5
+ data.tar.gz: !binary |-
6
+ YTUzODdlMDM3MmE3MzEzMDJiZDk3MzFmM2VkZDg2NjBjNWVjOTk3MQ==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ N2ViMjlkZjhmMmE2MDFhZjk5ZjlhMjRmODEyMjk1MjhiODJhZmU0ZjUzNjVm
10
+ NWEyNjRjM2Q5ZDQ1NWMyNGYyYzlmNDMxNDg5Y2NkYTM4ZDM3MjlkNTEwNjAx
11
+ NjllMzQzZDJlNjliNzlkNWMzOWM1N2VmMTk3ZmM3N2E5MjhiNTU=
12
+ data.tar.gz: !binary |-
13
+ MjlmYmVjYWNjYTBlNTNmMDYzMDE1MTMxYzY0NDM5ZjhhZTU3NTA0NWYxNjFl
14
+ YjgzZTBjODY1NGVjM2FlNWRjM2U2ZTU2ODQ2NWU5ZjVhNjI4YzQ5NDJjZDVh
15
+ MmJjOTFmZTJmZjUyYTE4NWVhZDIyNWEyNTE2YzZjZjAyMjExZjk=
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (C) <year> <copyright holders>
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 @@
1
+ This program is a simple game in which the players each take turns rolling a virtual die. The scores and healths of the players are determined based on the roll of the die and which treasures they find. Each player keeps collecting treasures each round and can either gain or lose points based on the roll of the die. When you decide the game is over the stats are all listed out at the bottom.
@@ -0,0 +1,6 @@
1
+ Knuckleheads High Scores
2
+ Alvin............... 3255
3
+ Simon............... 2170
4
+ Klutz............... 2115.0
5
+ Theo................ 2010
6
+ Berserker........... 1665
@@ -0,0 +1,3 @@
1
+ Alvin,100
2
+ Simon,60
3
+ Theo,125
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ # `chmod 755 #{__FILE__}`
3
+
4
+ require_relative '../lib/studio_game/player'
5
+ require_relative '../lib/studio_game/game'
6
+ require_relative '../lib/studio_game/clumsy_player'
7
+ require_relative '../lib/studio_game/berserk_player'
8
+
9
+ klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
10
+ berserk = StudioGame::BerserkPlayer.new("berserker", 50)
11
+
12
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
13
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
14
+ knuckleheads.load_players(ARGV.shift || default_player_file)
15
+ knuckleheads.add_player(klutz)
16
+ knuckleheads.add_player(berserk)
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 number or 'quit'"
30
+ end
31
+ end
32
+
33
+ knuckleheads.save_high_scores
34
+
35
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+ chmod +x bin/studio_game
3
+
4
+ require_relative '../lib/studio_game/player'
5
+ require_relative '../lib/studio_game/game'
6
+ require_relative '../lib/studio_game/clumsy_player'
7
+ require_relative '../lib/studio_game/berserk_player'
8
+
9
+ klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
10
+ berserk = StudioGame::BerserkPlayer.new("berserker", 50)
11
+
12
+ knuckleheads = StudioGame::Game.new("Knuckleheads")
13
+ default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
14
+ game.load_players(ARGV.shift || default_player_file)
15
+ knuckleheads.add_player(klutz)
16
+ knuckleheads.add_player(berserk)
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 number or 'quit'"
30
+ end
31
+ end
32
+
33
+ knuckleheads.save_high_scores
34
+
35
+
@@ -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,37 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class BerserkPlayer < Player
5
+
6
+ def initialize(name, health)
7
+ super(name, health)
8
+ @w00t_count = 0
9
+ end
10
+
11
+ def berserk?
12
+ @w00t_count > 5
13
+ end
14
+
15
+ def w00t
16
+ super
17
+ @w00t_count +=1
18
+ puts "#{@name} is berserk!" if berserk?
19
+ end
20
+
21
+ def blam
22
+ if berserk?
23
+ w00t
24
+ else
25
+ super
26
+ end
27
+ end
28
+ end
29
+ end
30
+
31
+ if __FILE__ == $0
32
+ berserker = BerserkPlayer.new("berserker", 50)
33
+ 6.times { berserker.w00t }
34
+ 2.times { berserker.blam }
35
+ puts berserker.health
36
+
37
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+
6
+ # attr_reader :boost_factor
7
+
8
+ # def initialize(name, health=100, boost_factor=1)
9
+ # super(name, health)
10
+ # @boost_factor = boost_factor
11
+ # end
12
+
13
+ # def w00t
14
+ # @boost_factor.times { super }
15
+ # end
16
+ # end
17
+
18
+ # clumsy = ClumsyPlayer.new("klutz", 105, 3)
19
+
20
+ def found_treasure(treasure)
21
+ damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
22
+ super(damaged_treasure)
23
+ end
24
+
25
+ def w00t
26
+ super
27
+ @health += 10
28
+ end
29
+ end
30
+ end
31
+
32
+ if __FILE__ == $0
33
+ clumsy = ClumsyPlayer.new("klutz")
34
+
35
+ hammer = Treasure.new(:hammer, 50)
36
+ clumsy.found_treasure(hammer)
37
+ clumsy.found_treasure(hammer)
38
+ clumsy.found_treasure(hammer)
39
+
40
+ crowbar = Treasure.new(:crowbar, 400)
41
+ clumsy.found_treasure(crowbar)
42
+
43
+ clumsy.each_found_treasure do |treasure|
44
+ puts "#{treasure.points} total #{treasure.name} points"
45
+ end
46
+ puts "#{clumsy.points} grand total points"
47
+ end
48
+
49
+ if __FILE__ == $0
50
+ klutz = ClumsyPlayer.new("klutz", 50)
51
+ klutz.w00t
52
+ puts klutz.health
53
+ end
@@ -0,0 +1,24 @@
1
+ require_relative 'auditable'
2
+ module StudioGame
3
+ class Die
4
+ include Auditable
5
+ attr_reader :number
6
+
7
+ def initialize
8
+ roll
9
+ end
10
+
11
+ def roll
12
+ @number = rand(1..6)
13
+ audit
14
+ @number
15
+ end
16
+ end
17
+ end
18
+
19
+ if __FILE__ == $0
20
+ die = Die.new
21
+ puts die.roll
22
+ puts die.roll
23
+ puts die.roll
24
+ end
@@ -0,0 +1,118 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'game_turn'
4
+ require_relative 'treasure_trove'
5
+
6
+ module StudioGame
7
+ class Game
8
+
9
+ attr_reader :title
10
+
11
+ def initialize(title)
12
+ @title = title
13
+ @players = []
14
+ end
15
+
16
+ def add_player(player_name)
17
+ @players.push(player_name)
18
+ end
19
+
20
+ def play(rounds)
21
+ puts "There are #{@players.size} players in #{@title}:"
22
+
23
+ treasures = TreasureTrove::TREASURES
24
+ puts "\nThere are #{treasures.size} treasures to be found:"
25
+
26
+ treasures.each do |treasures|
27
+ puts " A #{treasures.name} is worth #{treasures.points} points."
28
+ end
29
+
30
+ @players.each do |player|
31
+ puts player
32
+ end
33
+
34
+ 1.upto(rounds) do |round|
35
+ if block_given?
36
+ break if yield
37
+ end
38
+ puts "\nRound #{round}:"
39
+
40
+ @players.each do |player|
41
+ GameTurn.take_turn(player)
42
+ puts player
43
+ end
44
+ end
45
+ end
46
+
47
+ def print_name_and_health(player)
48
+ puts "#{player.name} (#{player.health})"
49
+ end
50
+
51
+ def print_stats
52
+ puts "\n#{@title} Statistics:"
53
+
54
+ strong_players, wimpy_players = @players.partition { |player| player.strong?}
55
+
56
+ puts "\n#{strong_players.size} strong players:"
57
+ strong_players.each do |player|
58
+ print_name_and_health(player)
59
+ end
60
+
61
+ puts "\n#{wimpy_players.size} wimpy players:"
62
+ wimpy_players.each do |player|
63
+ print_name_and_health(player)
64
+ end
65
+
66
+ puts "\n#{@title} High Scores"
67
+ @players.sort.each do |player|
68
+ puts high_score_entry(player)
69
+ end
70
+
71
+ @players.sort.each do |player|
72
+ puts "\n#{player.name}'s point totals:"
73
+ puts "#{player.points} grand total points"
74
+ end
75
+
76
+ puts "\n#{total_points} total points from treasures found"
77
+
78
+ @players.sort.each do |player|
79
+ puts "\n#{player.name}'s point totals:"
80
+ player.each_found_treasure do |treasure|
81
+ puts "#{treasure.points} total #{treasure.name} points"
82
+ end
83
+ puts "#{player.points} grand total points"
84
+ end
85
+ end
86
+
87
+ def total_points
88
+ @players.reduce(0) {|sum, player| sum + player.points}
89
+ end
90
+
91
+ def load_players(from_file)
92
+ File.readlines(from_file).each do |line|
93
+ add_player(Player.from_csv(line))
94
+ end
95
+ end
96
+
97
+ # def load_players(from_file)
98
+ # CSV.foreach(from_file) do |row|
99
+ # player = Player.new(row[0], row[1].to_i)
100
+ # add_player(player)
101
+ # end
102
+ # end
103
+
104
+ def save_high_scores(to_file="high_scores.txt")
105
+ File.open(to_file, "w") do |file|
106
+ file.puts "#{@title} High Scores"
107
+ @players.sort.each do |player|
108
+ file.puts high_score_entry(player)
109
+ end
110
+ end
111
+ end
112
+
113
+ def high_score_entry(player)
114
+ formatted_name = player.name.ljust(20, '.')
115
+ "#{formatted_name} #{player.score}"
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,30 @@
1
+ require_relative 'player'
2
+ require_relative 'die'
3
+ require_relative 'treasure_trove'
4
+ require_relative 'loaded_die'
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
+ player.found_treasure(TreasureTrove.random)
20
+
21
+ #treasure = TreasureTrove.random
22
+ #puts "#{player.name} found a #{treasure.name} worth #{treasure.points} points."
23
+ end
24
+ end
25
+ end
26
+
27
+ if __FILE__ == $0
28
+ player = Player.new("curly", 125)
29
+ GameTurn.take_turn(player)
30
+ end
@@ -0,0 +1,15 @@
1
+ require_relative 'auditable'
2
+ module StudioGame
3
+ class LoadedDie
4
+ include Auditable
5
+
6
+ attr_reader :number
7
+
8
+ def roll
9
+ numbers = [1, 1, 2, 5, 6, 6]
10
+ @number = numbers.sample
11
+ audit
12
+ @number
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ module StudioGame
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
+ health > 100
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,64 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'playable'
3
+
4
+ module StudioGame
5
+ class Player
6
+ include Playable
7
+ attr_reader :name
8
+ attr_accessor :found_treasures, :playable, :health
9
+
10
+ def name=(new_name)
11
+ @name = new_name.capitalize
12
+ end
13
+
14
+ def initialize(name, health = 100)
15
+ @name = name.capitalize
16
+ @health = health
17
+ @found_treasures = Hash.new(0)
18
+ end
19
+
20
+ def to_s
21
+ "I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}."
22
+ end
23
+
24
+ def score
25
+ @health + points
26
+ end
27
+
28
+
29
+ def <=>(other)
30
+ other.score <=> score
31
+ end
32
+
33
+ def found_treasure(treasure)
34
+ @found_treasures[treasure.name] += treasure.points
35
+ puts "#{@name} found a #{treasure.name} worth #{treasure.points}."
36
+ puts "#{@name}'s treasures: #{@found_treasures}"
37
+ end
38
+
39
+ def points
40
+ @found_treasures.values.reduce(0, :+)
41
+ end
42
+
43
+ def each_found_treasure
44
+ @found_treasures.each do |name, points|
45
+ yield Treasure.new(name, points)
46
+ end
47
+ end
48
+
49
+ def self.from_csv(string)
50
+ name, health = string.split(',')
51
+ Player.new(name, Integer(health))
52
+ end
53
+
54
+ end
55
+ end
56
+ if __FILE__ ==$0
57
+ player = Player.new("moe")
58
+ puts player.name
59
+ puts player.health
60
+ player.w00t
61
+ puts player.health
62
+ player.blam
63
+ puts player.health
64
+ end
@@ -0,0 +1,59 @@
1
+
2
+ module StudioGame
3
+ Treasure = Struct.new(:name, :points)
4
+
5
+ module TreasureTrove
6
+ def self.random
7
+ TREASURES.sample
8
+ end
9
+ TREASURES = [
10
+ Treasure.new(:pie, 5),
11
+ Treasure.new(:bottle, 25),
12
+ Treasure.new(:hammer, 50),
13
+ Treasure.new(:skillet, 100),
14
+ Treasure.new(:broomstick, 200),
15
+ Treasure.new(:crowbar, 400)]
16
+ end
17
+ end
18
+
19
+ # class Person
20
+ # def self.create_people(jobs)
21
+ # jobs.map do |job|
22
+ # new(job)
23
+ # end
24
+ # end
25
+
26
+ # def initialize(job)
27
+ # @job = job
28
+ # end
29
+ # end
30
+
31
+ # class Treasure
32
+ # def initialize(name, points)
33
+ # @name, @points = name, points
34
+ # end
35
+
36
+ # attr_accessor :name, :points
37
+ # end
38
+
39
+ # class Treasure < Struct.new(:name, :points)
40
+ # end
41
+
42
+ # class Parent
43
+ # def plays_sports
44
+ # true
45
+ # end
46
+ # end
47
+
48
+ # class Child < Parent
49
+ # def plays_sports
50
+ # if likes_playing_sports?
51
+ # super
52
+ # else
53
+ # false
54
+ # end
55
+ # end
56
+ # end
57
+
58
+ # Child.new.plays_sports
59
+ # #=> true
@@ -0,0 +1,29 @@
1
+ require 'studio_game/berserk_player'
2
+
3
+ module StudioGame
4
+ describe BerserkPlayer do
5
+
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
+ @player.berserk?.should be_true
20
+ end
21
+
22
+ it "gets w00ted instead of blammed when it goes berserk" do
23
+ 1.upto(6) { @player.w00t}
24
+ 1.upto(2) { @player.blam}
25
+
26
+ @player.health.should == @initial_health + (8 * 15)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,56 @@
1
+ require 'studio_game/clumsy_player'
2
+
3
+ module StudioGame
4
+ describe ClumsyPlayer do
5
+ before do
6
+ @player = ClumsyPlayer.new("klutz")
7
+ end
8
+
9
+ it "only gets half the point value for each treasure" do
10
+ @player.points.should == 0
11
+
12
+ hammer = Treasure.new(:hammer, 50)
13
+ @player.found_treasure(hammer)
14
+ @player.found_treasure(hammer)
15
+ @player.found_treasure(hammer)
16
+
17
+ @player.points.should == 75
18
+
19
+ crowbar = Treasure.new(:crowbar, 400)
20
+ @player.found_treasure(crowbar)
21
+
22
+ @player.points.should == 275
23
+
24
+ yielded = []
25
+ @player.each_found_treasure do |treasure|
26
+ yielded << treasure
27
+ end
28
+
29
+ yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
30
+ end
31
+
32
+ # context "with a boost factor" do
33
+ # before do
34
+ # @initial_health = 100
35
+ # @boost_factor = 10
36
+ # @player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
37
+ # end
38
+
39
+ # it "has a boost factor" do
40
+ # @player.boost_factor.should == 10
41
+ # end
42
+
43
+ # it "gets boost factor number of w00ts when w00ted" do
44
+ # @player.w00t
45
+ # @player.health.should == @initial_health + (15 * @boost_factor)
46
+ # end
47
+ # end
48
+
49
+ it "gets 25 points every time it is w00ted rather than the normal 10" do
50
+ @player.health.should == 100
51
+
52
+ @player.w00t
53
+ @player.health.should == 125
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,68 @@
1
+ require 'studio_game/game'
2
+
3
+ module StudioGame
4
+ describe Game do
5
+
6
+ before do
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 "has a title" do
16
+ @game.title.should == "Knuckleheads"
17
+ end
18
+
19
+ it "w00ts the player if a high number is rolled" do
20
+ Die.any_instance.stub(:roll).and_return(5)
21
+
22
+ @game.play(2)
23
+
24
+ @player.health.should == @initial_health + (15 * 2)
25
+ end
26
+
27
+ it "skips the player if a medium number is rolled" do
28
+ Die.any_instance.stub(:roll).and_return(4)
29
+ @game.play(2)
30
+ @player.health.should == @initial_health
31
+ end
32
+
33
+ it "blams a player if a low number is rolled" do
34
+ Die.any_instance.stub(:roll).and_return(1)
35
+ @game.play(2)
36
+ @player.health.should == @initial_health - (10 * 2)
37
+ end
38
+
39
+ it "assigns a treasure for points during a player's turn" do
40
+ game = Game.new("Knuckleheads")
41
+ player = Player.new("moe")
42
+
43
+ game.add_player(player)
44
+
45
+ game.play(1)
46
+
47
+ player.points.should_not be_zero
48
+
49
+ # or use alternate expectation syntax:
50
+ # expect(player.points).not_to be_zero
51
+ end
52
+ it "computes total points as the sum of all player points" do
53
+ game = Game.new("Knuckleheads")
54
+
55
+ player1 = Player.new("moe")
56
+ player2 = Player.new("larry")
57
+
58
+ game.add_player(player1)
59
+ game.add_player(player2)
60
+
61
+ player1.found_treasure(Treasure.new(:hammer, 50))
62
+ player1.found_treasure(Treasure.new(:hammer, 50))
63
+ player2.found_treasure(Treasure.new(:crowbar, 400))
64
+
65
+ game.total_points.should == 500
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,124 @@
1
+ require 'studio_game/player'
2
+ require 'studio_game/treasure_trove'
3
+
4
+ module StudioGame
5
+ describe Player do
6
+
7
+ before do
8
+ $stdout = StringIO.new
9
+ @initial_health = 150
10
+ @player = Player.new("larry", @initial_health)
11
+ end
12
+
13
+ it "has a capitalized name" do
14
+ @player.name.should == "Larry"
15
+
16
+ end
17
+
18
+ it "has an initial health" do
19
+ @player.health.should == 150
20
+ end
21
+
22
+ it "computes a score as the sum of its health and points" do
23
+ @player.found_treasure(Treasure.new(:hammer, 50))
24
+ @player.found_treasure(Treasure.new(:hammer, 50))
25
+
26
+ @player.score.should == 250
27
+ end
28
+ it "has a string representation" do
29
+ @player.found_treasure(Treasure.new(:hammer, 50))
30
+ @player.found_treasure(Treasure.new(:hammer, 50))
31
+ @player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250."
32
+ end
33
+
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
+ context "health over 100 should return strong" do
45
+ before do
46
+ @player = Player.new("larry", 150)
47
+ end
48
+
49
+ it "is strong" do
50
+ @player.should be_strong
51
+ end
52
+ end
53
+ context "health equal to or less than 100 should return false" do
54
+ before do
55
+ @player = Player.new("larry", 100)
56
+ end
57
+
58
+ it "is wimpy" do
59
+ @player.should_not be_strong
60
+ end
61
+ end
62
+
63
+ context "in a collection of players" do
64
+ before do
65
+ @player1 = Player.new("moe", 100)
66
+ @player2 = Player.new("larry", 200)
67
+ @player3 = Player.new("curly", 300)
68
+
69
+ @players = [@player1, @player2, @player3]
70
+ end
71
+
72
+ it "is sorted by decreasing score" do
73
+ @players.sort.should == [@player3, @player2, @player1]
74
+ end
75
+ end
76
+ it "computes points as the sum of all treasure points" do
77
+ @player.points.should == 0
78
+
79
+ @player.found_treasure(Treasure.new(:hammer, 50))
80
+
81
+ @player.points.should == 50
82
+
83
+ @player.found_treasure(Treasure.new(:crowbar, 400))
84
+
85
+ @player.points.should == 450
86
+
87
+ @player.found_treasure(Treasure.new(:hammer, 50))
88
+
89
+ @player.points.should == 500
90
+ end
91
+
92
+ it "yields each found treasure and its total points" do
93
+ @player.found_treasure(Treasure.new(:skillet, 100))
94
+ @player.found_treasure(Treasure.new(:skillet, 100))
95
+ @player.found_treasure(Treasure.new(:hammer, 50))
96
+ @player.found_treasure(Treasure.new(:bottle, 5))
97
+ @player.found_treasure(Treasure.new(:bottle, 5))
98
+ @player.found_treasure(Treasure.new(:bottle, 5))
99
+ @player.found_treasure(Treasure.new(:bottle, 5))
100
+ @player.found_treasure(Treasure.new(:bottle, 5))
101
+
102
+ yielded = []
103
+ @player.each_found_treasure do |treasure|
104
+ yielded << treasure
105
+ end
106
+
107
+ yielded.should == [
108
+ Treasure.new(:skillet, 200),
109
+ Treasure.new(:hammer, 50),
110
+ Treasure.new(:bottle, 25)
111
+ ]
112
+ end
113
+
114
+
115
+ it "can be created from a csv string" do
116
+ player = Player.from_csv("Larry,150")
117
+
118
+ player.name.should == "Larry"
119
+ player.health.should == 150
120
+ end
121
+ end
122
+ end
123
+
124
+
@@ -0,0 +1,56 @@
1
+ require 'studio_game/treasure_trove'
2
+
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
+
53
+ TreasureTrove::TREASURES.should include(treasure)
54
+ end
55
+ end
56
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gameology
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Wortham
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-19 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 program is a simple game in which the players each take turns
28
+ rolling a virtual die. The scores and healths of the players are determined based
29
+ on the roll of the die and which treasures they find. Each player keeps collecting
30
+ treasures each round and can either gain or lose points based on the roll of the
31
+ die. When you decide the game is over the stats are all listed out at the bottom. '
32
+ email: awortham@newlifechurch.tv
33
+ executables:
34
+ - studio_game
35
+ extensions: []
36
+ extra_rdoc_files: []
37
+ files:
38
+ - bin/high_scores.txt
39
+ - bin/players.csv
40
+ - bin/studio_game
41
+ - bin/studio_game.simple form
42
+ - lib/studio_game/auditable.rb
43
+ - lib/studio_game/berserk_player.rb
44
+ - lib/studio_game/clumsy_player.rb
45
+ - lib/studio_game/die.rb
46
+ - lib/studio_game/game.rb
47
+ - lib/studio_game/game_turn.rb
48
+ - lib/studio_game/loaded_die.rb
49
+ - lib/studio_game/playable.rb
50
+ - lib/studio_game/player.rb
51
+ - lib/studio_game/treasure_trove.rb
52
+ - spec/studio_game/berserk_player_spec.rb
53
+ - spec/studio_game/clumsy_player_spec.rb
54
+ - spec/studio_game/game_spec.rb
55
+ - spec/studio_game/player_spec.rb
56
+ - spec/studio_game/treasure_trove_spec.rb
57
+ - LICENSE
58
+ - README
59
+ homepage:
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '1.9'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.1.11
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Play this awesome game with dice
83
+ test_files:
84
+ - spec/studio_game/berserk_player_spec.rb
85
+ - spec/studio_game/clumsy_player_spec.rb
86
+ - spec/studio_game/game_spec.rb
87
+ - spec/studio_game/player_spec.rb
88
+ - spec/studio_game/treasure_trove_spec.rb
89
+ has_rdoc: