studio_game_xx 01.00.00
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 +4 -0
- data/bin/high_scores.txt +8 -0
- data/bin/my_favorite_players.csv +4 -0
- data/bin/players.csv +5 -0
- data/bin/studio_game +60 -0
- data/lib/studio_game/auditable.rb +8 -0
- data/lib/studio_game/berserk_player.rb +32 -0
- data/lib/studio_game/clumsy_player.rb +45 -0
- data/lib/studio_game/die.rb +18 -0
- data/lib/studio_game/game.rb +128 -0
- data/lib/studio_game/game_turn.rb +29 -0
- data/lib/studio_game/loaded_die.rb +14 -0
- data/lib/studio_game/playable.rb +19 -0
- data/lib/studio_game/player.rb +77 -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 +53 -0
- data/spec/studio_game/game_spec.rb +82 -0
- data/spec/studio_game/high_scores.txt +8 -0
- data/spec/studio_game/player_spec.rb +135 -0
- data/spec/studio_game/treasure_trove_spec.rb +57 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: a94b7000b45e211af1f4fda4f526cb471de7c25a
|
|
4
|
+
data.tar.gz: 7821605279f1634c5dbb4107cca4e4e44679c5d9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 205bcbc21948a8c9201d501b68888f35bd50de3d2fccfb432d30bd497063fd162ad8ed275b2cd7421650b4347518581af10506f97b0467751ba231b09b5a9936
|
|
7
|
+
data.tar.gz: d3f5b07d7d457336326f6b9bca00deeee059ec312be85cd6c167b713ce7de0b924a6d880327258b8038413c0091e733d67c759c02c7f49f0450f696f0b2bb08d
|
data/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2017 Adan's Ruby Partners
|
|
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
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
This gem name studio game es una gema que contiene
|
|
2
|
+
clases que permite jugar ya sea enviando en un csv los nombres de los jugadores
|
|
3
|
+
y su salud o de manera automatica. El juego se trata de que jugador mantiene mejor salud y adiciona
|
|
4
|
+
encuentra herramientas que lo hacen mas fuerte
|
data/bin/high_scores.txt
ADDED
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative '../lib/studio_game/player'
|
|
4
|
+
require_relative '../lib/studio_game/clumsy_player'
|
|
5
|
+
require_relative '../lib/studio_game/berserk_player'
|
|
6
|
+
require_relative '../lib/studio_game/game'
|
|
7
|
+
require_relative '../lib/studio_game/die'
|
|
8
|
+
|
|
9
|
+
module StudioGame
|
|
10
|
+
|
|
11
|
+
def time
|
|
12
|
+
Time.new.strftime("%I:%M:%S")
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
time = Time.new
|
|
16
|
+
puts "The game started on #{time.strftime("%A %d/%m/%Y at %I:%M %p")}"
|
|
17
|
+
|
|
18
|
+
game = StudioGame::Game.new("Knuckleheads")
|
|
19
|
+
puts File.join(File.dirname(__FILE__),'players.csv')
|
|
20
|
+
|
|
21
|
+
default_player_file = File.join(File.dirname(__FILE__),'players.csv')
|
|
22
|
+
game.load_players(ARGV.shift||default_player_file)
|
|
23
|
+
|
|
24
|
+
clumsy_player = ClumsyPlayer.new("klutz",105)
|
|
25
|
+
game.addplayers(clumsy_player)
|
|
26
|
+
|
|
27
|
+
berserkplayer = BerserkPlayer.new("berserker",50)
|
|
28
|
+
game.addplayers(berserkplayer)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
rounds = Die.new.roll
|
|
32
|
+
loop do
|
|
33
|
+
puts "Enter numbers of rouds or 'quit' to exit "
|
|
34
|
+
answer = gets.chomp.downcase
|
|
35
|
+
case answer
|
|
36
|
+
when /^\d+$/
|
|
37
|
+
game.play(answer.to_i)
|
|
38
|
+
when 'quit','exit'
|
|
39
|
+
game.print_stats
|
|
40
|
+
break
|
|
41
|
+
else
|
|
42
|
+
puts "Please Enter a Number or 'quit'"
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
end
|
|
46
|
+
game.save_high_scores
|
|
47
|
+
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
#puts "#{name1.capitalize}'s health is #{health1}"
|
|
56
|
+
#puts "#{name2.upcase}'s health is #{health2}"
|
|
57
|
+
#puts "#{name3} has a health of #{health3}".center(50,".")
|
|
58
|
+
#puts "#{name4.capitalize.ljust(48,".")} #{health4} health"
|
|
59
|
+
|
|
60
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
module StudioGame
|
|
3
|
+
class BerserkPlayer < Player
|
|
4
|
+
def initialize(player_name, player_health=100)
|
|
5
|
+
@wooted_times = 0
|
|
6
|
+
super(player_name, player_health)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def w00t
|
|
10
|
+
super
|
|
11
|
+
@wooted_times += 1
|
|
12
|
+
puts "#{@name} is berserk!" if self.berserk?
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def blam
|
|
16
|
+
self.berserk? ? self.w00t : super
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def berserk?
|
|
20
|
+
@wooted_times > 5
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
if __FILE__ == $0
|
|
26
|
+
berserkplayer = BerserkPlayer.new("Adan", 50)
|
|
27
|
+
6.times {berserkplayer.w00t}
|
|
28
|
+
2.times {berserkplayer.blam}
|
|
29
|
+
puts berserkplayer.health
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'treasure_trove'
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
|
|
6
|
+
def initialize(name, health=100, boost=10)
|
|
7
|
+
|
|
8
|
+
super(name,health)
|
|
9
|
+
@boost_factor = boost
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def w00t
|
|
13
|
+
@boost_factor.times {super}
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def found_treasure(treasure)
|
|
17
|
+
new_treasure = Treasure.new(treasure.name, treasure.points/2)
|
|
18
|
+
super(new_treasure)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def boost_factor
|
|
22
|
+
@boost_factor
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
if __FILE__ == $0
|
|
28
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
29
|
+
|
|
30
|
+
hammer = Treasure.new(:hammer, 50)
|
|
31
|
+
clumsy.found_treasure(hammer)
|
|
32
|
+
clumsy.found_treasure(hammer)
|
|
33
|
+
clumsy.found_treasure(hammer)
|
|
34
|
+
|
|
35
|
+
crowbar = Treasure.new(:crowbar, 400)
|
|
36
|
+
clumsy.found_treasure(crowbar)
|
|
37
|
+
|
|
38
|
+
clumsy.each_found_treasure do |treasure|
|
|
39
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
40
|
+
end
|
|
41
|
+
puts "#{clumsy.points} grand total points"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
require_relative 'die'
|
|
3
|
+
require_relative 'game_turn'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
require_relative 'clumsy_player'
|
|
6
|
+
require 'csv'
|
|
7
|
+
|
|
8
|
+
module StudioGame
|
|
9
|
+
class Game
|
|
10
|
+
attr_reader :title
|
|
11
|
+
def initialize(gametitle)
|
|
12
|
+
@title = gametitle
|
|
13
|
+
@players = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def addplayers(player)
|
|
17
|
+
@players << player
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def load_players(file)
|
|
21
|
+
CSV.foreach(file) do |registro|
|
|
22
|
+
player = Player.new(registro[0],Integer(registro[1]))
|
|
23
|
+
addplayers(player)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def save_high_scores (file="high_scores.txt")
|
|
28
|
+
File.open(file,"w") do |file|
|
|
29
|
+
file.puts "#{@title} High Scores:"
|
|
30
|
+
@players.sort.each do |player|
|
|
31
|
+
file.puts high_scores_entry(player)
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def play(rounds)
|
|
40
|
+
puts "There are #{@players.size} in #{self.title}:"
|
|
41
|
+
puts @players
|
|
42
|
+
treasure = TreasureTrove::TREASURES
|
|
43
|
+
|
|
44
|
+
puts "\n The are #{treasure.size} treasure to be found"
|
|
45
|
+
|
|
46
|
+
treasure.each do |treasure|
|
|
47
|
+
puts "A #{treasure.name} is worth #{treasure.points} points"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
1.upto(rounds) do |round|
|
|
53
|
+
puts "\n Round number: #{round} "
|
|
54
|
+
@players.each do |player|
|
|
55
|
+
GameTurn.take_turn(player)
|
|
56
|
+
puts player
|
|
57
|
+
end
|
|
58
|
+
if block_given?
|
|
59
|
+
if yield(total_points)
|
|
60
|
+
puts "\n\n ending game 2000+ points reached #{total_points}"
|
|
61
|
+
break
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def print_name_health(player)
|
|
69
|
+
player.name + "....." + player.health.to_s
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def print_stats
|
|
73
|
+
puts "Statistics...."
|
|
74
|
+
strong, wimpy = @players.partition {|player| player.strong?}
|
|
75
|
+
puts "\n Strong Players:"
|
|
76
|
+
strong.each { |player| puts self.print_name_health(player) }
|
|
77
|
+
puts "\n Wimpy Players:"
|
|
78
|
+
wimpy.each { |player| puts self.print_name_health(player) }
|
|
79
|
+
|
|
80
|
+
#sorted_players = @players.sort {|p1,p2| p2.score <=> p1.score}
|
|
81
|
+
|
|
82
|
+
@players.sort.each do |player|
|
|
83
|
+
puts "\n #{player.name}'s points totals:"
|
|
84
|
+
player.each_found_treasure do |treasure|
|
|
85
|
+
puts "#{treasure.points} totals #{treasure.name} points"
|
|
86
|
+
end
|
|
87
|
+
puts "\n #{player.points} grand totals..."
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
puts "Players Total Points"
|
|
93
|
+
@players.each do |player|
|
|
94
|
+
puts "\n #{player.name}'s point totals:"
|
|
95
|
+
puts "#{player.points} grand total points"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
puts "\n #{self.title} High Scores:"
|
|
101
|
+
|
|
102
|
+
@players.sort.each do |player|
|
|
103
|
+
puts high_scores_entry(player)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def high_scores_entry(player)
|
|
108
|
+
|
|
109
|
+
"#{player.name.ljust(20,".")} #{player.score}"
|
|
110
|
+
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def total_points
|
|
116
|
+
@players.reduce(0) do |sum,player|
|
|
117
|
+
sum += player.points
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
if __FILE__ == $0
|
|
124
|
+
game = Game.new("Nuevo Juego")
|
|
125
|
+
game.addplayers(Player.new("adan"))
|
|
126
|
+
game.play(4)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require_relative('die')
|
|
2
|
+
require_relative('player')
|
|
3
|
+
require_relative('treasure_trove')
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
module GameTurn
|
|
7
|
+
def self.take_turn(player)
|
|
8
|
+
die = Die.new
|
|
9
|
+
|
|
10
|
+
case die.roll
|
|
11
|
+
when 5..6
|
|
12
|
+
player.w00t
|
|
13
|
+
when 3..4
|
|
14
|
+
puts "Player #{player.name} was skipped"
|
|
15
|
+
else
|
|
16
|
+
player.blam
|
|
17
|
+
end
|
|
18
|
+
treasure = find_treasure
|
|
19
|
+
player.found_treasure(treasure)
|
|
20
|
+
#puts " Player #{player.name} found a #{treasure.name} with a #{treasure.points} points"
|
|
21
|
+
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def self.find_treasure
|
|
25
|
+
TreasureTrove.random
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
require_relative 'playable'
|
|
3
|
+
module StudioGame
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
|
|
7
|
+
attr_accessor :health, :name
|
|
8
|
+
|
|
9
|
+
def initialize(player_name, player_health=100)
|
|
10
|
+
@name = player_name.capitalize
|
|
11
|
+
@health = player_health
|
|
12
|
+
@found_treasures = Hash.new(0)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def each_found_treasure
|
|
17
|
+
@found_treasures.each do |key, value|
|
|
18
|
+
yield (Treasure.new(key,value))
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def name=(player_name)
|
|
24
|
+
@pname = player_name.capitalize
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def to_s
|
|
28
|
+
"I am #{@name} health = #{@health}, points = #{points}, score = #{score}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def score
|
|
34
|
+
@health + @found_treasures.values.reduce(0,:+)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def <=>(other_player)
|
|
40
|
+
other_player.score <=> self.score
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def found_treasure(treasure)
|
|
44
|
+
@found_treasures[treasure.name] += treasure.points
|
|
45
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points"
|
|
46
|
+
puts "#{@name} treasures #{@found_treasures}"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def points
|
|
50
|
+
@found_treasures.values.reduce(0,:+)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def total_treasures
|
|
54
|
+
@found_treasures.size
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.from_csv(player)
|
|
58
|
+
playername, health= player.split(",")
|
|
59
|
+
Player.new(playername, Integer(health))
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
if __FILE__ == $0
|
|
69
|
+
player = Player.new("moe")
|
|
70
|
+
puts player.name
|
|
71
|
+
puts player.health
|
|
72
|
+
player.w00t
|
|
73
|
+
puts player.health
|
|
74
|
+
player.blam
|
|
75
|
+
puts player.health
|
|
76
|
+
end
|
|
77
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
Treasure = Struct.new(:name, :points)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
module TreasureTrove
|
|
6
|
+
TREASURES = [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/berserk_player'
|
|
2
|
+
module StudioGame
|
|
3
|
+
|
|
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
|
+
# or if using Rspec 3.0:
|
|
14
|
+
@player.berserk?.should be_falsey
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
it "goes berserk when w00ted more than 5 times" do
|
|
18
|
+
1.upto(6) { @player.w00t }
|
|
19
|
+
# or if using Rspec 3.0:
|
|
20
|
+
@player.berserk?.should be_truthy
|
|
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,53 @@
|
|
|
1
|
+
require 'studio_game/clumsy_player'
|
|
2
|
+
module StudioGame
|
|
3
|
+
|
|
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
|
+
expect(@player.points).to eq(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
|
+
expect(@player.points).to eq(75)
|
|
18
|
+
|
|
19
|
+
crowbar = Treasure.new(:crowbar, 400)
|
|
20
|
+
@player.found_treasure(crowbar)
|
|
21
|
+
|
|
22
|
+
expect(@player.points).to eq(275)
|
|
23
|
+
|
|
24
|
+
yielded = []
|
|
25
|
+
@player.each_found_treasure do |treasure|
|
|
26
|
+
yielded << treasure
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
expect(yielded).to eq([Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
context "with a boost factor" do
|
|
37
|
+
before do
|
|
38
|
+
@initial_health = 100
|
|
39
|
+
@boost_factor = 5
|
|
40
|
+
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "has a boost factor" do
|
|
44
|
+
@player.boost_factor.should == 5
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "gets boost factor number of w00ts when w00ted" do
|
|
48
|
+
@player.w00t
|
|
49
|
+
|
|
50
|
+
@player.health.should == @initial_health + (15 * @boost_factor)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
require 'studio_game/game'
|
|
2
|
+
require 'studio_game/die'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
|
|
6
|
+
describe Game do
|
|
7
|
+
before do
|
|
8
|
+
@game = Game.new("Knuckleheads")
|
|
9
|
+
@initial_health = 100
|
|
10
|
+
@player = Player.new("adan",@initial_health)
|
|
11
|
+
|
|
12
|
+
@game.addplayers(@player)
|
|
13
|
+
|
|
14
|
+
@rounds = Die.new.roll
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
context "w00t the player when a high (5..6) numbers is rolled " do
|
|
21
|
+
it "player roll with a high number" do
|
|
22
|
+
Die.any_instance.stub(:roll).and_return(5)
|
|
23
|
+
@game.play(@rounds)
|
|
24
|
+
|
|
25
|
+
#@player.health.should == @initial_health + 15
|
|
26
|
+
expect(@player.health).to eq(@initial_health + (@rounds*15))
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
context "skip the player when a medium (3..4) numbers is rolled " do
|
|
31
|
+
it "player skip with a medium number" do
|
|
32
|
+
Die.any_instance.stub(:roll).and_return(3)
|
|
33
|
+
@game.play(@rounds)
|
|
34
|
+
|
|
35
|
+
expect(@player.health).to eq(@initial_health)
|
|
36
|
+
# @player.health.should == @initial_health
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "blam the player when a low (1..2) numbers is rolled " do
|
|
42
|
+
it "player blam with a low number" do
|
|
43
|
+
Die.any_instance.stub(:roll).and_return(1)
|
|
44
|
+
@game.play(@rounds)
|
|
45
|
+
|
|
46
|
+
expect(@player.health).to eq(@initial_health - (@rounds * 10))
|
|
47
|
+
#@player.health.should == @initial_health - 10
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "assigns a treasure for points during a player's turn" do
|
|
53
|
+
game = Game.new("Knuckleheads")
|
|
54
|
+
player = Player.new("moe")
|
|
55
|
+
|
|
56
|
+
game.addplayers(player)
|
|
57
|
+
|
|
58
|
+
game.play(1)
|
|
59
|
+
|
|
60
|
+
expect(player.points).not_to be_zero
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it "computes total points as the sum of all player points" do
|
|
64
|
+
game = Game.new("Knuckleheads")
|
|
65
|
+
|
|
66
|
+
player1 = Player.new("moe")
|
|
67
|
+
player2 = Player.new("larry")
|
|
68
|
+
|
|
69
|
+
game.addplayers(player1)
|
|
70
|
+
game.addplayers(player2)
|
|
71
|
+
|
|
72
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
|
73
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
|
74
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
|
75
|
+
|
|
76
|
+
game.total_points.should == 500
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
require 'studio_game/player'
|
|
2
|
+
require 'studio_game/treasure_trove'
|
|
3
|
+
module StudioGame
|
|
4
|
+
|
|
5
|
+
describe Player do
|
|
6
|
+
|
|
7
|
+
before do
|
|
8
|
+
@player = Player.new("larry",100)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
it "has a Capitalized title" do
|
|
13
|
+
expect(@player.name).to eq("Larry")
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "has an initial health" do
|
|
17
|
+
|
|
18
|
+
expect(@player.health).to eq(100)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
it "computes a score as the sum of its health plus total treasure points" do
|
|
24
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
25
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
expect(@player.score).to eq(200)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
context "Player has a string representation" do
|
|
32
|
+
before do
|
|
33
|
+
@player = Player.new("larry")
|
|
34
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
35
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
it "has a string representation" do
|
|
40
|
+
puts @player
|
|
41
|
+
|
|
42
|
+
expect(@player.to_s).to eq("I am Larry health = 100, points = 100, score = 200")
|
|
43
|
+
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it "increases health by 15 when w00ted" do
|
|
48
|
+
|
|
49
|
+
@player.w00t
|
|
50
|
+
expect(@player.health).to eq(115)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
it "decreases health by 10 when blammed" do
|
|
55
|
+
|
|
56
|
+
@player.blam
|
|
57
|
+
expect(@player.health).to eq(90)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
it "can be created from a csv file" do
|
|
61
|
+
player = Player.from_csv("Adan,50")
|
|
62
|
+
expect(player.name).to eq("Adan")
|
|
63
|
+
expect(player.health).to eq(50)
|
|
64
|
+
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
it "computes points as the sum of all treasure points" do
|
|
70
|
+
expect(@player.points).to eq(0)
|
|
71
|
+
|
|
72
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
73
|
+
|
|
74
|
+
expect(@player.points).to eq(50)
|
|
75
|
+
|
|
76
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
|
77
|
+
|
|
78
|
+
expect(@player.points).to eq(450)
|
|
79
|
+
|
|
80
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
81
|
+
|
|
82
|
+
expect(@player.points).to eq(500)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context "a player has a health greater than 100" do
|
|
86
|
+
before do
|
|
87
|
+
@player = Player.new("larry",150)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it "is strong" do
|
|
91
|
+
expect(@player).to be_strong
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
context "when a player has a health less or equal to 100" do
|
|
98
|
+
before do
|
|
99
|
+
@player = Player.new("adan",100)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
it "is whimpi" do
|
|
103
|
+
expect(@player).not_to be_strong
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
it "yields each found treasure and its total points" do
|
|
110
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
111
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
112
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
113
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
114
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
115
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
116
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
117
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
118
|
+
|
|
119
|
+
yielded = []
|
|
120
|
+
@player.each_found_treasure do |treasure|
|
|
121
|
+
yielded << treasure
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
expect(yielded).to eq([
|
|
125
|
+
Treasure.new(:skillet, 200),
|
|
126
|
+
Treasure.new(:hammer, 50),
|
|
127
|
+
Treasure.new(:bottle, 25)
|
|
128
|
+
])
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require 'studio_game/treasure_trove'
|
|
2
|
+
module StudioGame
|
|
3
|
+
|
|
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
|
+
expect(@treasure.name).to eq(:hammer)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "has a points attribute" do
|
|
15
|
+
expect(@treasure.points).to eq(50)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe TreasureTrove do
|
|
21
|
+
|
|
22
|
+
it "has six treasures" do
|
|
23
|
+
expect(TreasureTrove::TREASURES.size).to eq(6)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
it "has a pie worth 5 points" do
|
|
27
|
+
expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it "has a bottle worth 25 points" do
|
|
31
|
+
expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "has a hammer worth 50 points" do
|
|
35
|
+
expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "has a skillet worth 100 points" do
|
|
39
|
+
expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "has a broomstick worth 200 points" do
|
|
43
|
+
expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
it "has a crowbar worth 400 points" do
|
|
47
|
+
expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400))
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it "has a return a random treasure" do
|
|
51
|
+
treasure = TreasureTrove.random
|
|
52
|
+
expect(TreasureTrove::TREASURES).to include(treasure)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
end
|
|
57
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: studio_game_xx
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 01.00.00
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Adan Palma
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2017-04-02 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
|
+
This gem name studio game es una gema que contiene
|
|
29
|
+
clases que permite jugar ya sea enviando en un csv los nombres de los jugadores
|
|
30
|
+
y su salud o de manera automatica. El juego se trata de que jugador mantiene mejor salud y adiciona
|
|
31
|
+
encuentra herramientas que lo hacen mas fuerte
|
|
32
|
+
email: adanpalma@hotmail.com
|
|
33
|
+
executables:
|
|
34
|
+
- studio_game
|
|
35
|
+
extensions: []
|
|
36
|
+
extra_rdoc_files: []
|
|
37
|
+
files:
|
|
38
|
+
- LICENSE
|
|
39
|
+
- README
|
|
40
|
+
- bin/high_scores.txt
|
|
41
|
+
- bin/my_favorite_players.csv
|
|
42
|
+
- bin/players.csv
|
|
43
|
+
- bin/studio_game
|
|
44
|
+
- lib/studio_game/auditable.rb
|
|
45
|
+
- lib/studio_game/berserk_player.rb
|
|
46
|
+
- lib/studio_game/clumsy_player.rb
|
|
47
|
+
- lib/studio_game/die.rb
|
|
48
|
+
- lib/studio_game/game.rb
|
|
49
|
+
- lib/studio_game/game_turn.rb
|
|
50
|
+
- lib/studio_game/loaded_die.rb
|
|
51
|
+
- lib/studio_game/playable.rb
|
|
52
|
+
- lib/studio_game/player.rb
|
|
53
|
+
- lib/studio_game/treasure_trove.rb
|
|
54
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
55
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
56
|
+
- spec/studio_game/game_spec.rb
|
|
57
|
+
- spec/studio_game/high_scores.txt
|
|
58
|
+
- spec/studio_game/player_spec.rb
|
|
59
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
60
|
+
homepage: http://www.palmagarcia.com
|
|
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.5.1
|
|
81
|
+
signing_key:
|
|
82
|
+
specification_version: 4
|
|
83
|
+
summary: This is a example gem created as a part of a pragmatic studio course I took
|
|
84
|
+
test_files:
|
|
85
|
+
- spec/studio_game/berserk_player_spec.rb
|
|
86
|
+
- spec/studio_game/clumsy_player_spec.rb
|
|
87
|
+
- spec/studio_game/game_spec.rb
|
|
88
|
+
- spec/studio_game/high_scores.txt
|
|
89
|
+
- spec/studio_game/player_spec.rb
|
|
90
|
+
- spec/studio_game/treasure_trove_spec.rb
|