code_dudes_ruby_game 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +14 -0
- data/README +7 -0
- data/bin/code_dudes_ruby_game +25 -0
- data/bin/players.csv +4 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserker_player.rb +37 -0
- data/lib/studio_game/clumsy.rb +29 -0
- data/lib/studio_game/die.rb +15 -0
- data/lib/studio_game/game.rb +101 -0
- data/lib/studio_game/gameturn.rb +26 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +19 -0
- data/lib/studio_game/player.rb +62 -0
- data/lib/studio_game/treasure_trove.rb +19 -0
- data/spec/studio_game/berserk_player_spec.rb +31 -0
- data/spec/studio_game/clumsy_player_spec.rb +33 -0
- data/spec/studio_game/game_spec.rb +80 -0
- data/spec/studio_game/player_spec.rb +74 -0
- data/spec/studio_game/treasure_trove_spec.rb +56 -0
- metadata +89 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 953fd87019d3332cda2e31b97c9005420c7411b6
|
|
4
|
+
data.tar.gz: 5d63ab6fbb89b63c4e3a6701c3492a72dac422a9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 763f5551b9a86744a9ccf4b283e31043183bbc8f694ff98b49e603de2591a5fd7f82d530ea414df1f549b57841b40ab41b4069a18125be04fcb56644585cc28b
|
|
7
|
+
data.tar.gz: 4d12edc989e812fc30b8b3428551fd33b7d7991a30f00a9dbcdfb1459c78de2e0edb141deb662072fedf4410ffcf0c3c33ba02c93a8ae48983afe9132f92d9a7
|
data/LICENSE
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
4
|
+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
|
|
5
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
6
|
+
persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
7
|
+
|
|
8
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
|
|
9
|
+
Software.
|
|
10
|
+
|
|
11
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
|
|
12
|
+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
13
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
14
|
+
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,7 @@
|
|
|
1
|
+
Application built while going through "Pragmatic Studios: Ruby Course"
|
|
2
|
+
|
|
3
|
+
Plays a game by loading in players "name,health" format where 'name' is a string and health is an integer
|
|
4
|
+
|
|
5
|
+
You can manually construct a .csv file with players and pass it in as a command line argument.
|
|
6
|
+
|
|
7
|
+
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/game'
|
|
4
|
+
require_relative '../lib/studio_game/clumsy'
|
|
5
|
+
require_relative '../lib/studio_game/berserker_player'
|
|
6
|
+
|
|
7
|
+
game = StudioGame::Game.new("knuckleheads")
|
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
|
9
|
+
game.load_players(ARGV.shift || default_player_file)
|
|
10
|
+
|
|
11
|
+
loop do
|
|
12
|
+
puts "How many rounds? 'quit' to exit: "
|
|
13
|
+
answer = gets.chomp.downcase
|
|
14
|
+
case answer
|
|
15
|
+
when 'quit', 'exit'
|
|
16
|
+
game.print_stats
|
|
17
|
+
break
|
|
18
|
+
when /^\d+$/
|
|
19
|
+
game.play(answer.to_i)
|
|
20
|
+
else
|
|
21
|
+
"Please enter a number or 'quit'"
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
game.save_high_scores
|
data/bin/players.csv
ADDED
|
@@ -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
|
+
@total_times_w00ted = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def w00t
|
|
13
|
+
@total_times_w00ted += 1
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def blam
|
|
18
|
+
case berserk?
|
|
19
|
+
when true
|
|
20
|
+
w00t
|
|
21
|
+
puts "#{@name} is berserk!"
|
|
22
|
+
else
|
|
23
|
+
super
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def berserk?
|
|
28
|
+
@total_times_w00ted > 5
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if __FILE__ == $0
|
|
33
|
+
berserker = BerserkPlayer.new('ares',125)
|
|
34
|
+
1.upto(6) { berserker.w00t }
|
|
35
|
+
berserker.blam
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
|
|
6
|
+
def found_treasure(treasure)
|
|
7
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2)
|
|
8
|
+
super(damaged_treasure)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
if __FILE__ == $0
|
|
14
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
15
|
+
|
|
16
|
+
hammer = Treasure.new(:hammer, 50)
|
|
17
|
+
clumsy.found_treasure(hammer)
|
|
18
|
+
clumsy.found_treasure(hammer)
|
|
19
|
+
clumsy.found_treasure(hammer)
|
|
20
|
+
|
|
21
|
+
crowbar = Treasure.new(:crowbar, 400)
|
|
22
|
+
clumsy.found_treasure(crowbar)
|
|
23
|
+
|
|
24
|
+
clumsy.get_total_treasures do |treasure|
|
|
25
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
26
|
+
end
|
|
27
|
+
puts "#{clumsy.points} grand total points"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'gameturn'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
class Game
|
|
8
|
+
|
|
9
|
+
def initialize(title)
|
|
10
|
+
@title = title.capitalize
|
|
11
|
+
@players = []
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def add_player(player)
|
|
15
|
+
@players << player
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def play(round_number)
|
|
19
|
+
puts "#{@title}: #{@players.length} players in this game.\n"
|
|
20
|
+
treasures = TreasureTrove::TREASURES
|
|
21
|
+
puts "There are #{treasures.length} treasures to be found:"
|
|
22
|
+
treasures.each { | treasure | puts "A #{treasure.name} is worth #{treasure.points}"}
|
|
23
|
+
1.upto(round_number) do |number|
|
|
24
|
+
puts "\nGame round:#{number}"
|
|
25
|
+
@players.each { |player| GameTurn.take_turn(player) }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def partition_players
|
|
30
|
+
@strong, @wimpy = @players.partition { |player| player.strong? }
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def get_total_treasures
|
|
34
|
+
@players.each do |player|
|
|
35
|
+
puts "\n#{player.name} found:"
|
|
36
|
+
player.found_treasures.each do |key, value|
|
|
37
|
+
puts "-\tTotal #{key} points: #{value}"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def load_players(filename='players.csv')
|
|
43
|
+
File.readlines(filename).each do | line |
|
|
44
|
+
# name, health = line.split(",")
|
|
45
|
+
# add_player(Player.new(name, Integer(health)))
|
|
46
|
+
add_player(Player.player_csv(line))
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def save_high_scores(filename='recent_high_scores.txt')
|
|
51
|
+
File.open(filename, 'w') do |file|
|
|
52
|
+
@players.sort.each do |player|
|
|
53
|
+
file.puts player.format_name
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def grand_total
|
|
59
|
+
puts "\n#{@title} Grand Total:"
|
|
60
|
+
total = 0
|
|
61
|
+
@players.each { |player| total += player.points}
|
|
62
|
+
puts "#{total}"
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def high_scores
|
|
66
|
+
puts "\n#{@title} Scores:\n"
|
|
67
|
+
@players.sort.each { |player| puts "#{player.name.ljust(30,'.')}#{player.points}"}
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
def print_stats
|
|
71
|
+
puts "\n#{@title} game stats:"
|
|
72
|
+
partition_players
|
|
73
|
+
|
|
74
|
+
# Prints points by treasure
|
|
75
|
+
puts "\nPoints by treasure type:"
|
|
76
|
+
# get_total_treasures
|
|
77
|
+
|
|
78
|
+
# Uncomment to use custom iterator in the Player class 'get_total_treasures'
|
|
79
|
+
@players.sort.each do |player|
|
|
80
|
+
puts "\n#{@title}'s treasure totals:"
|
|
81
|
+
player.get_total_treasures do |treasure|
|
|
82
|
+
puts "#{treasure.points} total #{treasure.name}"
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Prints strong players
|
|
87
|
+
puts "\n#{@strong.length} strong players:\n"
|
|
88
|
+
@strong.each { |player| puts player.format_name }
|
|
89
|
+
|
|
90
|
+
# Prints wimpy players
|
|
91
|
+
puts "\n#{@wimpy.length} weak players:\n"
|
|
92
|
+
@wimpy.each { |player| puts player.format_name }
|
|
93
|
+
|
|
94
|
+
# Prints High Scores
|
|
95
|
+
high_scores
|
|
96
|
+
|
|
97
|
+
# Prints Grand total
|
|
98
|
+
grand_total
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require_relative 'die'
|
|
2
|
+
require_relative 'player'
|
|
3
|
+
require_relative 'treasure_trove'
|
|
4
|
+
require_relative 'loaded_die'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
module GameTurn
|
|
8
|
+
|
|
9
|
+
def self.take_turn(player)
|
|
10
|
+
die = Die.new
|
|
11
|
+
case die.roll
|
|
12
|
+
when 1..2
|
|
13
|
+
player.blam
|
|
14
|
+
when 3..4
|
|
15
|
+
puts "#{player.name} got skipped!"
|
|
16
|
+
when 5..6
|
|
17
|
+
player.w00t
|
|
18
|
+
else
|
|
19
|
+
puts 'No roll'
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
treasure = TreasureTrove.random
|
|
23
|
+
player.found_treasure(treasure)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
module Playable
|
|
3
|
+
def w00t
|
|
4
|
+
# Adds 15 health to a player
|
|
5
|
+
self.health += 15
|
|
6
|
+
puts "#{name} got w00ted!"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def blam
|
|
10
|
+
# Removes 10 health from a player
|
|
11
|
+
self.health -= 10
|
|
12
|
+
puts "#{name} got blammed!"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def strong?
|
|
16
|
+
self.health >= 100
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
require_relative 'game'
|
|
3
|
+
require_relative 'playable'
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
class Player
|
|
7
|
+
include Playable
|
|
8
|
+
|
|
9
|
+
# Class for player generation
|
|
10
|
+
attr_accessor :name, :found_treasures, :health
|
|
11
|
+
|
|
12
|
+
def initialize(name, health=100)
|
|
13
|
+
# Initialize player obj with name and health value
|
|
14
|
+
@name = name.capitalize
|
|
15
|
+
@health = health
|
|
16
|
+
@found_treasures = Hash.new(0)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
# Prints simple greeting message
|
|
21
|
+
"I'm #{@name} with a health of #{@health} and a score of #{points}."
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def <=>(other)
|
|
25
|
+
other.points <=> points
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def found_treasure(treasure)
|
|
29
|
+
@found_treasures[treasure.name] += treasure.points
|
|
30
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points}"
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def points
|
|
34
|
+
@found_treasures.values.reduce(0, :+)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.player_csv(string)
|
|
38
|
+
name, health = string.split(",")
|
|
39
|
+
Player.new(name,Integer(health))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def format_name()
|
|
43
|
+
"#{@name},#{points}"
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def get_total_treasures
|
|
47
|
+
@found_treasures.each do |name, points|
|
|
48
|
+
treasure = Treasure.new(name, points)
|
|
49
|
+
yield treasure
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
if __FILE__ == $0
|
|
56
|
+
player1 = Player.new("scott",80)
|
|
57
|
+
player1.blam
|
|
58
|
+
player1.w00t
|
|
59
|
+
puts player1
|
|
60
|
+
player1.score
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
require 'studio_game/berserker_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
|
+
|
|
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
|
+
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require 'studio_game/clumsy'
|
|
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.get_total_treasures do |treasure|
|
|
26
|
+
yielded << treasure
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
require 'studio_game/game'
|
|
2
|
+
require 'studio_game/die'
|
|
3
|
+
require 'studio_game/gameturn'
|
|
4
|
+
require 'studio_game/treasure_trove'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
describe Game do
|
|
8
|
+
|
|
9
|
+
before do
|
|
10
|
+
$stdout = StringIO.new
|
|
11
|
+
@game = Game.new("Knuckleheads")
|
|
12
|
+
|
|
13
|
+
@initial_health = 100
|
|
14
|
+
@player = Player.new("moe", @initial_health)
|
|
15
|
+
|
|
16
|
+
@game.add_player(@player)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "it 'w00t's a player when a high number is rolled " do
|
|
20
|
+
Die.any_instance.stub(:roll).and_return(5)
|
|
21
|
+
|
|
22
|
+
@game.play(1)
|
|
23
|
+
|
|
24
|
+
@player.health.should == @initial_health + 15
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "it does nothing when a medium number is rolled " do
|
|
29
|
+
Die.any_instance.stub(:roll).and_return(3)
|
|
30
|
+
|
|
31
|
+
@game.play(1)
|
|
32
|
+
|
|
33
|
+
@player.health.should == @initial_health
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "it 'blam's a player when a low number is rolled " do
|
|
37
|
+
Die.any_instance.stub(:roll).and_return(1)
|
|
38
|
+
|
|
39
|
+
@game.play(1)
|
|
40
|
+
|
|
41
|
+
@player.health.should == @initial_health - 10
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
context "it returns strong if a players health is lower than 100" do
|
|
45
|
+
|
|
46
|
+
before do
|
|
47
|
+
@player = Player.new('larry')
|
|
48
|
+
@game = Game.new('knuckleheads')
|
|
49
|
+
@game.add_player(@player)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "returns strong if health >= 100 " do
|
|
53
|
+
@player.strong?.should == true
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it "returns false if health < 100" do
|
|
57
|
+
@player.blam
|
|
58
|
+
@player.strong?.should == false
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
context "in a collection of players" do
|
|
64
|
+
before do
|
|
65
|
+
@player1 = Player.new("moe")
|
|
66
|
+
@player1.found_treasure(TreasureTrove::TREASURES[0])
|
|
67
|
+
@player2 = Player.new("larry")
|
|
68
|
+
@player2.found_treasure(TreasureTrove::TREASURES[1])
|
|
69
|
+
@player3 = Player.new("curly")
|
|
70
|
+
@player3.found_treasure(TreasureTrove::TREASURES[2])
|
|
71
|
+
|
|
72
|
+
@players = [@player1, @player2, @player3]
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "is sorted by decreasing score" do
|
|
76
|
+
@players.sort.should == [@player3, @player2, @player1]
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
require "studio_game/player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
describe Player do
|
|
5
|
+
|
|
6
|
+
before do
|
|
7
|
+
@player = Player.new("larry",90)
|
|
8
|
+
$stdout = StringIO.new
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "has a capitalized name" do
|
|
12
|
+
@player.name.should == "Larry"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
it "has a string representation from to_s" do
|
|
16
|
+
@player.to_s.should == "I'm Larry with a health of 90 and a score of 0."
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it "increases health by 15 when w00ted" do
|
|
20
|
+
@player.w00t
|
|
21
|
+
@player.health.should == 105
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "decreases health by 10 when blammed" do
|
|
25
|
+
@player.blam
|
|
26
|
+
@player.health.should == 80
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "created with a default health" do
|
|
30
|
+
|
|
31
|
+
before do
|
|
32
|
+
@player = Player.new("larry")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "has a default health of 100" do
|
|
36
|
+
@player.health.should == 100
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
context "created with 150 health" do
|
|
41
|
+
|
|
42
|
+
before do
|
|
43
|
+
@player = Player.new("larry",150)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "returns true when player is strong?" do
|
|
47
|
+
@player.should be_strong
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
context "created with 100" do
|
|
52
|
+
|
|
53
|
+
before do
|
|
54
|
+
@player = Player.new("larry",100)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
it "computes points as the sum of all treasure points" do
|
|
59
|
+
@player.points.should == 0
|
|
60
|
+
|
|
61
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
62
|
+
|
|
63
|
+
@player.points.should == 50
|
|
64
|
+
|
|
65
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
|
66
|
+
|
|
67
|
+
@player.points.should == 450
|
|
68
|
+
|
|
69
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
70
|
+
|
|
71
|
+
@player.points.should == 500
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -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: code_dudes_ruby_game
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Scott
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2016-01-18 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rspec
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - '>='
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '0'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
description: |+
|
|
28
|
+
Application built while going through "Pragmatic Studios: Ruby Course"
|
|
29
|
+
|
|
30
|
+
Plays a game by loading in players "name,health" format where 'name' is a string and health is an integer
|
|
31
|
+
|
|
32
|
+
You can manually construct a .csv file with players and pass it in as a command line argument.
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
email: smythe3000@gmail.com
|
|
36
|
+
executables:
|
|
37
|
+
- code_dudes_ruby_game
|
|
38
|
+
extensions: []
|
|
39
|
+
extra_rdoc_files: []
|
|
40
|
+
files:
|
|
41
|
+
- LICENSE
|
|
42
|
+
- README
|
|
43
|
+
- bin/code_dudes_ruby_game
|
|
44
|
+
- bin/players.csv
|
|
45
|
+
- lib/studio_game/auditable.rb
|
|
46
|
+
- lib/studio_game/berserker_player.rb
|
|
47
|
+
- lib/studio_game/clumsy.rb
|
|
48
|
+
- lib/studio_game/die.rb
|
|
49
|
+
- lib/studio_game/game.rb
|
|
50
|
+
- lib/studio_game/gameturn.rb
|
|
51
|
+
- lib/studio_game/loaded_die.rb
|
|
52
|
+
- lib/studio_game/playable.rb
|
|
53
|
+
- lib/studio_game/player.rb
|
|
54
|
+
- lib/studio_game/treasure_trove.rb
|
|
55
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
56
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
57
|
+
- spec/studio_game/game_spec.rb
|
|
58
|
+
- spec/studio_game/player_spec.rb
|
|
59
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
60
|
+
homepage: https://github.com/Code-Dude
|
|
61
|
+
licenses:
|
|
62
|
+
- MIT
|
|
63
|
+
metadata: {}
|
|
64
|
+
post_install_message:
|
|
65
|
+
rdoc_options: []
|
|
66
|
+
require_paths:
|
|
67
|
+
- lib
|
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
|
+
requirements:
|
|
70
|
+
- - '>='
|
|
71
|
+
- !ruby/object:Gem::Version
|
|
72
|
+
version: '1.9'
|
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
|
+
requirements:
|
|
75
|
+
- - '>='
|
|
76
|
+
- !ruby/object:Gem::Version
|
|
77
|
+
version: '0'
|
|
78
|
+
requirements: []
|
|
79
|
+
rubyforge_project:
|
|
80
|
+
rubygems_version: 2.4.8
|
|
81
|
+
signing_key:
|
|
82
|
+
specification_version: 4
|
|
83
|
+
summary: Simple game made in the Pragmatic Studios Course
|
|
84
|
+
test_files:
|
|
85
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
86
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
87
|
+
- spec/studio_game/player_spec.rb
|
|
88
|
+
- spec/studio_game/game_spec.rb
|
|
89
|
+
- spec/studio_game/berserk_player_spec.rb
|