aamax.amazing_game 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +7 -0
- data/README +1 -0
- data/bin/game_results.txt +68 -0
- data/bin/players.csv +4 -0
- data/bin/studio_game +46 -0
- data/lib/game/auditable.rb +5 -0
- data/lib/game/berserk.rb +28 -0
- data/lib/game/die.rb +18 -0
- data/lib/game/game.rb +126 -0
- data/lib/game/game_turn.rb +24 -0
- data/lib/game/klutz.rb +10 -0
- data/lib/game/loaded_die.rb +16 -0
- data/lib/game/playable.rb +21 -0
- data/lib/game/player.rb +53 -0
- data/lib/game/treasures.rb +18 -0
- data/spec/game/berserk_spec.rb +16 -0
- data/spec/game/game_spec.rb +71 -0
- data/spec/game/klutz_spec.rb +12 -0
- data/spec/game/player_spec.rb +103 -0
- data/spec/game/treasures_spec.rb +56 -0
- metadata +81 -0
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (C) 2012 Allen Maxwell
|
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
|
+
game app built from pragmatic studio ruby course... nothing special here.
|
@@ -0,0 +1,68 @@
|
|
1
|
+
|
2
|
+
Scores:
|
3
|
+
|
4
|
+
|
5
|
+
Player: Berserker...........
|
6
|
+
Itemization:
|
7
|
+
hammer.........500
|
8
|
+
skillet........1600
|
9
|
+
crowbar........8400
|
10
|
+
bottle.........375
|
11
|
+
pie............75
|
12
|
+
broomstick.....4200
|
13
|
+
Total:......15150
|
14
|
+
|
15
|
+
|
16
|
+
Player: Danny...............
|
17
|
+
Itemization:
|
18
|
+
hammer.........750
|
19
|
+
broomstick.....4400
|
20
|
+
bottle.........425
|
21
|
+
pie............70
|
22
|
+
crowbar........8000
|
23
|
+
skillet........1000
|
24
|
+
Total:......14645
|
25
|
+
|
26
|
+
|
27
|
+
Player: Cathy...............
|
28
|
+
Itemization:
|
29
|
+
hammer.........1000
|
30
|
+
bottle.........400
|
31
|
+
skillet........2500
|
32
|
+
crowbar........7200
|
33
|
+
broomstick.....2400
|
34
|
+
pie............35
|
35
|
+
Total:......13535
|
36
|
+
|
37
|
+
|
38
|
+
Player: Caitlin.............
|
39
|
+
Itemization:
|
40
|
+
hammer.........850
|
41
|
+
broomstick.....3400
|
42
|
+
bottle.........400
|
43
|
+
pie............85
|
44
|
+
crowbar........5600
|
45
|
+
skillet........1700
|
46
|
+
Total:......12035
|
47
|
+
|
48
|
+
|
49
|
+
Player: Allen...............
|
50
|
+
Itemization:
|
51
|
+
bottle.........600
|
52
|
+
hammer.........750
|
53
|
+
skillet........1200
|
54
|
+
pie............120
|
55
|
+
crowbar........4000
|
56
|
+
broomstick.....2600
|
57
|
+
Total:......9270
|
58
|
+
|
59
|
+
|
60
|
+
Player: Klutz...............
|
61
|
+
Itemization:
|
62
|
+
bottle.........276
|
63
|
+
hammer.........350
|
64
|
+
pie............36
|
65
|
+
broomstick.....1500
|
66
|
+
crowbar........3000
|
67
|
+
skillet........650
|
68
|
+
Total:......5812
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require_relative '../lib/game/game'
|
3
|
+
|
4
|
+
fname = ARGV[0] if ARGV.length > 0
|
5
|
+
|
6
|
+
puts "What's the name for your game?"
|
7
|
+
name = STDIN.gets.chomp
|
8
|
+
|
9
|
+
puts "We are beginning the game called '#{name}'\n-------------------------------------"
|
10
|
+
|
11
|
+
game = StudioGame::Game.new(name)
|
12
|
+
game.show_available_treasures
|
13
|
+
puts ""
|
14
|
+
|
15
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
16
|
+
|
17
|
+
game.load(ARGV[0] || default_player_file)
|
18
|
+
|
19
|
+
klutz = StudioGame::Klutz.new("klutz", 105)
|
20
|
+
game.add_player(klutz)
|
21
|
+
|
22
|
+
berserker = StudioGame::Berserk.new("berserker", 50)
|
23
|
+
game.add_player(berserker)
|
24
|
+
puts game
|
25
|
+
puts ""
|
26
|
+
|
27
|
+
game.play do
|
28
|
+
game.get_all_item_points >= 70000
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "\n\n----------------\n"
|
32
|
+
|
33
|
+
puts game
|
34
|
+
puts"\n\n"
|
35
|
+
|
36
|
+
game.print_stats
|
37
|
+
puts"\n\n"
|
38
|
+
|
39
|
+
puts "#{game.name} game scores:"
|
40
|
+
game_results = game.players.sort
|
41
|
+
game_results.each do |p|
|
42
|
+
formatted_name = p.name.ljust(20, '.')
|
43
|
+
puts formatted_name + p.score.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
game.output_results
|
data/lib/game/berserk.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class Berserk < Player
|
5
|
+
def initialize(name, health)
|
6
|
+
@woot_count = 0
|
7
|
+
super(name, health)
|
8
|
+
end
|
9
|
+
|
10
|
+
def w00t
|
11
|
+
@woot_count += 1
|
12
|
+
super
|
13
|
+
puts "#{@name} is berserk!" if berserk?
|
14
|
+
end
|
15
|
+
|
16
|
+
def blam
|
17
|
+
if berserk?
|
18
|
+
w00t
|
19
|
+
else
|
20
|
+
super
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def berserk?
|
25
|
+
@woot_count >= 5
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/game/die.rb
ADDED
data/lib/game/game.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'klutz'
|
3
|
+
require_relative 'berserk'
|
4
|
+
require_relative 'game_turn'
|
5
|
+
require_relative 'treasures'
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
module StudioGame
|
9
|
+
class Game
|
10
|
+
attr_reader :players, :name
|
11
|
+
|
12
|
+
def initialize(name)
|
13
|
+
@name = name
|
14
|
+
@players = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def load(fname)
|
18
|
+
file = File.open(fname)
|
19
|
+
CSV.foreach(fname) do |row|
|
20
|
+
@players << Player.from_csv(row)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def add_player(player)
|
25
|
+
@players << player
|
26
|
+
puts "#{player.name} was added."
|
27
|
+
end
|
28
|
+
|
29
|
+
def number_of_players
|
30
|
+
@players.length
|
31
|
+
end
|
32
|
+
|
33
|
+
def kill_player(name)
|
34
|
+
count = @players.length
|
35
|
+
@players.delete_if { |p| p.name.downcase == name.downcase }
|
36
|
+
puts @players.length < count ? "#{name} was killed" : "no player was killed..."
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
ret_str = "Game Name: #{@name}\n"
|
41
|
+
@players.each do |p|
|
42
|
+
ret_str += "#{p}\n"
|
43
|
+
end
|
44
|
+
ret_str
|
45
|
+
end
|
46
|
+
|
47
|
+
def print_stats
|
48
|
+
strong, wimpy = @players.sort.partition { |p| p.strong? }
|
49
|
+
puts "Strong Players:"
|
50
|
+
strong.each do |s|
|
51
|
+
puts s
|
52
|
+
end
|
53
|
+
|
54
|
+
puts "Wimpy Players:"
|
55
|
+
wimpy.each do |s|
|
56
|
+
puts s
|
57
|
+
end
|
58
|
+
|
59
|
+
puts "\n\nTotal Value of Items Found: #{get_all_item_points}"
|
60
|
+
|
61
|
+
output_scores(STDOUT)
|
62
|
+
""
|
63
|
+
end
|
64
|
+
|
65
|
+
def output_scores(out_stream)
|
66
|
+
out_stream.puts "\nScores:"
|
67
|
+
@players.sort.each do |p|
|
68
|
+
plyr = p.name.ljust(20, '.')
|
69
|
+
out_stream.puts "\n\nPlayer: #{plyr}"
|
70
|
+
out_stream.puts " Itemization:\n"
|
71
|
+
p.items do |i|
|
72
|
+
out_stream.puts " #{i[:name]}".ljust(20, '.') + "#{i[:value]}"
|
73
|
+
end
|
74
|
+
out_stream.puts " Total:".ljust(20, '.') + "#{p.item_values}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def output_results
|
79
|
+
File.open("game_results.txt", "w") do |aFile|
|
80
|
+
output_scores(aFile)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def show_available_treasures
|
85
|
+
puts "\nThere are #{TreasureTrove::TREASURES.size} treasures to be found in the game."
|
86
|
+
TreasureTrove::TREASURES.each do |t|
|
87
|
+
puts " #{t.name} is worth #{t.value} points."
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def get_all_item_points
|
92
|
+
@players.reduce(0) do |sum, plyr|
|
93
|
+
sum + plyr.item_values
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def play(rounds=-1)
|
98
|
+
puts "\nThere are #{@players.length} in #{@name}"
|
99
|
+
puts @players
|
100
|
+
puts ""
|
101
|
+
round = 0
|
102
|
+
loop do
|
103
|
+
round += 1
|
104
|
+
if rounds == -1
|
105
|
+
if yield
|
106
|
+
puts "GAME OVER!!!!! points max reached..."
|
107
|
+
break
|
108
|
+
end
|
109
|
+
else
|
110
|
+
if (round > rounds)
|
111
|
+
puts "GAME OVER - rounds count met..."
|
112
|
+
break
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
puts "\nRound: #{round}"
|
117
|
+
@players.each do |p|
|
118
|
+
GameTurn.take_turn(p)
|
119
|
+
puts p
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'player'
|
3
|
+
require_relative 'treasures'
|
4
|
+
|
5
|
+
module GameTurn
|
6
|
+
def self.roll
|
7
|
+
die = StudioGame::Die.new
|
8
|
+
die.roll
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.take_turn(player)
|
12
|
+
case roll
|
13
|
+
when 1..2
|
14
|
+
player.blam
|
15
|
+
when 3
|
16
|
+
# nop
|
17
|
+
else
|
18
|
+
player.w00t
|
19
|
+
end
|
20
|
+
item = StudioGame::TreasureTrove.get_treasure
|
21
|
+
player.found_item(item)
|
22
|
+
puts "#{player.name} found a #{item.name} worth #{item.value} points!"
|
23
|
+
end
|
24
|
+
end
|
data/lib/game/klutz.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
module StudioGame
|
2
|
+
module Playable
|
3
|
+
def w00t
|
4
|
+
self.health += 15
|
5
|
+
puts "#{name} got w00ted!"
|
6
|
+
end
|
7
|
+
|
8
|
+
def blam
|
9
|
+
self.health -= 10
|
10
|
+
puts "#{name} got blammed!"
|
11
|
+
end
|
12
|
+
|
13
|
+
def strong?
|
14
|
+
health > 100
|
15
|
+
end
|
16
|
+
|
17
|
+
def weak?
|
18
|
+
health <= 100
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/game/player.rb
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
require_relative 'treasures'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
attr_accessor :name, :health
|
7
|
+
|
8
|
+
include Playable
|
9
|
+
|
10
|
+
def initialize(name, health=100)
|
11
|
+
@name = name.capitalize
|
12
|
+
@health = health
|
13
|
+
@riches = Hash.new(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
def found_item(item)
|
17
|
+
@riches[item.name] += item.value
|
18
|
+
end
|
19
|
+
|
20
|
+
def found_treasure(item)
|
21
|
+
found_item(item)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.from_csv(row)
|
25
|
+
name = row[0]
|
26
|
+
health = row[1]
|
27
|
+
new(name, Integer(health))
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"My name is #{@name} with health of #{@health} and a score of #{score}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def item_values
|
35
|
+
@riches.values.reduce(0, :+)
|
36
|
+
end
|
37
|
+
|
38
|
+
def score
|
39
|
+
@health + item_values
|
40
|
+
end
|
41
|
+
|
42
|
+
def <=>(a_player)
|
43
|
+
a_player.score <=> self.score
|
44
|
+
end
|
45
|
+
|
46
|
+
def items
|
47
|
+
@riches.each do |name, value|
|
48
|
+
treasure = Treasure.new(name, value)
|
49
|
+
yield treasure
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module StudioGame
|
2
|
+
Treasure = Struct.new(:name, :value)
|
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.get_treasure
|
15
|
+
TREASURES.sample
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'game/berserk'
|
2
|
+
|
3
|
+
describe StudioGame::Berserk do
|
4
|
+
before (:each) do
|
5
|
+
@berserk = StudioGame::Berserk.new("allen", 100)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should woot instead of blam after 5 woots" do
|
9
|
+
val = 100 + (15 * 5)
|
10
|
+
5.times { @berserk.w00t }
|
11
|
+
@berserk.score.should == val
|
12
|
+
|
13
|
+
@berserk.blam
|
14
|
+
@berserk.score.should == val + 15
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'game/game'
|
2
|
+
require 'game/die'
|
3
|
+
require 'game/game_turn'
|
4
|
+
|
5
|
+
describe StudioGame::Game do
|
6
|
+
before do
|
7
|
+
@game = StudioGame::Game.new("Knuckleheads")
|
8
|
+
|
9
|
+
@initial_health = 100
|
10
|
+
@player = StudioGame::Player.new("moe", @initial_health)
|
11
|
+
|
12
|
+
@game.add_player(@player)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should w00t when a high number is rolled" do
|
16
|
+
GameTurn.stub(:roll).and_return(5)
|
17
|
+
@game.play(3)
|
18
|
+
@player.health.should == @initial_health + (15 * 3)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
it "should blam when a low number is rolled" do
|
23
|
+
GameTurn.stub(:roll).and_return(2)
|
24
|
+
@game.play(3)
|
25
|
+
@player.health.should == @initial_health - (10 * 3)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should not do anything when a 3 is rolled" do
|
29
|
+
GameTurn.stub(:roll).and_return(3)
|
30
|
+
@game.play(3)
|
31
|
+
@player.health.should == @initial_health
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should kill a player" do
|
35
|
+
@game.kill_player(@player.name)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should add a player" do
|
39
|
+
count = @game.players.length
|
40
|
+
@game.add_player(StudioGame::Player.new("new"))
|
41
|
+
new_count = @game.players.length
|
42
|
+
new_count.should == count + 1
|
43
|
+
end
|
44
|
+
|
45
|
+
it "assigns a treasure for points during a player's turn" do
|
46
|
+
game = StudioGame::Game.new("Knuckleheads")
|
47
|
+
player = StudioGame::Player.new("moe")
|
48
|
+
|
49
|
+
game.add_player(player)
|
50
|
+
|
51
|
+
game.play(1)
|
52
|
+
|
53
|
+
player.item_values.should_not be_zero
|
54
|
+
end
|
55
|
+
|
56
|
+
it "computes total points as the sum of all player points" do
|
57
|
+
game = StudioGame::Game.new("Knuckleheads")
|
58
|
+
|
59
|
+
player1 = StudioGame::Player.new("moe")
|
60
|
+
player2 = StudioGame::Player.new("larry")
|
61
|
+
|
62
|
+
game.add_player(player1)
|
63
|
+
game.add_player(player2)
|
64
|
+
|
65
|
+
player1.found_item(StudioGame::Treasure.new(:hammer, 50))
|
66
|
+
player1.found_item(StudioGame::Treasure.new(:hammer, 50))
|
67
|
+
player2.found_item(StudioGame::Treasure.new(:crowbar, 400))
|
68
|
+
|
69
|
+
game.get_all_item_points.should == 500
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'game/klutz'
|
2
|
+
|
3
|
+
describe StudioGame::Klutz do
|
4
|
+
before (:each) do
|
5
|
+
@klutz = StudioGame::Klutz.new("allen", 100)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should cut value of items in half when found by klutz" do
|
9
|
+
@klutz.found_treasure(StudioGame::Treasure.new(:skillet, 100))
|
10
|
+
@klutz.item_values.should == 50
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require 'game/player'
|
2
|
+
|
3
|
+
describe StudioGame::Player do
|
4
|
+
before (:each) do
|
5
|
+
@player = StudioGame::Player.new("allen", 100)
|
6
|
+
end
|
7
|
+
|
8
|
+
it "computes a score as the sum of its health and points" do
|
9
|
+
@player.found_item(StudioGame::Treasure.new(:hammer, 50))
|
10
|
+
@player.found_item(StudioGame::Treasure.new(:hammer, 50))
|
11
|
+
|
12
|
+
@player.score.should == 200
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should have a capitalized name" do
|
16
|
+
@player.name.should == "Allen"
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should have the correct health value" do
|
20
|
+
@player.health.should == 100
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should have a string representation" do
|
24
|
+
@player.to_s.should == "My name is #{@player.name} with health of #{@player.health} and a score of #{@player.score}"
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should increase score by 15 when w00ted" do
|
28
|
+
score = @player.score
|
29
|
+
@player.w00t
|
30
|
+
@player.score.should == score + 15
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should decrease score by 10 when blammed" do
|
34
|
+
score = @player.score
|
35
|
+
@player.blam
|
36
|
+
@player.score.should == score - 10
|
37
|
+
end
|
38
|
+
|
39
|
+
it "yields each found treasure and its total points" do
|
40
|
+
@player.found_treasure(StudioGame::Treasure.new(:skillet, 100))
|
41
|
+
@player.found_treasure(StudioGame::Treasure.new(:skillet, 100))
|
42
|
+
@player.found_treasure(StudioGame::Treasure.new(:hammer, 50))
|
43
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
44
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
45
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
46
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
47
|
+
@player.found_treasure(StudioGame::Treasure.new(:bottle, 5))
|
48
|
+
|
49
|
+
yielded = []
|
50
|
+
@player.items do |treasure|
|
51
|
+
yielded << treasure
|
52
|
+
end
|
53
|
+
|
54
|
+
yielded.should == [
|
55
|
+
StudioGame::Treasure.new(:skillet, 200),
|
56
|
+
StudioGame::Treasure.new(:hammer, 50),
|
57
|
+
StudioGame::Treasure.new(:bottle, 25)
|
58
|
+
]
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should create a player from csv entry" do
|
62
|
+
csv_str = ["Max",50]
|
63
|
+
p = StudioGame::Player.from_csv(csv_str)
|
64
|
+
p.name.should == "Max"
|
65
|
+
p.score.should == 50
|
66
|
+
end
|
67
|
+
|
68
|
+
context "is strong" do
|
69
|
+
before :each do
|
70
|
+
@strong_player = StudioGame::Player.new('Max', 150)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "is strong" do
|
74
|
+
@strong_player.should be_strong
|
75
|
+
@strong_player.should_not be_weak
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
context "is weak" do
|
80
|
+
before :each do
|
81
|
+
@weak_player = StudioGame::Player.new('Parker', 50)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "is weak" do
|
85
|
+
@weak_player.should be_weak
|
86
|
+
@weak_player.should_not be_strong
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context "in a collection of players" do
|
91
|
+
before do
|
92
|
+
@player1 = StudioGame::Player.new("moe", 100)
|
93
|
+
@player2 = StudioGame::Player.new("larry", 200)
|
94
|
+
@player3 = StudioGame::Player.new("curly", 300)
|
95
|
+
|
96
|
+
@players = [@player1, @player2, @player3]
|
97
|
+
end
|
98
|
+
|
99
|
+
it "is sorted by decreasing score" do
|
100
|
+
@players.sort.should == [@player3, @player2, @player1]
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'game/treasures'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe StudioGame::Treasure do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@treasure = StudioGame::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.value.should == 50
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe StudioGame::TreasureTrove do
|
21
|
+
|
22
|
+
it "has six treasures" do
|
23
|
+
StudioGame::TreasureTrove::TREASURES.size.should == 6
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a pie worth 5 points" do
|
27
|
+
StudioGame::TreasureTrove::TREASURES[0].should == StudioGame::Treasure.new(:pie, 5)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a bottle worth 25 points" do
|
31
|
+
StudioGame::TreasureTrove::TREASURES[1].should == StudioGame::Treasure.new(:bottle, 25)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a hammer worth 50 points" do
|
35
|
+
StudioGame::TreasureTrove::TREASURES[2].should == StudioGame::Treasure.new(:hammer, 50)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a skillet worth 100 points" do
|
39
|
+
StudioGame::TreasureTrove::TREASURES[3].should == StudioGame::Treasure.new(:skillet, 100)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a broomstick worth 200 points" do
|
43
|
+
StudioGame::TreasureTrove::TREASURES[4].should == StudioGame::Treasure.new(:broomstick, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a crowbar worth 400 points" do
|
47
|
+
StudioGame::TreasureTrove::TREASURES[5].should == StudioGame::Treasure.new(:crowbar, 400)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a random treasure" do
|
51
|
+
treasure = StudioGame::TreasureTrove.get_treasure
|
52
|
+
|
53
|
+
StudioGame::TreasureTrove::TREASURES.should include(treasure)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aamax.amazing_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Allen Maxwell
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-27 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70315837688860 !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: *70315837688860
|
25
|
+
description: game app built from pragmatic studio ruby course... nothing special here.
|
26
|
+
email: amaxwell@empowerit.com
|
27
|
+
executables:
|
28
|
+
- studio_game
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- bin/game_results.txt
|
33
|
+
- bin/players.csv
|
34
|
+
- bin/studio_game
|
35
|
+
- lib/game/auditable.rb
|
36
|
+
- lib/game/berserk.rb
|
37
|
+
- lib/game/die.rb
|
38
|
+
- lib/game/game.rb
|
39
|
+
- lib/game/game_turn.rb
|
40
|
+
- lib/game/klutz.rb
|
41
|
+
- lib/game/loaded_die.rb
|
42
|
+
- lib/game/playable.rb
|
43
|
+
- lib/game/player.rb
|
44
|
+
- lib/game/treasures.rb
|
45
|
+
- spec/game/berserk_spec.rb
|
46
|
+
- spec/game/game_spec.rb
|
47
|
+
- spec/game/klutz_spec.rb
|
48
|
+
- spec/game/player_spec.rb
|
49
|
+
- spec/game/treasures_spec.rb
|
50
|
+
- LICENSE
|
51
|
+
- README
|
52
|
+
homepage: http://maxwellhoffmanfamily.com
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.9'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project:
|
72
|
+
rubygems_version: 1.8.15
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: tutorial results for game building in ruby.
|
76
|
+
test_files:
|
77
|
+
- spec/game/berserk_spec.rb
|
78
|
+
- spec/game/game_spec.rb
|
79
|
+
- spec/game/klutz_spec.rb
|
80
|
+
- spec/game/player_spec.rb
|
81
|
+
- spec/game/treasures_spec.rb
|