prag_studio_game_by_dom 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 +19 -0
- data/README +0 -0
- data/bin/studio_game.rb +21 -0
- data/lib/studio_game/berzerk_player.rb +41 -0
- data/lib/studio_game/clumsy_player.rb +44 -0
- data/lib/studio_game/die.rb +21 -0
- data/lib/studio_game/game.rb +56 -0
- data/lib/studio_game/game_turn.rb +27 -0
- data/lib/studio_game/playable.rb +18 -0
- data/lib/studio_game/player.rb +61 -0
- data/lib/studio_game/treasure_trove.rb +34 -0
- data/spec/studio_game/berzerk_player_spec.rb +0 -0
- data/spec/studio_game/clumsy_player_spec.rb +49 -0
- data/spec/studio_game/game_spec.rb +43 -0
- data/spec/studio_game/player_spec.rb +133 -0
- data/spec/studio_game/spec_helper.rb +11 -0
- data/spec/studio_game/treasure_trove_spec.rb +58 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fb370ae80807bca7fc8989cb371bb1edb8505b71
|
4
|
+
data.tar.gz: edf4fc1554d4a8e577c091a189c3bc7285323d60
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d91d5409def0814236b0fe164f84301563ed388f20fc785d3ba619564e8ce5f42ce103aa54149cf0f8c88bb35ad61e333ca8693b1dbfbff5192b4dcb2412fcf
|
7
|
+
data.tar.gz: ea624d76025eefadf815254a7cc682087c45313c8cf6236086d44d97c54b53a3e670a8ca37259cc9f7020e91dee4802e89ce9ae75794917424dff007b6e403bb
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2017 Dominic Michalec
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
19
|
+
SOFTWARE.
|
data/README
ADDED
File without changes
|
data/bin/studio_game.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# run ruby bin/studio_game.rb
|
2
|
+
module StudioGame
|
3
|
+
require_relative '../lib/studio_game/game'
|
4
|
+
require_relative '../lib/studio_game/clumsy_player'
|
5
|
+
require_relative '../lib/studio_game/berzerk_player'
|
6
|
+
|
7
|
+
|
8
|
+
player1 = Player.new("moe")
|
9
|
+
player2 = Player.new("larry", 60)
|
10
|
+
player3 = Player.new("curly", 125)
|
11
|
+
player4 = ClumsyPlayer.new("klutz", 105, 3)
|
12
|
+
berserker = BerzerkPlayer.new("berserker", 50)
|
13
|
+
game = StudioGame::Game.new("thunderdome")
|
14
|
+
game.add(player1)
|
15
|
+
game.add(player2)
|
16
|
+
game.add(player3)
|
17
|
+
game.add(player4)
|
18
|
+
game.add(berserker)
|
19
|
+
game.play(5)
|
20
|
+
game.print_stats
|
21
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
module StudioGame
|
3
|
+
class BerzerkPlayer < Player
|
4
|
+
|
5
|
+
def initialize(name, health=100, woot_count=0)
|
6
|
+
# pass the name and health parameters to the initialize method in the Player
|
7
|
+
# class
|
8
|
+
super(name, health)
|
9
|
+
@woot_count = 0
|
10
|
+
end
|
11
|
+
|
12
|
+
# returns true if value of woot_count is greater than 5
|
13
|
+
def berzerk?
|
14
|
+
@woot_count >= 5
|
15
|
+
end
|
16
|
+
|
17
|
+
#
|
18
|
+
def w00t!
|
19
|
+
# run the w00t! method in the parent Player class
|
20
|
+
super
|
21
|
+
# increase w00t_count by 1
|
22
|
+
@woot_count += 1
|
23
|
+
# print a message if a player has gone berzerk
|
24
|
+
puts "#{@name} is berserk!" if berzerk?
|
25
|
+
end
|
26
|
+
|
27
|
+
# if player has gone berzerk, w00t! instead of blam!, else blam! the player
|
28
|
+
# from the blam! method defined in the parent Player class
|
29
|
+
def blam!
|
30
|
+
berzerk? ? w00t! : super
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
# put file-specific example code here
|
35
|
+
if __FILE__ == $0
|
36
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
37
|
+
6.times { berserker.w00t }
|
38
|
+
2.times { berserker.blam }
|
39
|
+
puts berserker.health
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'player'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class ClumsyPlayer < Player
|
6
|
+
attr_accessor :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
|
+
# w00t! a ClumsyPlayer by the boost_factor
|
15
|
+
@boost_factor.times { super }
|
16
|
+
end
|
17
|
+
|
18
|
+
# add the found treasure to the user's treasures chest hash and half the points
|
19
|
+
def find(treasure)
|
20
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
21
|
+
# pass the damanged treasure back up to the parent class Player definition
|
22
|
+
# of player.find method
|
23
|
+
super(damaged_treasure)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# put file-specific example code here
|
28
|
+
if __FILE__ == $0
|
29
|
+
clumsy = ClumsyPlayer.new("klutz")
|
30
|
+
|
31
|
+
hammer = Treasure.new(:hammer, 50)
|
32
|
+
clumsy.find(hammer)
|
33
|
+
clumsy.find(hammer)
|
34
|
+
clumsy.find(hammer)
|
35
|
+
|
36
|
+
crowbar = Treasure.new(:crowbar, 400)
|
37
|
+
clumsy.find(crowbar)
|
38
|
+
|
39
|
+
clumsy.each_found_treasure do |treasure|
|
40
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
41
|
+
end
|
42
|
+
puts "#{clumsy.points} grand total points"
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module StudioGame
|
2
|
+
class Die
|
3
|
+
|
4
|
+
# create initial state of die and call its roll method upon creation
|
5
|
+
def initialize
|
6
|
+
roll
|
7
|
+
end
|
8
|
+
|
9
|
+
# returns a random number between 1 and 6
|
10
|
+
def roll
|
11
|
+
@number = rand(1..6)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
# put file-specific example code here
|
17
|
+
if __FILE__ == $0
|
18
|
+
number_rolled = Die.new
|
19
|
+
puts number_rolled
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'game_turn'
|
2
|
+
require_relative 'treasure_trove'
|
3
|
+
module StudioGame
|
4
|
+
class Game
|
5
|
+
attr_reader :title
|
6
|
+
# create initial state of game with a name and container for players
|
7
|
+
def initialize(title)
|
8
|
+
@title = title.capitalize
|
9
|
+
@players = Array.new
|
10
|
+
end
|
11
|
+
|
12
|
+
# add players to the @players array
|
13
|
+
def add(player)
|
14
|
+
@players << player
|
15
|
+
end
|
16
|
+
|
17
|
+
# driver method for how the game is played
|
18
|
+
def play(rounds)
|
19
|
+
puts "\nThere are #{@players.size} players and " +
|
20
|
+
"#{TreasureTrove::TREASURES.size} treasures in #{@title}"
|
21
|
+
1.upto(rounds) do |round|
|
22
|
+
puts "\nRound #{round}"
|
23
|
+
@players.each do |p|
|
24
|
+
GameTurn.take_turn(p)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
# stylize how final score is presented
|
30
|
+
def print_name_and_health(player)
|
31
|
+
puts "#{player.name.ljust(20,'.')}#{player.score}"
|
32
|
+
player.each_treasure do |treasure|
|
33
|
+
puts "#{treasure.points} points from #{treasure.name}"
|
34
|
+
end
|
35
|
+
puts "...for a grand total of #{player.points} points."
|
36
|
+
end
|
37
|
+
|
38
|
+
def print_stats
|
39
|
+
puts "\n#{@title}'s Final Scores:"
|
40
|
+
sorted_players = @players.sort
|
41
|
+
strong_players, wimpy_players = sorted_players.partition { |x| x.strong? }
|
42
|
+
puts "Strong players:"
|
43
|
+
strong_players.each do |strong_player|
|
44
|
+
print_name_and_health(strong_player)
|
45
|
+
end
|
46
|
+
puts "Wimpy players:"
|
47
|
+
wimpy_players.each do |wimpy_player|
|
48
|
+
print_name_and_health(wimpy_player)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
# put file-specific example code here
|
54
|
+
if __FILE__ == $0
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
module GameTurn
|
7
|
+
|
8
|
+
# create a module method that encapsulates the turn taking behavior
|
9
|
+
def self.take_turn(player)
|
10
|
+
die = Die.new
|
11
|
+
case die.roll
|
12
|
+
when 5..6
|
13
|
+
player.w00t!
|
14
|
+
puts "#{player.name} was w00ted!."
|
15
|
+
when 3..4
|
16
|
+
puts "#{player.name} was skipped."
|
17
|
+
when 1..2
|
18
|
+
player.blam!
|
19
|
+
puts "#{player.name} was blammed!"
|
20
|
+
end
|
21
|
+
|
22
|
+
# a player finds a treasure at the end of each round
|
23
|
+
treasure = TreasureTrove.random
|
24
|
+
player.find(treasure)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module StudioGame
|
2
|
+
module Playable
|
3
|
+
# increase health by a 10 if w00ted
|
4
|
+
def w00t!
|
5
|
+
self.health += 15
|
6
|
+
end
|
7
|
+
|
8
|
+
# decrease health by 15 if blammed
|
9
|
+
def blam!
|
10
|
+
self.health -= 10
|
11
|
+
end
|
12
|
+
|
13
|
+
# determine if player is strong
|
14
|
+
def strong?
|
15
|
+
self.health >= 100
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'playable'
|
2
|
+
module StudioGame
|
3
|
+
class Player
|
4
|
+
include Playable
|
5
|
+
# getter and setter method for the name and health attributes
|
6
|
+
attr_accessor :health
|
7
|
+
attr_accessor :name
|
8
|
+
# create initial state of player objects with default health of 100
|
9
|
+
def initialize(name, health=100)
|
10
|
+
@name = name.capitalize
|
11
|
+
@health = health
|
12
|
+
# create a hash with default value pairs of zero
|
13
|
+
@treasure_chest = Hash.new(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
# print out the following string everytime puts is called on object
|
17
|
+
def to_s
|
18
|
+
"My name is #{name} with a health of #{health}."
|
19
|
+
end
|
20
|
+
|
21
|
+
def each_treasure
|
22
|
+
@treasure_chest.each do |name, points|
|
23
|
+
yield Treasure.new(name, points)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# add the found treasure to the user's treasures chest hash
|
28
|
+
def find(treasure)
|
29
|
+
@treasure_chest[treasure.name] += treasure.points
|
30
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
31
|
+
puts "#{@name}'s treasures: #{@treasure_chest}"
|
32
|
+
end
|
33
|
+
|
34
|
+
# add up all the points in a player's treasure chest as a virtual attribute
|
35
|
+
def points
|
36
|
+
@treasure_chest.values.reduce(0, :+)
|
37
|
+
end
|
38
|
+
|
39
|
+
# sort players by descending scores
|
40
|
+
def <=>(other)
|
41
|
+
other.score <=> score
|
42
|
+
end
|
43
|
+
|
44
|
+
# create a virtual attribute comprised of player's name and health
|
45
|
+
def score
|
46
|
+
@health + self.points
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# put file-specific example code here
|
51
|
+
if __FILE__ == $0
|
52
|
+
# access and change name attribute outside of the class (by default an object's state is
|
53
|
+
# private)
|
54
|
+
dom = Player.new("dom")
|
55
|
+
puts dom.name
|
56
|
+
dom.name = "Dominic"
|
57
|
+
puts dom.name
|
58
|
+
# access the health attribute outside of the class
|
59
|
+
puts dom
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# class Treasure
|
2
|
+
# attr_reader :name
|
3
|
+
# attr_writer :carbs
|
4
|
+
|
5
|
+
# def initialize(name, points)
|
6
|
+
# @name = name
|
7
|
+
# @point_value = points
|
8
|
+
# end
|
9
|
+
# end
|
10
|
+
|
11
|
+
module StudioGame
|
12
|
+
Treasure = Struct.new(:name, :points)
|
13
|
+
|
14
|
+
module TreasureTrove
|
15
|
+
|
16
|
+
TREASURES = [
|
17
|
+
Treasure.new(:pie, 5),
|
18
|
+
Treasure.new(:bottle, 25),
|
19
|
+
Treasure.new(:hammer, 50),
|
20
|
+
Treasure.new(:skillet, 100),
|
21
|
+
Treasure.new(:broomstick, 200),
|
22
|
+
Treasure.new(:crowbar, 400)
|
23
|
+
]
|
24
|
+
|
25
|
+
# return a random Treasure
|
26
|
+
def self.random
|
27
|
+
TREASURES.sample
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# put file-specific example code here
|
32
|
+
if __FILE__ == $0
|
33
|
+
end
|
34
|
+
end
|
File without changes
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
module StudioGame
|
3
|
+
describe ClumsyPlayer do
|
4
|
+
before do
|
5
|
+
@player = ClumsyPlayer.new("klutz")
|
6
|
+
end
|
7
|
+
|
8
|
+
it "only gets half the point value for each treasure" do
|
9
|
+
@player.points.should == 0
|
10
|
+
|
11
|
+
hammer = Treasure.new(:hammer, 50)
|
12
|
+
@player.find(hammer)
|
13
|
+
@player.find(hammer)
|
14
|
+
@player.find(hammer)
|
15
|
+
|
16
|
+
@player.points.should == 75
|
17
|
+
|
18
|
+
crowbar = Treasure.new(:crowbar, 400)
|
19
|
+
@player.find(crowbar)
|
20
|
+
|
21
|
+
@player.points.should == 275
|
22
|
+
|
23
|
+
yielded = []
|
24
|
+
@player.each_treasure do |treasure|
|
25
|
+
yielded << treasure
|
26
|
+
end
|
27
|
+
|
28
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
29
|
+
end
|
30
|
+
|
31
|
+
context "with a boost factor" do
|
32
|
+
before do
|
33
|
+
@initial_health = 100
|
34
|
+
@boost_factor = 5
|
35
|
+
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a boost factor" do
|
39
|
+
@player.boost_factor.should == 5
|
40
|
+
end
|
41
|
+
|
42
|
+
it "gets boost factor number of w00ts when w00ted" do
|
43
|
+
@player.w00t!
|
44
|
+
|
45
|
+
@player.health.should == @initial_health + (15 * @boost_factor)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
require 'studio_game/spec_helper'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
describe Game do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@game = Game.new("Knuckleheads")
|
9
|
+
|
10
|
+
@initial_health = 100
|
11
|
+
@player = Player.new("moe", @initial_health)
|
12
|
+
|
13
|
+
@game.add(@player)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "w00ts the player if a high number is rolled" do
|
17
|
+
#allow_any_instance_of(Die).to receive(:roll).and_return(5)
|
18
|
+
Die.any_instance.stub(:roll).and_return(5)
|
19
|
+
|
20
|
+
@game.play(1)
|
21
|
+
|
22
|
+
@player.health.should == @initial_health + 15
|
23
|
+
end
|
24
|
+
|
25
|
+
it "skips the player if a medium number is rolled" do
|
26
|
+
#allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
27
|
+
Die.any_instance.stub(:roll).and_return(3)
|
28
|
+
|
29
|
+
@game.play(1)
|
30
|
+
|
31
|
+
@player.health.should == @initial_health
|
32
|
+
end
|
33
|
+
|
34
|
+
it "blams a player if a low number is rolled" do
|
35
|
+
#allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
36
|
+
Die.any_instance.stub(:roll).and_return(1)
|
37
|
+
|
38
|
+
@game.play(1)
|
39
|
+
|
40
|
+
@player.health.should == @initial_health - 10
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
require 'studio_game/spec_helper'
|
3
|
+
module StudioGame
|
4
|
+
# define a Player example group with describe
|
5
|
+
# run rspec player_spec.rb --color to run test suite
|
6
|
+
describe Player do
|
7
|
+
|
8
|
+
# extract player state to before block
|
9
|
+
before do
|
10
|
+
@player = Player.new("dom", 10)
|
11
|
+
end
|
12
|
+
|
13
|
+
# expect a capitalized name
|
14
|
+
it "should have a capitalized name" do
|
15
|
+
# expect(@player.name).to eq("Dom")
|
16
|
+
@player.name.should == "Dom"
|
17
|
+
end
|
18
|
+
|
19
|
+
# expect to_s to return name and health
|
20
|
+
it "should return name and health with to_s" do
|
21
|
+
# expect(@player.to_s).to eq("My name is Dom with a health of 10")
|
22
|
+
@player.to_s.should == "My name is Dom with a health of 10."
|
23
|
+
end
|
24
|
+
|
25
|
+
# expect a w00t! to increase health by 10
|
26
|
+
it "should increase health by 10 if w00ted" do
|
27
|
+
@player.w00t!
|
28
|
+
# expect(@player.health).to eq(20)
|
29
|
+
@player.health.should == 25
|
30
|
+
end
|
31
|
+
|
32
|
+
# expect a blam! to decrease health by 15
|
33
|
+
it "should decrease health by 10 if blammed" do
|
34
|
+
@player.blam!
|
35
|
+
# expect(@player.health).to eq(0)
|
36
|
+
@player.health.should == 0
|
37
|
+
end
|
38
|
+
|
39
|
+
# expect a players score (virtual attribute) to equal health plus name length
|
40
|
+
it "should have a score equal to its health plus length of name" do
|
41
|
+
@player.score
|
42
|
+
# expect(@player.score).to eq(10)
|
43
|
+
@player.score.should == 10
|
44
|
+
end
|
45
|
+
|
46
|
+
# set up a player with a default initial health for context
|
47
|
+
context do
|
48
|
+
|
49
|
+
# extract player state to before block
|
50
|
+
before do
|
51
|
+
@initial_health = 100
|
52
|
+
@player = Player.new("dom", @initial_health)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should have an initial health of 100" do
|
56
|
+
# expect(@player.health).to eq(100)
|
57
|
+
@player.health.should == 100
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# set up a player with a default initial health and status for context
|
62
|
+
context do
|
63
|
+
|
64
|
+
# extract player state to before block
|
65
|
+
before do
|
66
|
+
@player = Player.new("dom")
|
67
|
+
end
|
68
|
+
|
69
|
+
# should be strong if health is greater than or equal to 100
|
70
|
+
it "should be strong" do
|
71
|
+
# @player.strong?.should == true
|
72
|
+
@player.should be_strong
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
# set up a player with a health of 150
|
77
|
+
context do
|
78
|
+
|
79
|
+
before do
|
80
|
+
@player = Player.new("dom", 150)
|
81
|
+
end
|
82
|
+
|
83
|
+
# expect the player to be strong
|
84
|
+
it "should be considered strong" do
|
85
|
+
# @player.strong?.should == true
|
86
|
+
# expect(@player.strong?).to eq(true)
|
87
|
+
@player.should be_strong
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
# set up a player with a health of 150
|
92
|
+
context do
|
93
|
+
|
94
|
+
before do
|
95
|
+
@player = Player.new("dom", 9)
|
96
|
+
end
|
97
|
+
|
98
|
+
# expect the player to be strong
|
99
|
+
it "should be considered strong" do
|
100
|
+
# @player.strong?.should == false
|
101
|
+
# expect(@player.strong?).to eq(false)
|
102
|
+
@player.should_not be_strong
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
it "computes points as the sum of all treasure points" do
|
107
|
+
@player.points.should == 0
|
108
|
+
|
109
|
+
@player.find(Treasure.new(:hammer, 50))
|
110
|
+
@player.points.should == 50
|
111
|
+
|
112
|
+
@player.find(Treasure.new(:crowbar, 400))
|
113
|
+
@player.points.should == 450
|
114
|
+
|
115
|
+
@player.find(Treasure.new(:hammer, 50))
|
116
|
+
@player.points.should == 500
|
117
|
+
end
|
118
|
+
|
119
|
+
context "in a collection of players" do
|
120
|
+
before do
|
121
|
+
@player1 = Player.new("moe", 100)
|
122
|
+
@player2 = Player.new("larry", 200)
|
123
|
+
@player3 = Player.new("curly", 300)
|
124
|
+
|
125
|
+
@players = [@player1, @player2, @player3]
|
126
|
+
end
|
127
|
+
|
128
|
+
it "is sorted by decreasing score" do
|
129
|
+
@players.sort.should == [@player3, @player2, @player1]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# enable #should syntax without deprication warning
|
2
|
+
module StudioGame
|
3
|
+
RSpec.configure do |config|
|
4
|
+
config.expect_with :rspec do |c|
|
5
|
+
c.syntax = [:should, :expect]
|
6
|
+
end
|
7
|
+
config.mock_with :rspec do |c|
|
8
|
+
c.syntax = [:should, :expect]
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'studio_game/treasure_trove'
|
2
|
+
module StudioGame
|
3
|
+
describe Treasure do
|
4
|
+
|
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
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
describe TreasureTrove do
|
20
|
+
|
21
|
+
it "has six treasures" do
|
22
|
+
TreasureTrove::TREASURES.size.should == 6
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a pie worth 5 points" do
|
26
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "has a bottle worth 25 points" do
|
30
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has a hammer worth 50 points" do
|
34
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
35
|
+
end
|
36
|
+
|
37
|
+
it "has a skillet worth 100 points" do
|
38
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
39
|
+
end
|
40
|
+
|
41
|
+
it "has a broomstick worth 200 points" do
|
42
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has a crowbar worth 400 points" do
|
46
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "returns a random treasure" do
|
50
|
+
treasure = TreasureTrove.random
|
51
|
+
|
52
|
+
TreasureTrove::TREASURES.should include(treasure)
|
53
|
+
|
54
|
+
# or use alternate expectation syntax:
|
55
|
+
# expect(TreasureTrove::TREASURES).to include(treasure)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: prag_studio_game_by_dom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dominic Michalec
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-03-22 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
|
+
email: dominicjjmichalec@gmail.com
|
29
|
+
executables:
|
30
|
+
- studio_game.rb
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- LICENSE
|
35
|
+
- README
|
36
|
+
- bin/studio_game.rb
|
37
|
+
- lib/studio_game/berzerk_player.rb
|
38
|
+
- lib/studio_game/clumsy_player.rb
|
39
|
+
- lib/studio_game/die.rb
|
40
|
+
- lib/studio_game/game.rb
|
41
|
+
- lib/studio_game/game_turn.rb
|
42
|
+
- lib/studio_game/playable.rb
|
43
|
+
- lib/studio_game/player.rb
|
44
|
+
- lib/studio_game/treasure_trove.rb
|
45
|
+
- spec/studio_game/berzerk_player_spec.rb
|
46
|
+
- spec/studio_game/clumsy_player_spec.rb
|
47
|
+
- spec/studio_game/game_spec.rb
|
48
|
+
- spec/studio_game/player_spec.rb
|
49
|
+
- spec/studio_game/spec_helper.rb
|
50
|
+
- spec/studio_game/treasure_trove_spec.rb
|
51
|
+
homepage:
|
52
|
+
licenses:
|
53
|
+
- MIT
|
54
|
+
metadata: {}
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '1.9'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 2.4.8
|
72
|
+
signing_key:
|
73
|
+
specification_version: 4
|
74
|
+
summary: Studio Game Ruby Gem
|
75
|
+
test_files:
|
76
|
+
- spec/studio_game/berzerk_player_spec.rb
|
77
|
+
- spec/studio_game/clumsy_player_spec.rb
|
78
|
+
- spec/studio_game/game_spec.rb
|
79
|
+
- spec/studio_game/player_spec.rb
|
80
|
+
- spec/studio_game/spec_helper.rb
|
81
|
+
- spec/studio_game/treasure_trove_spec.rb
|