demo_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 +7 -0
- data/README +12 -0
- data/bin/demo_game +31 -0
- data/bin/players.csv +3 -0
- data/lib/demo_game/auditable.rb +7 -0
- data/lib/demo_game/berserk_player.rb +32 -0
- data/lib/demo_game/clumsy_player.rb +36 -0
- data/lib/demo_game/die.rb +18 -0
- data/lib/demo_game/game.rb +96 -0
- data/lib/demo_game/game_turn.rb +23 -0
- data/lib/demo_game/loaded_die.rb +16 -0
- data/lib/demo_game/playable.rb +17 -0
- data/lib/demo_game/player.rb +61 -0
- data/lib/demo_game/treasure_trove.rb +18 -0
- data/spec/demo_game/berserk_player_spec.rb +37 -0
- data/spec/demo_game/clumsy_player_spec.rb +50 -0
- data/spec/demo_game/game_spec.rb +80 -0
- data/spec/demo_game/player_spec.rb +113 -0
- data/spec/demo_game/treasure_trove_spec.rb +56 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b01c66b72953823536cc35e164c9f48e280a0661
|
4
|
+
data.tar.gz: 0dcd875a49dc42851fb0b886b5144ff4e3ed9c81
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2b7780ad1c4b5656b009181e96d84520ccadac029a71f739794026ee02bc1fd1e7a4329b6bd1ac99c30c928d177925dcecb1842fff2207530968a567df11ac2
|
7
|
+
data.tar.gz: 268cf0cb77df31671feafd2d39ccf60866ce2ef149098de415a3b3cdda4889a158773c9a5e39bd4c93ae82c3b34cb020f5b510818716321f63daed21c7074cb7
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) <2014> <Luis Ortiz>
|
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,12 @@
|
|
1
|
+
Very simple ruby application that prompts you for the number of rounds you want to play. Created
|
2
|
+
following the tutorials from pragmaticstudio.
|
3
|
+
Just enter a number and the game players will randomly find treasures and gain/lose hit points.
|
4
|
+
You can play as many times as you want until you enter exit/quit.
|
5
|
+
You can also include your own csv files of any players you want to use. The format is 'player_name, health'
|
6
|
+
ex: player1, 100
|
7
|
+
player2, 40
|
8
|
+
player3, 50
|
9
|
+
|
10
|
+
To use: install the gem
|
11
|
+
gem install DemoGame
|
12
|
+
Run it from the command line with cmd 'demo_game'
|
data/bin/demo_game
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/demo_game/game'
|
4
|
+
require_relative '../lib/demo_game/clumsy_player'
|
5
|
+
require_relative '../lib/demo_game/berserk_player'
|
6
|
+
|
7
|
+
final_fantasy = DemoGame::Game.new("Final Fantasy")
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
9
|
+
final_fantasy.load(ARGV.shift || default_player_file)
|
10
|
+
|
11
|
+
klutz = DemoGame::ClumsyPlayer.new("klutz", 105, 3)
|
12
|
+
berserker = DemoGame::BerserkPlayer.new("berserker", 50)
|
13
|
+
final_fantasy.add_player(klutz)
|
14
|
+
final_fantasy.add_player(berserker)
|
15
|
+
|
16
|
+
loop do
|
17
|
+
puts "\How many rounds do you want to play: ('quit' to exit)"
|
18
|
+
answer = gets.chomp.downcase
|
19
|
+
case answer
|
20
|
+
when /^\d+$/
|
21
|
+
final_fantasy.play(answer.to_i)
|
22
|
+
final_fantasy.print_stats
|
23
|
+
when "quit", "exit"
|
24
|
+
break
|
25
|
+
else
|
26
|
+
puts "Enter a number or quit..."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
final_fantasy.save("final_fantasy.savegame")
|
31
|
+
puts "Game saved..."
|
data/bin/players.csv
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module DemoGame
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
|
6
|
+
def initialize(name, health)
|
7
|
+
super(name, health)
|
8
|
+
@w00t_count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def w00t
|
12
|
+
super
|
13
|
+
@w00t_count += 1
|
14
|
+
puts "#{@name} is berserk!" if berserk?
|
15
|
+
end
|
16
|
+
|
17
|
+
def blam
|
18
|
+
berserk? ? w00t : super
|
19
|
+
end
|
20
|
+
|
21
|
+
def berserk?
|
22
|
+
@w00t_count > 5
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
if __FILE__ == $PROGRAM_NAME
|
27
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
28
|
+
6.times { berserker.w00t }
|
29
|
+
2.times { berserker.blam }
|
30
|
+
puts berserker.health
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'treasure_trove'
|
3
|
+
|
4
|
+
module DemoGame
|
5
|
+
class ClumsyPlayer < Player
|
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
|
+
|
17
|
+
def found_treasure(treasure)
|
18
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points/2.0)
|
19
|
+
super(damaged_treasure)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
if __FILE__ == $PROGRAM_NAME
|
24
|
+
clumsy = ClumsyPlayer.new("klutz")
|
25
|
+
hammer = Treasure.new(:hammer, 50)
|
26
|
+
clumsy.found_treasure(hammer)
|
27
|
+
clumsy.found_treasure(hammer)
|
28
|
+
clumsy.found_treasure(hammer)
|
29
|
+
crowbar = Treasure.new(:crowbar, 400)
|
30
|
+
clumsy.found_treasure(crowbar)
|
31
|
+
clumsy.each_treasure do |treasure|
|
32
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
33
|
+
end
|
34
|
+
puts "#{clumsy.points} grand total points"
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'game_turn'
|
4
|
+
|
5
|
+
module DemoGame
|
6
|
+
class Game
|
7
|
+
attr_reader :title
|
8
|
+
|
9
|
+
def initialize(title)
|
10
|
+
@title = title.capitalize
|
11
|
+
@players = []
|
12
|
+
end
|
13
|
+
|
14
|
+
def high_score_entry(player)
|
15
|
+
"#{player.name.ljust(20, ".")} #{player.score}"
|
16
|
+
end
|
17
|
+
|
18
|
+
def load(from_file)
|
19
|
+
File.readlines(from_file).each do |line|
|
20
|
+
add_player(Player.from_csv(line))
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def save(to_file="save_game.txt")
|
25
|
+
File.open(to_file, "w") do |file|
|
26
|
+
file.puts "\n#{@title} High Scores:"
|
27
|
+
@players.sort.each do |player|
|
28
|
+
file.puts high_score_entry(player)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def add_player(player)
|
34
|
+
@players << player
|
35
|
+
end
|
36
|
+
|
37
|
+
def total_points
|
38
|
+
@players.inject(0) { |sum, player| sum += player.points }
|
39
|
+
end
|
40
|
+
|
41
|
+
def play(rounds)
|
42
|
+
puts "There are #{@players.size} players in #{@title}"
|
43
|
+
|
44
|
+
@players.each do |player|
|
45
|
+
puts player
|
46
|
+
end
|
47
|
+
|
48
|
+
treasures = TreasureTrove::TREASURES
|
49
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
50
|
+
treasures.each do |treasure|
|
51
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
52
|
+
end
|
53
|
+
|
54
|
+
1.upto(rounds) do |round|
|
55
|
+
puts "\nRound: #{round}"
|
56
|
+
if block_given?
|
57
|
+
break if yield
|
58
|
+
end
|
59
|
+
@players.each do |player|
|
60
|
+
GameTurn.take_turn(player)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_name_and_health(player)
|
66
|
+
puts "#{player.name} (#{player.health})"
|
67
|
+
end
|
68
|
+
|
69
|
+
def print_stats
|
70
|
+
puts "\n#{@title} statistics:"
|
71
|
+
puts "#{total_points} total points from treasures found"
|
72
|
+
|
73
|
+
@players.each do |player|
|
74
|
+
puts "\n#{player.name}'s point totals:"
|
75
|
+
player.each_treasure do |treasure|
|
76
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
77
|
+
end
|
78
|
+
puts "#{player.points} grand total points"
|
79
|
+
end
|
80
|
+
|
81
|
+
puts "\nStrong:"
|
82
|
+
@players.each do |p|
|
83
|
+
print_name_and_health(p) if p.strong?
|
84
|
+
end
|
85
|
+
puts "\nWimpy:"
|
86
|
+
@players.each do |p|
|
87
|
+
print_name_and_health(p) if !p.strong?
|
88
|
+
end
|
89
|
+
|
90
|
+
puts "\n#{@title} High Scores:"
|
91
|
+
@players.sort.each do |player|
|
92
|
+
puts high_score_entry(player)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'player'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
require_relative 'loaded_die'
|
5
|
+
|
6
|
+
module DemoGame
|
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
|
+
# random treasure found by the player
|
19
|
+
treasure = TreasureTrove.random
|
20
|
+
player.found_treasure(treasure)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
require_relative 'playable'
|
2
|
+
|
3
|
+
module DemoGame
|
4
|
+
class Player
|
5
|
+
include Playable
|
6
|
+
|
7
|
+
attr_accessor :name, :health
|
8
|
+
|
9
|
+
def initialize(name, health=100)
|
10
|
+
@name = name.capitalize
|
11
|
+
@health = health
|
12
|
+
@treasures_found = Hash.new(0)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.from_csv(line)
|
16
|
+
name, health = line.split(",")
|
17
|
+
new(name, Integer(health))
|
18
|
+
end
|
19
|
+
|
20
|
+
def each_treasure
|
21
|
+
@treasures_found.each do |name, points|
|
22
|
+
yield(Treasure.new(name, points))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def found_treasure(treasure)
|
27
|
+
@treasures_found[treasure.name] += treasure.points
|
28
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
29
|
+
end
|
30
|
+
|
31
|
+
def name=(new_name)
|
32
|
+
@name = new_name.capitalize
|
33
|
+
end
|
34
|
+
|
35
|
+
def <=>(player)
|
36
|
+
player.score<=>score
|
37
|
+
end
|
38
|
+
|
39
|
+
def score
|
40
|
+
@health + points
|
41
|
+
end
|
42
|
+
|
43
|
+
def points
|
44
|
+
@treasures_found.values.reduce(0, :+)
|
45
|
+
end
|
46
|
+
|
47
|
+
def to_s
|
48
|
+
"I'm #{@name} with health = #{@health}, points = 100, and score = #{score}"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
if __FILE__ == $PROGRAM_NAME
|
53
|
+
player = Player.new("moe")
|
54
|
+
puts player.name
|
55
|
+
puts player.health
|
56
|
+
player.w00t
|
57
|
+
puts player.health
|
58
|
+
player.blam
|
59
|
+
puts player.health
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module DemoGame
|
2
|
+
Treasure = Struct.new(:name, :points)
|
3
|
+
|
4
|
+
module TreasureTrove
|
5
|
+
TREASURES = [
|
6
|
+
Treasure.new(:pie, 5),
|
7
|
+
Treasure.new(:bottle, 25),
|
8
|
+
Treasure.new(:hammer, 50),
|
9
|
+
Treasure.new(:skillet, 100),
|
10
|
+
Treasure.new(:broomstick, 200),
|
11
|
+
Treasure.new(:crowbar, 400)
|
12
|
+
]
|
13
|
+
|
14
|
+
def self.random
|
15
|
+
TREASURES.sample
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'demo_game/berserk_player'
|
2
|
+
|
3
|
+
module DemoGame
|
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
|
+
|
16
|
+
# or if using Rspec 3.0:
|
17
|
+
# @player.berserk?.should be_falsey
|
18
|
+
end
|
19
|
+
|
20
|
+
it "goes berserk when w00ted more than 5 times" do
|
21
|
+
1.upto(6) { @player.w00t }
|
22
|
+
|
23
|
+
@player.berserk?.should be_true
|
24
|
+
|
25
|
+
# or if using Rspec 3.0:
|
26
|
+
# @player.berserk?.should be_truthy
|
27
|
+
end
|
28
|
+
|
29
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
30
|
+
1.upto(6) { @player.w00t }
|
31
|
+
1.upto(2) { @player.blam }
|
32
|
+
|
33
|
+
@player.health.should == @initial_health + (8 * 15)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'demo_game/clumsy_player'
|
2
|
+
|
3
|
+
module DemoGame
|
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_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 = 5
|
36
|
+
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has a boost factor" do
|
40
|
+
@player.boost_factor.should == 5
|
41
|
+
end
|
42
|
+
|
43
|
+
it "gets boost factor number of w00ts when w00ted" do
|
44
|
+
@player.w00t
|
45
|
+
|
46
|
+
@player.health.should == @initial_health + (15 * @boost_factor)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,80 @@
|
|
1
|
+
require 'demo_game/game'
|
2
|
+
|
3
|
+
module DemoGame
|
4
|
+
describe Game do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@game = Game.new("FinalFantasy")
|
8
|
+
|
9
|
+
@initial_health = 100
|
10
|
+
@player = Player.new("moe", @initial_health)
|
11
|
+
|
12
|
+
@game.add_player(@player)
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'w00ts the player if die rolls a high number' do
|
16
|
+
Die.any_instance.stub(:roll).and_return(5)
|
17
|
+
|
18
|
+
@game.play(2)
|
19
|
+
@player.health.should == @initial_health + (15 * 2)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'leaves the health unchanged if die roll is a medium number' do
|
23
|
+
Die.any_instance.stub(:roll).and_return(3)
|
24
|
+
|
25
|
+
@game.play(2)
|
26
|
+
@player.health.should == @initial_health
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'blams the player if die roll is a low number' do
|
30
|
+
Die.any_instance.stub(:roll).and_return(1)
|
31
|
+
|
32
|
+
@game.play(2)
|
33
|
+
@player.health.should == @initial_health - (10 * 2)
|
34
|
+
end
|
35
|
+
|
36
|
+
context "in a collection of players" do
|
37
|
+
before do
|
38
|
+
@player1 = Player.new("moe", 100)
|
39
|
+
@player2 = Player.new("larry", 200)
|
40
|
+
@player3 = Player.new("curly", 300)
|
41
|
+
|
42
|
+
@players = [@player1, @player2, @player3]
|
43
|
+
end
|
44
|
+
|
45
|
+
it "is sorted by decreasing score" do
|
46
|
+
@players.sort.should == [@player3, @player2, @player1]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "assigns a treasure for points during a player's turn" do
|
51
|
+
game = Game.new("Knuckleheads")
|
52
|
+
player = Player.new("moe")
|
53
|
+
|
54
|
+
game.add_player(player)
|
55
|
+
|
56
|
+
game.play(1)
|
57
|
+
|
58
|
+
player.points.should_not be_zero
|
59
|
+
|
60
|
+
# or use alternate expectation syntax:
|
61
|
+
# expect(player.points).not_to be_zero
|
62
|
+
end
|
63
|
+
|
64
|
+
it "computes total points as the sum of all player points" do
|
65
|
+
game = Game.new("Knuckleheads")
|
66
|
+
|
67
|
+
player1 = Player.new("moe")
|
68
|
+
player2 = Player.new("larry")
|
69
|
+
|
70
|
+
game.add_player(player1)
|
71
|
+
game.add_player(player2)
|
72
|
+
|
73
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
74
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
75
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
76
|
+
|
77
|
+
game.total_points.should == 500
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'demo_game/player'
|
2
|
+
require 'demo_game/treasure_trove'
|
3
|
+
|
4
|
+
module DemoGame
|
5
|
+
describe Player do
|
6
|
+
before do
|
7
|
+
@health = 150
|
8
|
+
@player = Player.new("larry", @health)
|
9
|
+
# Have puts statements printed out to a string object instead of console during
|
10
|
+
# spec tests.
|
11
|
+
$stdout = StringIO.new
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has a capitalized name' do
|
15
|
+
@player.name.should == "Larry"
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'has an initial health' do
|
19
|
+
@player.health.should == 150
|
20
|
+
end
|
21
|
+
|
22
|
+
it "has a string representation" do
|
23
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
24
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
25
|
+
|
26
|
+
@player.to_s.should == "I'm Larry with health = 150, points = 100, and score = 250"
|
27
|
+
end
|
28
|
+
|
29
|
+
it "computes a score as the sum of its health and points" do
|
30
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
31
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
32
|
+
|
33
|
+
@player.score.should == 250
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'increases health by 15 when w00ted' do
|
37
|
+
@player.w00t
|
38
|
+
@player.health.should == @health + 15
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'decreases health by 10 when blammed' do
|
42
|
+
@player.blam
|
43
|
+
@player.health.should == @health - 10
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'created with health greater than 100' do
|
47
|
+
before do
|
48
|
+
@initial_health = 150
|
49
|
+
@player = Player.new("larry", @initial_health)
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'health is greater than 150, player is strong' do
|
53
|
+
@player.should be_strong
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context 'created with health less than or equal to 100' do
|
58
|
+
before do
|
59
|
+
@initial_health = 100
|
60
|
+
@player = Player.new("larry", @initial_health)
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'player is wimpy' do
|
64
|
+
@player.should_not be_strong
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
it "computes points as the sum of all treasure points" do
|
69
|
+
@player.points.should == 0
|
70
|
+
|
71
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
72
|
+
|
73
|
+
@player.points.should == 50
|
74
|
+
|
75
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
76
|
+
|
77
|
+
@player.points.should == 450
|
78
|
+
|
79
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
80
|
+
|
81
|
+
@player.points.should == 500
|
82
|
+
end
|
83
|
+
|
84
|
+
it "yields each found treasure and its total points" do
|
85
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
86
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
87
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
88
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
89
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
90
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
91
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
92
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
93
|
+
|
94
|
+
yielded = []
|
95
|
+
@player.each_treasure do |treasure|
|
96
|
+
yielded << treasure
|
97
|
+
end
|
98
|
+
|
99
|
+
yielded.should == [
|
100
|
+
Treasure.new(:skillet, 200),
|
101
|
+
Treasure.new(:hammer, 50),
|
102
|
+
Treasure.new(:bottle, 25)
|
103
|
+
]
|
104
|
+
end
|
105
|
+
|
106
|
+
it "can be created from a CSV string" do
|
107
|
+
player = Player.from_csv("larry,150")
|
108
|
+
|
109
|
+
player.name.should == "Larry"
|
110
|
+
player.health.should == 150
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require "demo_game/treasure_trove"
|
2
|
+
|
3
|
+
module DemoGame
|
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,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: demo_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Luis Ortiz
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-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: |-
|
28
|
+
Very simple ruby application that prompts you for the number of rounds you want to play. Created
|
29
|
+
following the tutorials from pragmaticstudio.
|
30
|
+
Just enter a number and the game players will randomly find treasures and gain/lose hit points.
|
31
|
+
You can play as many times as you want until you enter exit/quit.
|
32
|
+
You can also include your own csv files of any players you want to use. The format is 'player_name, health'
|
33
|
+
ex: player1, 100
|
34
|
+
player2, 40
|
35
|
+
player3, 50
|
36
|
+
|
37
|
+
To use: install the gem
|
38
|
+
gem install DemoGame
|
39
|
+
Run it from the command line with cmd 'demo_game'
|
40
|
+
email: lortiz1145@gmail.com
|
41
|
+
executables:
|
42
|
+
- demo_game
|
43
|
+
extensions: []
|
44
|
+
extra_rdoc_files: []
|
45
|
+
files:
|
46
|
+
- LICENSE
|
47
|
+
- README
|
48
|
+
- bin/demo_game
|
49
|
+
- bin/players.csv
|
50
|
+
- lib/demo_game/auditable.rb
|
51
|
+
- lib/demo_game/berserk_player.rb
|
52
|
+
- lib/demo_game/clumsy_player.rb
|
53
|
+
- lib/demo_game/die.rb
|
54
|
+
- lib/demo_game/game.rb
|
55
|
+
- lib/demo_game/game_turn.rb
|
56
|
+
- lib/demo_game/loaded_die.rb
|
57
|
+
- lib/demo_game/playable.rb
|
58
|
+
- lib/demo_game/player.rb
|
59
|
+
- lib/demo_game/treasure_trove.rb
|
60
|
+
- spec/demo_game/berserk_player_spec.rb
|
61
|
+
- spec/demo_game/clumsy_player_spec.rb
|
62
|
+
- spec/demo_game/game_spec.rb
|
63
|
+
- spec/demo_game/player_spec.rb
|
64
|
+
- spec/demo_game/treasure_trove_spec.rb
|
65
|
+
homepage: https://github.com/skippyPeanutButter/demo_game.git
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata: {}
|
69
|
+
post_install_message:
|
70
|
+
rdoc_options: []
|
71
|
+
require_paths:
|
72
|
+
- lib
|
73
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.9'
|
78
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 2.4.5
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Text based game created following tutorial
|
89
|
+
test_files:
|
90
|
+
- spec/demo_game/berserk_player_spec.rb
|
91
|
+
- spec/demo_game/clumsy_player_spec.rb
|
92
|
+
- spec/demo_game/game_spec.rb
|
93
|
+
- spec/demo_game/player_spec.rb
|
94
|
+
- spec/demo_game/treasure_trove_spec.rb
|