knucleheads_game 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README +14 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +32 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/beserk_player.rb +33 -0
- data/lib/studio_game/clumsy_player.rb +36 -0
- data/lib/studio_game/die.rb +20 -0
- data/lib/studio_game/game.rb +108 -0
- data/lib/studio_game/game_turn.rb +21 -0
- data/lib/studio_game/loaded_die.rb +17 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +55 -0
- data/lib/studio_game/treasure_trove.rb +25 -0
- data/spec/studio_game/beserk_player_spec.rb +31 -0
- data/spec/studio_game/clumsy_player_spec.rb +58 -0
- data/spec/studio_game/game_spec.rb +63 -0
- data/spec/studio_game/player_spec.rb +124 -0
- data/spec/studio_game/treasure_trove_spec.rb +58 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8a05e12a996a45709ddd9172e3452bd9f4b5b20f
|
4
|
+
data.tar.gz: 00a274cf82efee3c421e8297880c8a56505d770c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e5248dba169649e40479aad0a239e388a0a7981bc3097a1e443298f529f715082e8fad563d58c64d68017d9e953320df60b153d96d19ac3172cd3b86effaf78f
|
7
|
+
data.tar.gz: 782f369e429e72044636bc0f13c9dfdd362846d61254026c6dca1b4e494fc32691bf933bf52b6e6c5837a08f1c91b4d8ea74b541965f90861e678df7d12b78af
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Victor Alexandre Franco Silva
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
This RubyGem contais a nice and fun game called Knucleheads (once using the code in your computer, you can call it anything! :) )
|
2
|
+
|
3
|
+
The game runs into the command-line, using just the command 'studio_game'.
|
4
|
+
You can choose the number of rounds you want to play and, when exiting, you'll receive the stats of the rounds.
|
5
|
+
You can create a '.csv' file to push new player into the game. The file must have the following structure:
|
6
|
+
|
7
|
+
---NAME----|---HEALTH--- (This is just explanatory, not to put into file)
|
8
|
+
Player-name,100
|
9
|
+
|
10
|
+
(The comma should appear into each string.)
|
11
|
+
|
12
|
+
Well what else can I say? Just...have fun, playing and using this humble code into your robust and well-tested program.
|
13
|
+
|
14
|
+
Good-bye !!!
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../lib/studio_game/game'
|
4
|
+
require_relative '../lib/studio_game/clumsy_player'
|
5
|
+
require_relative '../lib/studio_game/beserk_player'
|
6
|
+
|
7
|
+
knucleheads = StudioGame::Game.new("knucleheads")
|
8
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
9
|
+
knucleheads.load_players(ARGV.shift || default_player_file)
|
10
|
+
|
11
|
+
klutz = StudioGame::ClumsyPlayer.new("klutz", 105, 2)
|
12
|
+
beserk = StudioGame::BeserkPlayer.new("beserker", 50)
|
13
|
+
|
14
|
+
knucleheads.add_player(klutz)
|
15
|
+
knucleheads.add_player(beserk)
|
16
|
+
|
17
|
+
loop do
|
18
|
+
puts "\nHow many game rounds ? (type 'quit' to exit)"
|
19
|
+
answer = gets.chomp.downcase
|
20
|
+
case answer
|
21
|
+
when /^\d+$/
|
22
|
+
knucleheads.play(answer.to_i)
|
23
|
+
when 'quit', 'exit'
|
24
|
+
knucleheads.print_stats
|
25
|
+
knucleheads.print_score
|
26
|
+
break
|
27
|
+
else
|
28
|
+
puts "\nPlease enter a number or 'quit'..."
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
knucleheads.save_high_scores("high_scores.txt")
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class BeserkPlayer < Player
|
5
|
+
|
6
|
+
def initialize(name, health=100)
|
7
|
+
super(name, health)
|
8
|
+
@times_w00ted = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def beserk?
|
12
|
+
@times_w00ted > 5
|
13
|
+
end
|
14
|
+
|
15
|
+
def w00t
|
16
|
+
super
|
17
|
+
@times_w00ted += 1
|
18
|
+
puts "#{@name} is beserk!" if beserk?
|
19
|
+
end
|
20
|
+
|
21
|
+
def blam
|
22
|
+
beserk? ? w00t : super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
if __FILE__ == $0
|
28
|
+
beserk = BeserkPlayer.new("beserk", 105)
|
29
|
+
6.times {beserk.w00t}
|
30
|
+
2.times {beserk.blam}
|
31
|
+
puts beserk.health
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
|
6
|
+
attr_accessor :boost_factor
|
7
|
+
|
8
|
+
def initialize(name, health, boost_factor=0)
|
9
|
+
super(name, health)
|
10
|
+
@boost_factor = boost_factor
|
11
|
+
end
|
12
|
+
|
13
|
+
def found_treasure(treasure)
|
14
|
+
super(Treasure.new(treasure.name, treasure.points / 2.0))
|
15
|
+
end
|
16
|
+
|
17
|
+
def w00t
|
18
|
+
@boost_factor.times {super}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
if __FILE__ == $0
|
25
|
+
klutz = ClumsyPlayer.new("klutz", 105)
|
26
|
+
klutz.found_treasure(Treasure.new(:hammer, 50))
|
27
|
+
klutz.found_treasure(Treasure.new(:hammer, 50))
|
28
|
+
klutz.found_treasure(Treasure.new(:hammer, 50))
|
29
|
+
klutz.found_treasure(Treasure.new(:crowbar, 400))
|
30
|
+
|
31
|
+
klutz.each_found_treasure do |treasure|
|
32
|
+
puts "#{treasure.points} total #{treasure.name} points."
|
33
|
+
end
|
34
|
+
puts "\n#{klutz.points} grand total points."
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'game_turn'
|
4
|
+
require_relative 'treasure_trove'
|
5
|
+
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
module StudioGame
|
9
|
+
class Game
|
10
|
+
def initialize(title)
|
11
|
+
@title = title.capitalize
|
12
|
+
@players = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def high_score_entry(player)
|
16
|
+
"#{player.name.ljust(20, '.')} #{player.score}"
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def load_players(file)
|
21
|
+
CSV.foreach(file) do |row|
|
22
|
+
add_player(Player.new(row[0], row[1].to_i))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def save_high_scores(output_file="high_scores.txt")
|
27
|
+
File.open(output_file, "w") do |file|
|
28
|
+
file.puts "#{@title} High Scores:"
|
29
|
+
@players.sort.each do |player|
|
30
|
+
file.puts high_score_entry(player)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_player(player_name)
|
36
|
+
@players << player_name
|
37
|
+
end
|
38
|
+
|
39
|
+
def print_score
|
40
|
+
puts "\n#{@title} high scores:"
|
41
|
+
@players.sort.each do |player|
|
42
|
+
puts high_score_entry(player)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def strong_stats(strong_players)
|
47
|
+
puts "\n#{strong_players.size} strong players:"
|
48
|
+
strong_players.each do |player|
|
49
|
+
puts "#{player.name} (#{player.health})"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def wimpy_stats(wimpy_players)
|
54
|
+
puts "\n#{wimpy_players.size} wimpy players:"
|
55
|
+
wimpy_players.each do |player|
|
56
|
+
puts "#{player.name} (#{player.health})"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def total_treasure_points
|
61
|
+
@players.reduce(0) do |sum, player|
|
62
|
+
sum + player.points
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def print_stats
|
67
|
+
puts "\n#{@title}'s totals:"
|
68
|
+
puts "#{total_treasure_points} total points from treasures found."
|
69
|
+
@players.each do |player|
|
70
|
+
puts "\n#{player.name}'s point totals:"
|
71
|
+
player.each_found_treasure do |treasure|
|
72
|
+
puts "#{treasure.points} total #{treasure.name} points."
|
73
|
+
end
|
74
|
+
puts "#{player.points} GRAND TOTAL POINTS."
|
75
|
+
end
|
76
|
+
puts "\n#{@title} statistics:"
|
77
|
+
strong_players, wimpy_players = @players.partition { |player| player.strong? }
|
78
|
+
strong_stats(strong_players)
|
79
|
+
wimpy_stats(wimpy_players)
|
80
|
+
end
|
81
|
+
|
82
|
+
def play(rounds)
|
83
|
+
TreasureTrove.list
|
84
|
+
puts "\nThere are #{@players.size} players in #{@title}."
|
85
|
+
@players.each do |p|
|
86
|
+
puts p
|
87
|
+
end
|
88
|
+
1.upto(rounds) do |count|
|
89
|
+
puts "\nRound #{count}"
|
90
|
+
@players.each do |p|
|
91
|
+
GameTurn.take_turn(p)
|
92
|
+
puts p
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
if __FILE__ == $PROGRAM_NAME
|
99
|
+
game1 = Game.new("Chipmonks")
|
100
|
+
|
101
|
+
player1 = Player.new("Marcus", 100)
|
102
|
+
player2 = Player.new("Amanda", 100)
|
103
|
+
game1.add_player(player1)
|
104
|
+
game1.add_player(player2)
|
105
|
+
game1.play(10)
|
106
|
+
game1.print_stats
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,21 @@
|
|
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
|
+
case die.roll
|
10
|
+
when 1..2
|
11
|
+
player.blam
|
12
|
+
when 3..4
|
13
|
+
puts "#{player.name} was skipped."
|
14
|
+
else
|
15
|
+
player.w00t
|
16
|
+
end
|
17
|
+
treasure = TreasureTrove.random
|
18
|
+
player.found_treasure(treasure)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
|
7
|
+
include Playable
|
8
|
+
|
9
|
+
attr_accessor :name, :health
|
10
|
+
|
11
|
+
def initialize(name, health=100)
|
12
|
+
@name = name.capitalize
|
13
|
+
@health = health
|
14
|
+
@found_treasures = Hash.new(0)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"I'm #{@name}, health = #{@health}, points = #{points}, and score = #{score}."
|
19
|
+
end
|
20
|
+
|
21
|
+
def points
|
22
|
+
@found_treasures.values.reduce(0, :+)
|
23
|
+
end
|
24
|
+
|
25
|
+
def each_found_treasure
|
26
|
+
@found_treasures.each do |name, points|
|
27
|
+
yield Treasure.new(name, points)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def found_treasure(treasure)
|
32
|
+
@found_treasures[treasure.name] += treasure.points
|
33
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
34
|
+
puts "#{@name}'s treasures: #{@found_treasures}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def <=>(other_player)
|
38
|
+
other_player.score <=> score
|
39
|
+
end
|
40
|
+
|
41
|
+
def score
|
42
|
+
@health + points
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
if __FILE__ == $0
|
47
|
+
player1 = Player.new("moe", 90)
|
48
|
+
puts player1
|
49
|
+
player1.w00t
|
50
|
+
player1.w00t
|
51
|
+
puts "#{player1.name}'s health is: #{player1.health}."
|
52
|
+
player1.blam
|
53
|
+
puts "#{player1.name}'s health is: #{player1.health}."
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,25 @@
|
|
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
|
+
def self.list
|
19
|
+
puts "There are #{TREASURES.size} treasures to be found:"
|
20
|
+
TREASURES.each do |treasure|
|
21
|
+
puts "A #{treasure.name} is worth #{treasure.points} points."
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'studio_game/beserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe BeserkPlayer do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@initial_health = 50
|
8
|
+
@beserker = BeserkPlayer.new("beserker", @initial_health)
|
9
|
+
$stdout = StringIO.new
|
10
|
+
end
|
11
|
+
|
12
|
+
it "does not go beserk when w00ted up to five times" do
|
13
|
+
1.upto(5) {@beserker.w00t}
|
14
|
+
|
15
|
+
expect(@beserker.beserk?).to be_falsey
|
16
|
+
end
|
17
|
+
|
18
|
+
it "goes beserk when w00t more than five times" do
|
19
|
+
1.upto(6) {@beserker.w00t}
|
20
|
+
|
21
|
+
expect(@beserker.beserk?).to be_truthy
|
22
|
+
end
|
23
|
+
|
24
|
+
it "gets w00ted instead of blammed when it's beserk" do
|
25
|
+
1.upto(6) {@beserker.w00t}
|
26
|
+
1.upto(2) {@beserker.blam}
|
27
|
+
|
28
|
+
expect(@beserker.health).to eq(@initial_health + 8 * 15)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe ClumsyPlayer do
|
5
|
+
|
6
|
+
before do
|
7
|
+
$stdout = StringIO.new
|
8
|
+
@clumsy_player = ClumsyPlayer.new("klutz", 105)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "damages a treasure receiving half of the points" do
|
12
|
+
expect(@clumsy_player.points).to eq(0)
|
13
|
+
|
14
|
+
@clumsy_player.found_treasure(Treasure.new(:hammer, 50))
|
15
|
+
@clumsy_player.found_treasure(Treasure.new(:hammer, 50))
|
16
|
+
@clumsy_player.found_treasure(Treasure.new(:hammer, 50))
|
17
|
+
|
18
|
+
expect(@clumsy_player.points).to eq(75)
|
19
|
+
|
20
|
+
@clumsy_player.found_treasure(Treasure.new(:crowbar, 400))
|
21
|
+
@clumsy_player.found_treasure(Treasure.new(:skillet, 100))
|
22
|
+
@clumsy_player.found_treasure(Treasure.new(:crowbar, 400))
|
23
|
+
|
24
|
+
expect(@clumsy_player.points).to eq(525)
|
25
|
+
|
26
|
+
yielded = []
|
27
|
+
@clumsy_player.each_found_treasure do |treasure|
|
28
|
+
yielded << treasure
|
29
|
+
end
|
30
|
+
|
31
|
+
expect(yielded).to eq([
|
32
|
+
Treasure.new(:hammer, 75),
|
33
|
+
Treasure.new(:crowbar, 400),
|
34
|
+
Treasure.new(:skillet, 50)
|
35
|
+
])
|
36
|
+
end
|
37
|
+
|
38
|
+
context "with a boost factor" do
|
39
|
+
|
40
|
+
before do
|
41
|
+
@initial_health = 105
|
42
|
+
@boost_factor = 5
|
43
|
+
@clumsy = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a boost factor" do
|
47
|
+
expect(@clumsy.boost_factor).to eq(5)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "is w00ted up to the boost factor" do
|
51
|
+
@clumsy.w00t
|
52
|
+
|
53
|
+
expect(@clumsy.health).to eq(@initial_health + (@boost_factor * 15))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
require 'studio_game/die'
|
3
|
+
|
4
|
+
require 'csv'
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
describe Game do
|
8
|
+
before do
|
9
|
+
@game = Game.new("Knuckleheads")
|
10
|
+
|
11
|
+
@initial_health = 100
|
12
|
+
@player = Player.new("moe", @initial_health)
|
13
|
+
@player2 = Player.new("larry", 90)
|
14
|
+
|
15
|
+
@game.add_player(@player)
|
16
|
+
@game.add_player(@player2)
|
17
|
+
$stdout = StringIO.new
|
18
|
+
end
|
19
|
+
|
20
|
+
it "assigns a treasure for points during a player's turn" do
|
21
|
+
@game.play(1)
|
22
|
+
|
23
|
+
expect(@player.points).not_to be_zero
|
24
|
+
end
|
25
|
+
|
26
|
+
it "w00ts the player when a high number is rolled" do
|
27
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(5)
|
28
|
+
|
29
|
+
@game.play(3)
|
30
|
+
|
31
|
+
expect(@player.health).to eq(@initial_health + 15 * 3)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "skips the player when a medium number is rolled" do
|
35
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
36
|
+
|
37
|
+
@game.play(3)
|
38
|
+
|
39
|
+
expect(@player.health).to eq(@initial_health)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "formats the high score entry" do
|
43
|
+
string = @game.high_score_entry(@player)
|
44
|
+
|
45
|
+
expect(string).to eq("#{@player.name.ljust(20, '.')} #{@player.score}")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "blams the player when a lower number is rolled" do
|
49
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(1)
|
50
|
+
|
51
|
+
@game.play(3)
|
52
|
+
|
53
|
+
expect(@player.health).to eq(@initial_health - 10 * 3)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "computs total points as the sum of all players points" do
|
57
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
58
|
+
@player2.found_treasure(Treasure.new(:crowbar, 400))
|
59
|
+
|
60
|
+
expect(@game.total_treasure_points).to eq(450)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
describe Player do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@initial_health = 150
|
9
|
+
@player = Player.new("larry", @initial_health)
|
10
|
+
$stdout = StringIO.new
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a capitalized name" do
|
14
|
+
expect(@player.name).to eq("Larry")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has an initial health" do
|
18
|
+
expect(@player.health).to eq(@initial_health)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "yields each found treasure and its total points" do
|
22
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
23
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
24
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
25
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
26
|
+
@player.found_treasure(Treasure.new(:broomstick, 200))
|
27
|
+
|
28
|
+
yielded = []
|
29
|
+
|
30
|
+
@player.each_found_treasure do |treasure|
|
31
|
+
yielded << treasure
|
32
|
+
end
|
33
|
+
|
34
|
+
expect(yielded).to eq([
|
35
|
+
Treasure.new(:hammer, 100),
|
36
|
+
Treasure.new(:skillet, 200),
|
37
|
+
Treasure.new(:broomstick, 200)
|
38
|
+
])
|
39
|
+
end
|
40
|
+
|
41
|
+
it "computes points as the sum of all found treasures" do
|
42
|
+
expect(@player.points).to eq(0)
|
43
|
+
|
44
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
45
|
+
|
46
|
+
expect(@player.points).to eq(50)
|
47
|
+
|
48
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
49
|
+
|
50
|
+
expect(@player.points).to eq(450)
|
51
|
+
|
52
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
53
|
+
|
54
|
+
expect(@player.points).to eq(500)
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has a string representation" do
|
58
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
59
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
60
|
+
|
61
|
+
expect(@player.to_s).to eq("I'm #{@player.name}, health = #{@player.health}, points = 450, and score = #{@player.score}.")
|
62
|
+
end
|
63
|
+
|
64
|
+
it "computes a score as the sum of its health and points" do
|
65
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
66
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
67
|
+
|
68
|
+
expect(@player.score).to eq(450 + @initial_health)
|
69
|
+
end
|
70
|
+
|
71
|
+
it "increases the health by 15 when w00ted" do
|
72
|
+
@player.w00t
|
73
|
+
|
74
|
+
expect(@player.health).to eq(@initial_health + 15)
|
75
|
+
end
|
76
|
+
|
77
|
+
it "decreases the health by 10 when blammed" do
|
78
|
+
@player.blam
|
79
|
+
|
80
|
+
expect(@player.health).to eq(@initial_health - 10)
|
81
|
+
end
|
82
|
+
|
83
|
+
context "player has an initial health higher than 100" do
|
84
|
+
before do
|
85
|
+
@initial_health = 150
|
86
|
+
@player = Player.new("larry", @initial_health)
|
87
|
+
end
|
88
|
+
|
89
|
+
it "is strong" do
|
90
|
+
@player.strong?
|
91
|
+
|
92
|
+
expect(@player).to be_strong
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "player has an initial health of 100" do
|
97
|
+
before do
|
98
|
+
@initial_health = 100
|
99
|
+
@player = Player.new("larry", @initial_health)
|
100
|
+
end
|
101
|
+
|
102
|
+
it "is not strong" do
|
103
|
+
@player.strong?
|
104
|
+
|
105
|
+
expect(@player).not_to be_strong
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
context "in a collection of players" do
|
110
|
+
|
111
|
+
before do
|
112
|
+
@player1 = Player.new("moe", 80)
|
113
|
+
@player2 = Player.new("curly", 90)
|
114
|
+
@player3 = Player.new("larry", 100)
|
115
|
+
|
116
|
+
@players = [@player1, @player2, @player3]
|
117
|
+
end
|
118
|
+
|
119
|
+
it "is sorted by decreased order" do
|
120
|
+
expect(@players.sort).to eq([@player3, @player2, @player1])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,58 @@
|
|
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
|
+
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
|
+
describe TreasureTrove do
|
19
|
+
|
20
|
+
it "has an array holding treasure structs" do
|
21
|
+
expect(TreasureTrove::TREASURES.size).to eq(6)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "has a pie treasure of 5 points" do
|
25
|
+
expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a bottle treasure of 25 points" do
|
29
|
+
expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
|
30
|
+
end
|
31
|
+
|
32
|
+
it "has a hammer treasure of 50 points" do
|
33
|
+
expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
|
34
|
+
end
|
35
|
+
|
36
|
+
it "has a skillet treasure of 100 points" do
|
37
|
+
expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
|
38
|
+
end
|
39
|
+
|
40
|
+
it "has a broomstick treasure of 200 points" do
|
41
|
+
expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
|
42
|
+
end
|
43
|
+
|
44
|
+
it "has a crowbar treasure of 400 points" do
|
45
|
+
expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400))
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when finding a treasure" do
|
49
|
+
|
50
|
+
it "chooses a random treasure from the array" do
|
51
|
+
treasure = TreasureTrove.random
|
52
|
+
|
53
|
+
expect(TreasureTrove::TREASURES).to include(treasure)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: knucleheads_game
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Victor Alexandre Franco Silva
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-01 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 RubyGem contais a nice and fun game called Knucleheads (once using the code in your computer, you can call it anything! :) )
|
29
|
+
|
30
|
+
The game runs into the command-line, using just the command 'studio_game'.
|
31
|
+
You can choose the number of rounds you want to play and, when exiting, you'll receive the stats of the rounds.
|
32
|
+
You can create a '.csv' file to push new player into the game. The file must have the following structure:
|
33
|
+
|
34
|
+
---NAME----|---HEALTH--- (This is just explanatory, not to put into file)
|
35
|
+
Player-name,100
|
36
|
+
|
37
|
+
(The comma should appear into each string.)
|
38
|
+
|
39
|
+
Well what else can I say? Just...have fun, playing and using this humble code into your robust and well-tested program.
|
40
|
+
|
41
|
+
Good-bye !!!
|
42
|
+
email: victor.alexandrefs@gmail.com
|
43
|
+
executables:
|
44
|
+
- studio_game
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- LICENSE
|
49
|
+
- README
|
50
|
+
- bin/players.csv
|
51
|
+
- bin/studio_game
|
52
|
+
- lib/studio_game/auditable.rb
|
53
|
+
- lib/studio_game/beserk_player.rb
|
54
|
+
- lib/studio_game/clumsy_player.rb
|
55
|
+
- lib/studio_game/die.rb
|
56
|
+
- lib/studio_game/game.rb
|
57
|
+
- lib/studio_game/game_turn.rb
|
58
|
+
- lib/studio_game/loaded_die.rb
|
59
|
+
- lib/studio_game/playable.rb
|
60
|
+
- lib/studio_game/player.rb
|
61
|
+
- lib/studio_game/treasure_trove.rb
|
62
|
+
- spec/studio_game/beserk_player_spec.rb
|
63
|
+
- spec/studio_game/clumsy_player_spec.rb
|
64
|
+
- spec/studio_game/game_spec.rb
|
65
|
+
- spec/studio_game/player_spec.rb
|
66
|
+
- spec/studio_game/treasure_trove_spec.rb
|
67
|
+
homepage: http://github.com/victorfranco
|
68
|
+
licenses:
|
69
|
+
- MIT
|
70
|
+
metadata: {}
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options: []
|
73
|
+
require_paths:
|
74
|
+
- lib
|
75
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '1.9'
|
80
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
requirements: []
|
86
|
+
rubyforge_project:
|
87
|
+
rubygems_version: 2.4.8
|
88
|
+
signing_key:
|
89
|
+
specification_version: 4
|
90
|
+
summary: A command-line text game
|
91
|
+
test_files:
|
92
|
+
- spec/studio_game/beserk_player_spec.rb
|
93
|
+
- spec/studio_game/treasure_trove_spec.rb
|
94
|
+
- spec/studio_game/clumsy_player_spec.rb
|
95
|
+
- spec/studio_game/game_spec.rb
|
96
|
+
- spec/studio_game/player_spec.rb
|