yard_game 1.0.0 → 1.2.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 +4 -4
- data/README +1 -1
- data/bin/my_favorite_players.csv +5 -3
- data/bin/players.csv +6 -3
- data/bin/yard_game +21 -24
- data/lib/yard_game/auditable.rb +1 -1
- data/lib/yard_game/berserk_player.rb +12 -14
- data/lib/yard_game/clumsy_player.rb +28 -24
- data/lib/yard_game/die.rb +4 -4
- data/lib/yard_game/drunkhead_player.rb +28 -0
- data/lib/yard_game/game.rb +58 -50
- data/lib/yard_game/game_turn.rb +6 -10
- data/lib/yard_game/player.rb +36 -34
- data/lib/yard_game/{playable.rb → scorable.rb} +8 -3
- data/lib/yard_game/treasure_trove.rb +2 -1
- data/spec/yard_game/berserk_player_spec.rb +2 -3
- data/spec/yard_game/clumsy_player_spec.rb +10 -9
- data/spec/yard_game/drunkhead_player_spec.rb +24 -0
- data/spec/yard_game/game_spec.rb +14 -30
- data/spec/yard_game/player_spec.rb +31 -30
- data/spec/yard_game/treasure_trove_spec.rb +16 -7
- metadata +9 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed398bf730ea6224cd8f115dc7e7393fb43609bdcabef39275154804e1f79da7
|
4
|
+
data.tar.gz: 41f8ca6e8ac779e8da684eeee4b83f5c642c18df3e36544c0a1c6a32183c109c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 88e3614537d1a9065d92d1a8bbc6366fc37f0867acbcb579bc1dafa742e4c88a3cfa09b48c259fbcb8b7a04c361de6faa8ae9e810151afc974f5b1536ef55c26
|
7
|
+
data.tar.gz: 9b5e013ccb312066112887ae97db3273f0cbcdb7fb817d995e16fa6aed7a81d2cea75dd454d632548afa7f51086fb8a4a45db50e257941a50c872a35c220a39a
|
data/README
CHANGED
@@ -19,7 +19,7 @@ added to the player's health to gain higher scores. It involves a random die rol
|
|
19
19
|
## Setup
|
20
20
|
To run this project, install it locally.
|
21
21
|
|
22
|
-
$ gem install yard_game_1.
|
22
|
+
$ gem install yard_game_1.2.0.gem
|
23
23
|
|
24
24
|
You can load players from the command line in a CSV file. You can also run the
|
25
25
|
game without specifying a player file. A default players.csv file is packaged
|
data/bin/my_favorite_players.csv
CHANGED
data/bin/players.csv
CHANGED
data/bin/yard_game
CHANGED
@@ -1,40 +1,37 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require_relative '../lib/yard_game/player'
|
4
3
|
require_relative '../lib/yard_game/game'
|
5
|
-
require_relative '../lib/yard_game/
|
4
|
+
require_relative '../lib/yard_game/treasure_trove'
|
6
5
|
require_relative '../lib/yard_game/berserk_player'
|
6
|
+
require_relative '../lib/yard_game/clumsy_player'
|
7
|
+
require_relative '../lib/yard_game/drunkhead_player'
|
7
8
|
|
8
|
-
|
9
|
-
knuckleheads = YardGame::Game.new("knuckleheads")
|
9
|
+
knucklehead_game = YardGame::Game.new("Knuckleheads")
|
10
10
|
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
knucklehead_game.load_players(ARGV.shift || default_player_file)
|
12
|
+
|
13
|
+
berserker = YardGame::BerserkPlayer.new("jill", 50)
|
14
|
+
knucklehead_game.add_player(berserker)
|
15
|
+
|
16
|
+
clumsy = YardGame::ClumsyPlayer.new("klutz", 105, 3)
|
17
|
+
knucklehead_game.add_player(clumsy)
|
18
|
+
|
19
|
+
drunk = YardGame::DrunkheadPlayer.new("jack", 200)
|
20
|
+
knucklehead_game.add_player(drunk)
|
16
21
|
|
17
22
|
loop do
|
18
23
|
puts "\nHow many game rounds? ('quit' to exit)"
|
19
24
|
answer = gets.chomp.downcase
|
20
25
|
case answer
|
21
26
|
when /^\d+$/
|
22
|
-
|
23
|
-
when 'quit'
|
24
|
-
|
27
|
+
knucklehead_game.play(answer.to_i)
|
28
|
+
when 'quit', 'exit'
|
29
|
+
knucklehead_game.print_stats
|
30
|
+
knucklehead_game.score_board
|
25
31
|
break
|
26
|
-
else
|
32
|
+
else
|
33
|
+
puts "Please enter a number or 'quit'"
|
27
34
|
end
|
28
35
|
end
|
29
|
-
knuckleheads.save_high_scores
|
30
36
|
|
31
|
-
|
32
|
-
#chipmunks.add_player(player4)
|
33
|
-
#chipmunks.add_player(player5)
|
34
|
-
#chipmunks.add_player(player6)
|
35
|
-
#puts "Welcome to Chipmunks Game"
|
36
|
-
#puts "\nHow many game rounds? ('quit' to exit)"
|
37
|
-
#answer = gets.chomp()
|
38
|
-
#chipmunks.play(answer.to_i)
|
39
|
-
#puts "Enjoy your game"
|
40
|
-
#chipmunks.print_stats
|
37
|
+
knucklehead_game.save_high_scores
|
data/lib/yard_game/auditable.rb
CHANGED
@@ -6,7 +6,6 @@ module YardGame
|
|
6
6
|
def initialize(name, health=100)
|
7
7
|
super(name, health)
|
8
8
|
@w00t_count = 0
|
9
|
-
|
10
9
|
end
|
11
10
|
|
12
11
|
def berserk?
|
@@ -16,23 +15,22 @@ module YardGame
|
|
16
15
|
def w00t
|
17
16
|
super
|
18
17
|
@w00t_count += 1
|
19
|
-
|
18
|
+
if berserk?
|
19
|
+
puts "#{name} is berserk!"
|
20
|
+
end
|
20
21
|
end
|
21
22
|
|
22
23
|
def blam
|
23
|
-
|
24
|
-
|
25
|
-
else super
|
26
|
-
end
|
27
|
-
# Using the ternary operator instead if ? berserk? w00t else : super
|
28
|
-
# berserk? ? w00t : super
|
24
|
+
# using tenary operator
|
25
|
+
berserk? ? w00t : super
|
29
26
|
end
|
30
27
|
end
|
31
|
-
end
|
32
28
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
|
30
|
+
if __FILE__ == $0
|
31
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
32
|
+
6.times { berserker.w00t }
|
33
|
+
2.times { berserker.blam }
|
34
|
+
puts berserker.health
|
35
|
+
end
|
38
36
|
end
|
@@ -1,43 +1,47 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "player"
|
2
2
|
|
3
3
|
module YardGame
|
4
4
|
class ClumsyPlayer < Player
|
5
5
|
attr_reader :boost_factor
|
6
6
|
|
7
|
-
def initialize(name, health
|
7
|
+
def initialize(name, health, boost_factor=1)
|
8
8
|
super(name, health)
|
9
9
|
@boost_factor = boost_factor
|
10
10
|
end
|
11
11
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
12
|
+
def found_treasure(treasure)
|
13
|
+
treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
14
|
+
super #refactored with super to remove duplication
|
15
|
+
# half_treasure_points = treasure.points / 2.0
|
16
|
+
# @found_treasures[treasure.name] += half_treasure_points
|
17
|
+
|
18
|
+
# puts "#{@name} found a hammer worth #{half_treasure_points}"
|
15
19
|
end
|
16
20
|
|
17
|
-
def
|
18
|
-
|
19
|
-
super(damanged_treasure)
|
21
|
+
def w00t?
|
22
|
+
super
|
20
23
|
end
|
21
|
-
end
|
22
|
-
end
|
23
24
|
|
24
|
-
|
25
|
-
|
25
|
+
def w00t
|
26
|
+
@boost_factor.times { super }
|
27
|
+
end
|
28
|
+
end
|
26
29
|
|
27
|
-
|
28
|
-
|
29
|
-
clumsy.found_treasure(hammer)
|
30
|
-
clumsy.found_treasure(hammer)
|
30
|
+
if __FILE__ == $0
|
31
|
+
clumsy = ClumsyPlayer.new("klutz")
|
31
32
|
|
32
|
-
|
33
|
-
|
33
|
+
hammer = Treasure.new(:hammer, 50)
|
34
|
+
clumsy.found_treasure(hammer)
|
35
|
+
clumsy.found_treasure(hammer)
|
36
|
+
clumsy.found_treasure(hammer)
|
34
37
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
puts "#{clumsy.points} grand total points"
|
38
|
+
crowbar = Treasure.new(:crowbar, 400)
|
39
|
+
clumsy.found_treasure(crowbar)
|
39
40
|
|
41
|
+
clumsy.each_found_treasure do |treasure|
|
42
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
|
45
|
+
puts "#{clumsy.points} grand total points"
|
46
|
+
end
|
43
47
|
end
|
data/lib/yard_game/die.rb
CHANGED
@@ -1,10 +1,10 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative 'auditable'
|
1
|
+
require_relative "auditable"
|
3
2
|
|
4
3
|
module YardGame
|
5
4
|
class Die
|
6
5
|
include Auditable
|
7
|
-
|
6
|
+
|
7
|
+
attr_reader :number
|
8
8
|
|
9
9
|
def initialize
|
10
10
|
roll
|
@@ -13,7 +13,7 @@ module YardGame
|
|
13
13
|
def roll
|
14
14
|
@number = rand(1..6)
|
15
15
|
audit
|
16
|
-
@number
|
16
|
+
return @number
|
17
17
|
end
|
18
18
|
end
|
19
19
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative "player"
|
2
|
+
|
3
|
+
module YardGame
|
4
|
+
class DrunkheadPlayer < Player
|
5
|
+
def initialize(name, health)
|
6
|
+
super(name, health)
|
7
|
+
@drunk_points = 10
|
8
|
+
end
|
9
|
+
|
10
|
+
def points
|
11
|
+
super - @drunk_points
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
if __FILE__ ==$0
|
16
|
+
@initial_health = 90
|
17
|
+
drunk = DrunkheadPlayer.new("Harry", @initial_health)
|
18
|
+
|
19
|
+
hammer = Treasure.new(:hammer, 50)
|
20
|
+
drunk.found_treasure(hammer)
|
21
|
+
skillet = Treasure.new(:skillet, 100)
|
22
|
+
drunk.found_treasure(skillet)
|
23
|
+
broomstick = Treasure.new(:broomstick, 200)
|
24
|
+
drunk.found_treasure(broomstick)
|
25
|
+
drunk.skipped
|
26
|
+
puts "#{drunk.name} has #{drunk.points}"
|
27
|
+
end
|
28
|
+
end
|
data/lib/yard_game/game.rb
CHANGED
@@ -1,114 +1,122 @@
|
|
1
1
|
require_relative 'player'
|
2
|
+
require_relative 'die'
|
2
3
|
require_relative 'game_turn'
|
3
4
|
require_relative 'treasure_trove'
|
4
5
|
require 'csv'
|
5
6
|
|
6
7
|
module YardGame
|
7
8
|
class Game
|
9
|
+
|
8
10
|
attr_reader :title
|
9
11
|
|
10
12
|
def initialize(title)
|
11
|
-
@
|
13
|
+
@title = title
|
12
14
|
@players = []
|
13
15
|
end
|
14
16
|
|
15
|
-
|
16
|
-
|
17
|
-
# File.readlines(from_file).each do |line|
|
18
|
-
# add_player(Player.from_csv(line))
|
19
|
-
# end
|
20
|
-
# end
|
21
|
-
|
22
|
-
# Using CSV class method
|
23
|
-
def load_players(from_file)
|
24
|
-
CSV.foreach(from_file) do |row|
|
25
|
-
player = Player.new(row[0], row[1].to_i)
|
26
|
-
add_player(player)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def add_player(a_player)
|
31
|
-
@players.push(a_player) # @players << a_player
|
17
|
+
def add_player(player)
|
18
|
+
@players << player
|
32
19
|
end
|
33
20
|
|
34
21
|
def play(rounds)
|
35
|
-
puts "
|
36
|
-
|
22
|
+
puts "There are #{@players.size} players in #{@title}"
|
23
|
+
|
37
24
|
@players.each do |player|
|
38
25
|
puts player
|
39
26
|
end
|
40
27
|
|
41
28
|
treasures = TreasureTrove::TREASURES
|
42
|
-
|
29
|
+
|
30
|
+
puts "There are #{treasures.size} treasures to be found:"
|
31
|
+
|
43
32
|
treasures.each do |treasure|
|
44
33
|
puts "A #{treasure.name} is worth #{treasure.points} points"
|
45
34
|
end
|
46
35
|
|
47
|
-
1.upto(rounds) do |
|
48
|
-
|
36
|
+
1.upto(rounds) do |count|
|
37
|
+
if block_given?
|
38
|
+
break if yield
|
39
|
+
end
|
40
|
+
puts "\nRound #{count}:"
|
49
41
|
@players.each do |player|
|
50
42
|
GameTurn.take_turn(player)
|
43
|
+
puts player
|
51
44
|
end
|
52
45
|
end
|
53
46
|
end
|
54
47
|
|
55
|
-
def
|
56
|
-
puts "#{player.name}
|
48
|
+
def print_name_health(player)
|
49
|
+
puts "#{player.name} (#{player.health})"
|
57
50
|
end
|
58
51
|
|
59
52
|
def print_stats
|
60
|
-
strong_players, wimpy_players
|
61
|
-
|
62
|
-
puts "\n#{@g_title} Statistics:"
|
53
|
+
strong_players, wimpy_players = @players.partition { |player| player.strong? }
|
63
54
|
|
64
|
-
puts "\n#{
|
55
|
+
puts "\n #{title.upcase} STATISTICS:"
|
56
|
+
puts "\n #{strong_players.size} strong players:"
|
65
57
|
strong_players.each do |player|
|
66
|
-
|
58
|
+
print_name_health(player)
|
67
59
|
end
|
68
60
|
|
69
|
-
puts "\n#{wimpy_players.count} wimpy players:"
|
70
|
-
wimpy_players.each do |player|
|
71
|
-
print_name_and_health(player)
|
72
|
-
end
|
73
61
|
|
74
|
-
puts "#{
|
75
|
-
|
76
|
-
|
62
|
+
puts "\n #{wimpy_players.size} wimpy players:"
|
63
|
+
wimpy_players.each do |player|
|
64
|
+
print_name_health(player)
|
77
65
|
end
|
78
66
|
|
79
|
-
puts "\nPoints:"
|
80
67
|
@players.each do |player|
|
81
|
-
puts "#{player.name}'s point totals:"
|
68
|
+
puts "\n#{player.name}'s point totals:'"
|
82
69
|
puts "#{player.points} grand total points"
|
83
70
|
end
|
84
|
-
puts "#{total_points} total points from treasures found"
|
85
71
|
|
86
|
-
|
72
|
+
puts "\nTotal Game Treasure Points: #{total_points}"
|
73
|
+
|
74
|
+
@players.each do |player|
|
87
75
|
puts "\n#{player.name}'s point totals:"
|
88
76
|
player.each_found_treasure do |treasure|
|
89
77
|
puts "#{treasure.points} total #{treasure.name} points"
|
90
78
|
end
|
91
|
-
|
92
|
-
puts player_total_points.upcase
|
79
|
+
puts "#{player.points} grand total points"
|
93
80
|
end
|
81
|
+
|
94
82
|
end
|
95
83
|
|
96
|
-
|
97
|
-
|
98
|
-
|
84
|
+
|
85
|
+
def score_board
|
86
|
+
puts "\n#{title} High Scores:"
|
87
|
+
@players.sort.each do |player|
|
88
|
+
puts high_scores_entry(player)
|
89
|
+
end
|
90
|
+
puts "\n\n"
|
91
|
+
puts "*" * 60
|
99
92
|
end
|
100
93
|
|
94
|
+
|
101
95
|
def total_points
|
102
|
-
|
96
|
+
@players.reduce(0) do |sum, player|
|
97
|
+
sum + player.points
|
98
|
+
end
|
103
99
|
end
|
104
100
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
101
|
+
def load_players(from_file)
|
102
|
+
CSV.foreach(from_file) do |row|
|
103
|
+
player = Player.new(row[0], row[1].to_i)
|
104
|
+
add_player(player)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def save_high_scores(to_file="high_scores.txt")
|
109
|
+
File.open(to_file, 'w') do |file|
|
110
|
+
file.puts "#{@title} High Scores:" # file.puts prints or writes to file
|
108
111
|
@players.sort.each do |player|
|
109
112
|
file.puts high_scores_entry(player)
|
110
113
|
end
|
111
114
|
end
|
112
115
|
end
|
116
|
+
|
117
|
+
def high_scores_entry(player)
|
118
|
+
"#{player.name.ljust(30, ".")} #{player.score}"
|
119
|
+
end
|
120
|
+
|
113
121
|
end
|
114
122
|
end
|
data/lib/yard_game/game_turn.rb
CHANGED
@@ -1,30 +1,26 @@
|
|
1
|
-
require_relative 'die'
|
2
|
-
#require_relative 'loaded_die'
|
3
1
|
require_relative 'player'
|
2
|
+
require_relative 'die'
|
4
3
|
require_relative 'treasure_trove'
|
5
4
|
|
6
5
|
module YardGame
|
7
6
|
module GameTurn
|
8
|
-
|
9
|
-
# self refers to the module beight defined. ie. GameTurn. So we need to
|
10
|
-
# define the method with the form self.xxx.
|
7
|
+
|
11
8
|
def self.take_turn(player)
|
12
|
-
|
13
|
-
|
14
|
-
number_rolled = rolled_die.roll
|
9
|
+
die = Die.new
|
10
|
+
number_rolled = die.roll
|
15
11
|
|
16
12
|
case number_rolled
|
17
13
|
when 1..2
|
18
14
|
player.blam
|
19
15
|
when 3..4
|
20
|
-
|
16
|
+
player.skipped
|
17
|
+
#puts "#{player.name} was skipped!"
|
21
18
|
else
|
22
19
|
player.w00t
|
23
20
|
end
|
24
21
|
|
25
22
|
treasure = TreasureTrove.random
|
26
23
|
player.found_treasure(treasure)
|
27
|
-
|
28
24
|
end
|
29
25
|
end
|
30
26
|
end
|
data/lib/yard_game/player.rb
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
require_relative
|
2
|
-
require_relative
|
1
|
+
require_relative "treasure_trove"
|
2
|
+
require_relative "scorable"
|
3
3
|
|
4
4
|
module YardGame
|
5
5
|
class Player
|
6
|
-
include
|
7
|
-
|
6
|
+
include Scorable
|
7
|
+
|
8
|
+
attr_accessor :name
|
9
|
+
attr_accessor :health
|
8
10
|
|
9
11
|
def initialize(name, health=100)
|
10
12
|
@name = name.capitalize
|
@@ -12,54 +14,54 @@ module YardGame
|
|
12
14
|
@found_treasures = Hash.new(0)
|
13
15
|
end
|
14
16
|
|
15
|
-
def
|
16
|
-
|
17
|
-
|
18
|
-
end
|
17
|
+
def self.from_csv(string)
|
18
|
+
name, health = string.split(',')
|
19
|
+
Player.new(name, Integer(health))
|
19
20
|
end
|
20
21
|
|
21
22
|
|
22
|
-
def
|
23
|
-
|
23
|
+
def each_found_treasure
|
24
|
+
@found_treasures.each do |name, point|
|
25
|
+
yield Treasure.new(name, point)
|
26
|
+
end
|
24
27
|
end
|
25
28
|
|
26
29
|
def found_treasure(treasure)
|
27
|
-
@found_treasures[treasure.name
|
28
|
-
puts "#{name} found a #{treasure.name} worth #{treasure.points} points."
|
29
|
-
puts "#{name}'s treasures
|
30
|
+
@found_treasures[treasure.name] += treasure.points
|
31
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
32
|
+
puts "#{@name}'s treasures:#{@found_treasures}'"
|
30
33
|
end
|
31
34
|
|
32
|
-
def
|
33
|
-
|
35
|
+
def points
|
36
|
+
@found_treasures.values.reduce(0, :+)
|
34
37
|
end
|
35
38
|
|
36
39
|
|
37
|
-
def score
|
40
|
+
def score
|
38
41
|
@health + points
|
39
42
|
end
|
40
43
|
|
41
|
-
def
|
42
|
-
@name =
|
44
|
+
def to_s
|
45
|
+
"I'm #{@name} with a health = #{@health}, points = #{points}, and score = #{score}."
|
43
46
|
end
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
other.score <=> score
|
48
|
+
def skipped
|
49
|
+
puts "#{@name} was skipped!"
|
48
50
|
end
|
49
51
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
52
|
+
# def name=(new_name)
|
53
|
+
# @name = new_name.capitalize
|
54
|
+
# end
|
55
|
+
|
54
56
|
end
|
55
|
-
end
|
56
57
|
|
57
|
-
if __FILE__ == $0
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
58
|
+
if __FILE__ == $0
|
59
|
+
player = Player.new("moe")
|
60
|
+
puts player.name
|
61
|
+
puts player.health
|
62
|
+
player.w00t
|
63
|
+
puts player.health
|
64
|
+
player.blam
|
65
|
+
puts player.health
|
66
|
+
end
|
65
67
|
end
|
@@ -1,18 +1,23 @@
|
|
1
1
|
module YardGame
|
2
|
-
module
|
2
|
+
module Scorable
|
3
3
|
|
4
4
|
def blam
|
5
|
-
|
5
|
+
self.health -= 10
|
6
6
|
puts "#{name} got blammed!"
|
7
7
|
end
|
8
8
|
|
9
9
|
def w00t
|
10
|
-
|
10
|
+
self.health += 15
|
11
11
|
puts "#{name} got w00ted!"
|
12
12
|
end
|
13
13
|
|
14
14
|
def strong?
|
15
15
|
health > 100
|
16
16
|
end
|
17
|
+
|
18
|
+
def <=>(other_player)
|
19
|
+
other_player.score <=> score
|
20
|
+
end
|
21
|
+
|
17
22
|
end
|
18
23
|
end
|
@@ -4,7 +4,6 @@ module YardGame
|
|
4
4
|
describe BerserkPlayer do
|
5
5
|
|
6
6
|
before do
|
7
|
-
$stdout = StringIO.new
|
8
7
|
@initial_health = 50
|
9
8
|
@player = BerserkPlayer.new("berserker", @initial_health)
|
10
9
|
end
|
@@ -15,13 +14,13 @@ module YardGame
|
|
15
14
|
expect(@player.berserk?).to be_falsey
|
16
15
|
end
|
17
16
|
|
18
|
-
it "goes berserk when w00ted
|
17
|
+
it "goes berserk when w00ted up to 6 times" do
|
19
18
|
1.upto(6) { @player.w00t }
|
20
19
|
|
21
20
|
expect(@player.berserk?).to be_truthy
|
22
21
|
end
|
23
22
|
|
24
|
-
it "
|
23
|
+
it "gets w00t instead of blammed when its gone bersek" do
|
25
24
|
1.upto(6) { @player.w00t }
|
26
25
|
1.upto(2) { @player.blam }
|
27
26
|
|
@@ -3,10 +3,10 @@ require 'yard_game/clumsy_player'
|
|
3
3
|
module YardGame
|
4
4
|
describe ClumsyPlayer do
|
5
5
|
before do
|
6
|
-
@player = ClumsyPlayer.new("klutz")
|
6
|
+
@player = ClumsyPlayer.new("klutz", boost_factor=2)
|
7
7
|
end
|
8
8
|
|
9
|
-
it "only gets half the point for each treasure" do
|
9
|
+
it "only gets half the point value for each treasure" do
|
10
10
|
expect(@player.points).to eq(0)
|
11
11
|
|
12
12
|
hammer = Treasure.new(:hammer, 50)
|
@@ -22,6 +22,7 @@ module YardGame
|
|
22
22
|
expect(@player.points).to eq(275)
|
23
23
|
|
24
24
|
yielded = []
|
25
|
+
|
25
26
|
@player.each_found_treasure do |treasure|
|
26
27
|
yielded << treasure
|
27
28
|
end
|
@@ -29,22 +30,22 @@ module YardGame
|
|
29
30
|
expect(yielded).to eq([Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)])
|
30
31
|
end
|
31
32
|
|
32
|
-
context "
|
33
|
+
context "with a boost_factor" do
|
33
34
|
before do
|
35
|
+
@boost_factor = 2
|
34
36
|
@initial_health = 50
|
35
|
-
@boost_factor = 5
|
36
37
|
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
37
38
|
end
|
38
39
|
|
39
40
|
it "has a boost_factor" do
|
40
|
-
|
41
|
+
|
42
|
+
expect(@player.boost_factor).to eq(2)
|
41
43
|
end
|
42
44
|
|
43
|
-
it "gets a boost everytime its w00ted" do
|
44
|
-
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
45
45
|
|
46
|
-
|
47
|
-
|
46
|
+
it "receives a boost in health value when w00ted" do
|
47
|
+
@player.w00t
|
48
|
+
expect(@player.health).to eq(50 + (2 * 15))
|
48
49
|
end
|
49
50
|
end
|
50
51
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'yard_game/drunkhead_player'
|
2
|
+
|
3
|
+
module YardGame
|
4
|
+
describe DrunkheadPlayer do
|
5
|
+
before do
|
6
|
+
@initial_health = 90
|
7
|
+
@player = DrunkheadPlayer.new("Harry", @initial_health)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "gets 10 points deducted from points when skipped" do
|
11
|
+
|
12
|
+
hammer = Treasure.new(:hammer, 50)
|
13
|
+
@player.found_treasure(hammer)
|
14
|
+
skillet = Treasure.new(:skillet, 100)
|
15
|
+
@player.found_treasure(skillet)
|
16
|
+
broomstick = Treasure.new(:broomstick, 200)
|
17
|
+
@player.found_treasure(broomstick)
|
18
|
+
|
19
|
+
@player.skipped
|
20
|
+
expect(@player.points).to eq(350 - 10)
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/spec/yard_game/game_spec.rb
CHANGED
@@ -8,20 +8,21 @@ module YardGame
|
|
8
8
|
@game = Game.new("Knuckleheads")
|
9
9
|
|
10
10
|
@initial_health = 100
|
11
|
-
@player = Player.new("
|
11
|
+
@player = Player.new("larry", @initial_health)
|
12
12
|
|
13
13
|
@game.add_player(@player)
|
14
14
|
end
|
15
15
|
|
16
|
-
it "increases
|
16
|
+
it "increases by 15 when a higher number is rolled" do
|
17
|
+
|
17
18
|
allow_any_instance_of(Die).to receive(:roll).and_return(5)
|
18
19
|
|
19
20
|
@game.play(2)
|
20
21
|
|
21
|
-
expect(@player.health).to eq(@initial_health +
|
22
|
+
expect(@player.health).to eq(@initial_health + 15 * 2)
|
22
23
|
end
|
23
24
|
|
24
|
-
it "skips
|
25
|
+
it "skips a player when a medium number is rolled" do
|
25
26
|
allow_any_instance_of(Die).to receive(:roll).and_return(3)
|
26
27
|
|
27
28
|
@game.play(2)
|
@@ -29,30 +30,12 @@ module YardGame
|
|
29
30
|
expect(@player.health).to eq(@initial_health)
|
30
31
|
end
|
31
32
|
|
32
|
-
it "
|
33
|
+
it "reduces by 10 when a lower number is rolled" do
|
33
34
|
allow_any_instance_of(Die).to receive(:roll).and_return(1)
|
34
35
|
|
35
36
|
@game.play(2)
|
36
37
|
|
37
|
-
expect(@player.health).to eq(@initial_health -
|
38
|
-
end
|
39
|
-
|
40
|
-
context "players that are strong from their statistics" do
|
41
|
-
@game = Game.new("Knuckleheads")
|
42
|
-
|
43
|
-
@initial_health = 100
|
44
|
-
@player = Player.new("moe", @initial_health)
|
45
|
-
|
46
|
-
@game.add_player(@player)
|
47
|
-
|
48
|
-
# it "shows a strong player" do
|
49
|
-
# @game.print_stats
|
50
|
-
|
51
|
-
# expect(@player).to eq( "Moe : #{@initial_health}" )
|
52
|
-
# end
|
53
|
-
|
54
|
-
# it "shows a winpy player"
|
55
|
-
|
38
|
+
expect(@player.health).to eq(@initial_health - 10 * 2)
|
56
39
|
end
|
57
40
|
|
58
41
|
it "assigns a treasure for points during a player's turn" do
|
@@ -63,23 +46,24 @@ module YardGame
|
|
63
46
|
|
64
47
|
game.play(1)
|
65
48
|
|
66
|
-
expect(player.points).not_to
|
49
|
+
expect(player.points).not_to be_zero
|
67
50
|
end
|
68
51
|
|
69
52
|
it "computes total points as the sum of all player points" do
|
70
|
-
|
53
|
+
|
54
|
+
game = Game.new("Knuckleheads")
|
71
55
|
|
72
56
|
player1 = Player.new("moe")
|
73
57
|
player2 = Player.new("larry")
|
74
58
|
|
75
|
-
|
76
|
-
|
59
|
+
game.add_player(player1)
|
60
|
+
game.add_player(player2)
|
77
61
|
|
78
62
|
player1.found_treasure(Treasure.new(:hammer, 50))
|
79
63
|
player1.found_treasure(Treasure.new(:hammer, 50))
|
80
|
-
player2.found_treasure(Treasure.new(:
|
64
|
+
player2.found_treasure(Treasure.new(:hammer, 400))
|
81
65
|
|
82
|
-
expect(
|
66
|
+
expect(game.total_points).to eq(500)
|
83
67
|
end
|
84
68
|
end
|
85
69
|
end
|
@@ -1,66 +1,68 @@
|
|
1
1
|
require 'yard_game/player'
|
2
|
-
require 'yard_game/treasure_trove'
|
3
2
|
|
4
3
|
module YardGame
|
5
4
|
describe Player do
|
6
5
|
before do
|
7
|
-
$stdout = StringIO.new
|
8
|
-
@initial_health =
|
6
|
+
$stdout = StringIO.new
|
7
|
+
@initial_health = 60
|
9
8
|
@player = Player.new("larry", @initial_health)
|
10
|
-
|
11
9
|
end
|
12
10
|
|
13
|
-
it "has a capitalized
|
11
|
+
it "has a name that is a capitalized" do
|
12
|
+
|
14
13
|
expect(@player.name).to eq("Larry")
|
15
14
|
end
|
16
15
|
|
17
16
|
it "has an initial health" do
|
18
|
-
|
17
|
+
|
18
|
+
expect(@player.health).to eq(60)
|
19
19
|
end
|
20
20
|
|
21
21
|
it "has a string representation" do
|
22
22
|
@player.found_treasure(Treasure.new(:hammer, 50))
|
23
23
|
@player.found_treasure(Treasure.new(:hammer, 50))
|
24
24
|
|
25
|
-
expect(@player.to_s).to eq("I'm Larry with a health =
|
25
|
+
expect(@player.to_s).to eq("I'm Larry with a health = 60, points = 100, and score = 160.")
|
26
26
|
end
|
27
27
|
|
28
|
-
it "computes a score as the sum of its health and
|
28
|
+
it "computes a score as the sum of its health and points" do
|
29
29
|
@player.found_treasure(Treasure.new(:hammer, 50))
|
30
30
|
@player.found_treasure(Treasure.new(:hammer, 50))
|
31
31
|
|
32
|
-
expect(@player.score).to eq(
|
32
|
+
expect(@player.score).to eq(160)
|
33
33
|
end
|
34
34
|
|
35
|
+
|
35
36
|
it "increases health by 15 when w00ted" do
|
36
|
-
@player.w00t
|
37
37
|
|
38
|
-
|
38
|
+
@player.w00t
|
39
|
+
expect(@player.health).to eq(@initial_health + 15)
|
39
40
|
end
|
40
41
|
|
41
|
-
it "
|
42
|
-
@player.blam
|
42
|
+
it "decreases health by 10 when blammed" do
|
43
43
|
|
44
|
-
|
44
|
+
@player.blam
|
45
|
+
expect(@player.health).to eq(@initial_health - 10)
|
45
46
|
end
|
46
47
|
|
47
|
-
context "
|
48
|
+
context "with an initial health greater than 100" do
|
48
49
|
before do
|
49
50
|
@player = Player.new("larry", 150)
|
50
51
|
end
|
51
52
|
|
52
|
-
it "is strong" do
|
53
|
+
it "is a strong player" do
|
54
|
+
|
53
55
|
expect(@player).to be_strong
|
54
|
-
#@player.strong?.should be_truthy
|
55
56
|
end
|
56
57
|
end
|
57
58
|
|
58
|
-
context "
|
59
|
+
context "with an initial health of 100 of less" do
|
59
60
|
before do
|
60
|
-
|
61
|
+
player = Player.new("larry", 100)
|
61
62
|
end
|
62
63
|
|
63
64
|
it "is wimpy" do
|
65
|
+
|
64
66
|
expect(@player).not_to be_strong
|
65
67
|
end
|
66
68
|
end
|
@@ -80,6 +82,7 @@ module YardGame
|
|
80
82
|
end
|
81
83
|
|
82
84
|
it "computes points as the sum of all treasure points" do
|
85
|
+
|
83
86
|
expect(@player.points).to eq(0)
|
84
87
|
|
85
88
|
@player.found_treasure(Treasure.new(:hammer, 50))
|
@@ -105,25 +108,23 @@ module YardGame
|
|
105
108
|
@player.found_treasure(Treasure.new(:bottle, 5))
|
106
109
|
@player.found_treasure(Treasure.new(:bottle, 5))
|
107
110
|
|
108
|
-
yielded
|
109
|
-
|
111
|
+
yielded = []
|
110
112
|
@player.each_found_treasure do |treasure|
|
111
113
|
yielded << treasure
|
112
114
|
end
|
113
115
|
|
114
116
|
expect(yielded).to eq([
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
117
|
+
Treasure.new(:skillet, 200),
|
118
|
+
Treasure.new(:hammer, 50),
|
119
|
+
Treasure.new(:bottle, 25)
|
120
|
+
])
|
119
121
|
end
|
120
122
|
|
121
|
-
it "
|
122
|
-
player = Player.from_csv("
|
123
|
+
it "can be created from a CSV string" do
|
124
|
+
@player = Player.from_csv("Larry,60")
|
123
125
|
|
124
|
-
expect(player.name).to eq("
|
125
|
-
expect(player.health).to eq(
|
126
|
+
expect(@player.name).to eq("Larry")
|
127
|
+
expect(@player.health).to eq(60)
|
126
128
|
end
|
127
|
-
|
128
129
|
end
|
129
130
|
end
|
@@ -4,54 +4,63 @@ module YardGame
|
|
4
4
|
describe Treasure do
|
5
5
|
|
6
6
|
before do
|
7
|
-
@treasure = Treasure.new(:hammer, 50)
|
7
|
+
@treasure = Treasure.new(:hammer, 50 )
|
8
8
|
end
|
9
9
|
|
10
10
|
it "has a name attribute" do
|
11
|
+
|
11
12
|
expect(@treasure.name).to eq(:hammer)
|
12
13
|
end
|
13
14
|
|
14
15
|
it "has a points attribute" do
|
16
|
+
|
15
17
|
expect(@treasure.points).to eq(50)
|
16
18
|
end
|
17
|
-
|
18
19
|
end
|
19
20
|
|
21
|
+
|
20
22
|
describe TreasureTrove do
|
21
23
|
|
22
24
|
it "has six treasures" do
|
25
|
+
|
23
26
|
expect(TreasureTrove::TREASURES.size).to eq(6)
|
24
27
|
end
|
25
28
|
|
26
29
|
it "has a pie worth 5 points" do
|
30
|
+
|
27
31
|
expect(TreasureTrove::TREASURES[0]).to eq(Treasure.new(:pie, 5))
|
28
32
|
end
|
29
33
|
|
30
34
|
it "has a bottle worth 25 points" do
|
35
|
+
|
31
36
|
expect(TreasureTrove::TREASURES[1]).to eq(Treasure.new(:bottle, 25))
|
32
37
|
end
|
33
38
|
|
34
39
|
it "has a hammer worth 50 points" do
|
40
|
+
|
35
41
|
expect(TreasureTrove::TREASURES[2]).to eq(Treasure.new(:hammer, 50))
|
36
42
|
end
|
37
43
|
|
38
|
-
it "has a
|
44
|
+
it "has a skillet worth 100 points" do
|
45
|
+
|
39
46
|
expect(TreasureTrove::TREASURES[3]).to eq(Treasure.new(:skillet, 100))
|
40
47
|
end
|
41
48
|
|
42
|
-
it "has a
|
49
|
+
it "has a brownstick worth 200 points" do
|
50
|
+
|
43
51
|
expect(TreasureTrove::TREASURES[4]).to eq(Treasure.new(:broomstick, 200))
|
44
52
|
end
|
45
53
|
|
46
54
|
it "has a crowbar worth 400 points" do
|
47
|
-
|
55
|
+
|
56
|
+
expect(TreasureTrove::TREASURES[5]).to eq(Treasure.new(:crowbar, 400 ))
|
48
57
|
end
|
49
58
|
|
50
|
-
it "
|
59
|
+
it "retuurns a random treasure" do
|
60
|
+
|
51
61
|
treasure = TreasureTrove.random
|
52
62
|
|
53
63
|
expect(TreasureTrove::TREASURES).to include(treasure)
|
54
64
|
end
|
55
|
-
|
56
65
|
end
|
57
66
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yard_game
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulette Erijo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -52,7 +52,7 @@ description: |
|
|
52
52
|
## Setup
|
53
53
|
To run this project, install it locally.
|
54
54
|
|
55
|
-
$ gem install yard_game_1.
|
55
|
+
$ gem install yard_game_1.2.0.gem
|
56
56
|
|
57
57
|
You can load players from the command line in a CSV file. You can also run the
|
58
58
|
game without specifying a player file. A default players.csv file is packaged
|
@@ -75,14 +75,16 @@ files:
|
|
75
75
|
- lib/yard_game/berserk_player.rb
|
76
76
|
- lib/yard_game/clumsy_player.rb
|
77
77
|
- lib/yard_game/die.rb
|
78
|
+
- lib/yard_game/drunkhead_player.rb
|
78
79
|
- lib/yard_game/game.rb
|
79
80
|
- lib/yard_game/game_turn.rb
|
80
81
|
- lib/yard_game/loaded_die.rb
|
81
|
-
- lib/yard_game/playable.rb
|
82
82
|
- lib/yard_game/player.rb
|
83
|
+
- lib/yard_game/scorable.rb
|
83
84
|
- lib/yard_game/treasure_trove.rb
|
84
85
|
- spec/yard_game/berserk_player_spec.rb
|
85
86
|
- spec/yard_game/clumsy_player_spec.rb
|
87
|
+
- spec/yard_game/drunkhead_player_spec.rb
|
86
88
|
- spec/yard_game/game_spec.rb
|
87
89
|
- spec/yard_game/player_spec.rb
|
88
90
|
- spec/yard_game/treasure_trove_spec.rb
|
@@ -108,10 +110,12 @@ requirements: []
|
|
108
110
|
rubygems_version: 3.3.4
|
109
111
|
signing_key:
|
110
112
|
specification_version: 4
|
111
|
-
summary:
|
113
|
+
summary: An updated version of YardGame 1.0.0, a ruby game where players search for
|
114
|
+
treasures in a yard and earn points.
|
112
115
|
test_files:
|
113
116
|
- spec/yard_game/berserk_player_spec.rb
|
114
117
|
- spec/yard_game/clumsy_player_spec.rb
|
118
|
+
- spec/yard_game/drunkhead_player_spec.rb
|
115
119
|
- spec/yard_game/game_spec.rb
|
116
120
|
- spec/yard_game/player_spec.rb
|
117
121
|
- spec/yard_game/treasure_trove_spec.rb
|