studio_game_421 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +19 -0
- data/README.md +2 -0
- data/bin/high_scores.txt +6 -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/berserk_player.rb +36 -0
- data/lib/studio_game/clumsy_player.rb +39 -0
- data/lib/studio_game/die.rb +15 -0
- data/lib/studio_game/fave_players.csv +3 -0
- data/lib/studio_game/game.rb +89 -0
- data/lib/studio_game/game_turn.rb +23 -0
- data/lib/studio_game/highscores.csv +6 -0
- data/lib/studio_game/loaded_die.rb +16 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +65 -0
- data/lib/studio_game/print_players.rb +7 -0
- data/lib/studio_game/spec_helper.rb +10 -0
- data/lib/studio_game/treasure_trove.rb +18 -0
- data/spec/studio_game/berserk_player_spec.rb +33 -0
- data/spec/studio_game/clumsy_player_spec.rb +41 -0
- data/spec/studio_game/game_spec.rb +63 -0
- data/spec/studio_game/player_spec.rb +126 -0
- data/spec/studio_game/treasure_trove_spec.rb +54 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 79de1e241ba3f7f0509417ac866b8484b8431d0915c2525fe5795739b97a581c
|
4
|
+
data.tar.gz: 9bc10703448e0b717c51434b36985e620398b138f3314844b8a4ba5d82cc122d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cdc92d32f8ec2aee41eb93d192beffbdf198c7611fa474e05d2ee061ed15fabb931231426f09b6ab5b890663461bb23bdb8e4d03d5ba46a9ec07adced7a74440
|
7
|
+
data.tar.gz: ba9a8a72fa61470c8880390c325ce95eed329de0caa275f73ae837fd13345720f0166faaf3ee35bca330d9f54b9d9c4aff44585256b0ebd5ecf9f084283ce683
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) <year> <copyright holders>
|
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.md
ADDED
data/bin/high_scores.txt
ADDED
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/player'
|
5
|
+
require_relative '../lib/studio_game/clumsy_player'
|
6
|
+
require_relative '../lib/studio_game/berserk_player'
|
7
|
+
|
8
|
+
knuckleheads = StudioGame::Game.new("Knuckleheads")
|
9
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
10
|
+
knuckleheads.load_players(ARGV.shift || default_player_file)
|
11
|
+
knuckleheads.add_player(StudioGame::ClumsyPlayer.new("klutz", 105, 5))
|
12
|
+
knuckleheads.add_player(StudioGame::BerserkPlayer.new("berserker", 100))
|
13
|
+
|
14
|
+
# knuckleheads.play(2) do
|
15
|
+
# knuckleheads.total_points >= 2000
|
16
|
+
# end
|
17
|
+
|
18
|
+
loop do
|
19
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
20
|
+
rounds = gets.chomp.downcase
|
21
|
+
case rounds
|
22
|
+
when /^\d+$/
|
23
|
+
knuckleheads.play(rounds.to_i)
|
24
|
+
when 'quit', 'exit'
|
25
|
+
knuckleheads.print_stats
|
26
|
+
break
|
27
|
+
else
|
28
|
+
puts "Please enter a number or 'quit'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
knuckleheads.save_high_scores
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
def initialize(name, health=100)
|
6
|
+
super(name, health)
|
7
|
+
@w00ts = 0
|
8
|
+
end
|
9
|
+
|
10
|
+
def berserk?
|
11
|
+
@w00ts > 5
|
12
|
+
end
|
13
|
+
|
14
|
+
def w00t
|
15
|
+
super
|
16
|
+
@w00ts += 1
|
17
|
+
if berserk?
|
18
|
+
puts "#{@name} is berserk!"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def blam
|
23
|
+
if berserk?
|
24
|
+
w00t
|
25
|
+
else
|
26
|
+
super
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if __FILE__ == $0
|
33
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
34
|
+
1.upto(5) { berserker.w00t}
|
35
|
+
puts berserker.berserk?
|
36
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
attr_reader :boost
|
6
|
+
|
7
|
+
def initialize(name, health=100, boost)
|
8
|
+
super(name, health)
|
9
|
+
@boost = boost
|
10
|
+
end
|
11
|
+
def found_treasure(treasure)
|
12
|
+
damaged_treasure = Treasure.new(treasure.name, treasure.points / 2.0)
|
13
|
+
super(damaged_treasure)
|
14
|
+
end
|
15
|
+
|
16
|
+
def w00t
|
17
|
+
@boost.times do
|
18
|
+
super
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
if __FILE__ == $0
|
25
|
+
clumsy = ClumsyPlayer.new("klutz")
|
26
|
+
|
27
|
+
hammer = Treasure.new(:hammer, 50)
|
28
|
+
clumsy.found_treasure(hammer)
|
29
|
+
clumsy.found_treasure(hammer)
|
30
|
+
clumsy.found_treasure(hammer)
|
31
|
+
|
32
|
+
crowbar = Treasure.new(:crowbar, 400)
|
33
|
+
clumsy.found_treasure(crowbar)
|
34
|
+
|
35
|
+
clumsy.each_found_treasure do |treasure|
|
36
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
37
|
+
end
|
38
|
+
puts "#{clumsy.points} grand total points"
|
39
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
require_relative 'die'
|
3
|
+
require_relative 'game_turn'
|
4
|
+
require_relative 'print_players'
|
5
|
+
require_relative 'treasure_trove'
|
6
|
+
require 'csv'
|
7
|
+
|
8
|
+
module StudioGame
|
9
|
+
class Game
|
10
|
+
attr_reader :title
|
11
|
+
|
12
|
+
def initialize(title)
|
13
|
+
@title = title
|
14
|
+
@players = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def load_players(from_file)
|
18
|
+
# File.readlines(from_file).each do |line|
|
19
|
+
# player = Player.parse(line)
|
20
|
+
# add_player(player)
|
21
|
+
# end
|
22
|
+
CSV.foreach(from_file) do |line|
|
23
|
+
player = Player.new(line[0], line[1].to_i)
|
24
|
+
add_player(player)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def save_high_scores(to_file = File.join(File.dirname(__FILE__), 'highscores.csv'))
|
29
|
+
File.open(to_file, "w") do |file|
|
30
|
+
file.puts "#{@title} High Scores:"
|
31
|
+
@players.sort.each { |player| file.puts player.format_score }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_player(player)
|
36
|
+
@players << player
|
37
|
+
end
|
38
|
+
|
39
|
+
def play(rounds)
|
40
|
+
puts "There are #{@players.size} players in #{@title}:"
|
41
|
+
|
42
|
+
@players.each do |player|
|
43
|
+
puts player
|
44
|
+
end
|
45
|
+
|
46
|
+
treasures = TreasureTrove::TREASURES
|
47
|
+
puts "\nThere are #{treasures.size} treasures to be found:"
|
48
|
+
treasures.each { |treasure| puts "A #{treasure.name} is worth #{treasure.points} points" }
|
49
|
+
|
50
|
+
1.upto(rounds) do |round|
|
51
|
+
if block_given?
|
52
|
+
break if yield
|
53
|
+
end
|
54
|
+
puts "\nRound #{round}:"
|
55
|
+
@players.each do |player|
|
56
|
+
GameTurn.take_turn(player)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def total_points
|
62
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
63
|
+
end
|
64
|
+
|
65
|
+
def print_stats
|
66
|
+
strong_players, wimpy_players = @players.partition { |player| player.strong? }
|
67
|
+
puts "\n#{@title} Statistics:"
|
68
|
+
|
69
|
+
puts "\n#{strong_players.size} strong players:"
|
70
|
+
PrintPlayers.print(strong_players)
|
71
|
+
|
72
|
+
puts "\n#{wimpy_players.size} wimpy players:"
|
73
|
+
PrintPlayers.print(wimpy_players)
|
74
|
+
|
75
|
+
puts "\n#{@title} High Scores:"
|
76
|
+
@players.sort.each { |player| puts player.format_score }
|
77
|
+
|
78
|
+
@players.sort.each do |player|
|
79
|
+
puts "\n#{player.name}'s point totals:"
|
80
|
+
player.each_found_treasure do |treasure|
|
81
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
82
|
+
end
|
83
|
+
puts "#{player.points} grand total points"
|
84
|
+
end
|
85
|
+
|
86
|
+
puts "\n#{total_points} total points from treasures found"
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require_relative "die"
|
2
|
+
require_relative "loaded_die"
|
3
|
+
require_relative "treasure_trove"
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
module GameTurn
|
7
|
+
def self.take_turn(player)
|
8
|
+
number_rolled = Die.new.roll
|
9
|
+
|
10
|
+
case number_rolled
|
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
|
+
|
19
|
+
treasure = TreasureTrove.random
|
20
|
+
player.found_treasure(treasure)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require_relative "treasure_trove"
|
2
|
+
require_relative "playable"
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
include Playable
|
7
|
+
|
8
|
+
attr_accessor :health
|
9
|
+
attr_accessor :name, :found_treasures
|
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} with health = #{@health}, points = #{points} and score = #{score}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.parse(csv_string)
|
22
|
+
name, health = csv_string.split(',')
|
23
|
+
Player.new(name, Integer(health))
|
24
|
+
end
|
25
|
+
|
26
|
+
def score
|
27
|
+
@health + points
|
28
|
+
end
|
29
|
+
|
30
|
+
def format_score
|
31
|
+
"#{@name.ljust(20, '.')} #{score}"
|
32
|
+
end
|
33
|
+
|
34
|
+
def <=>(other_player)
|
35
|
+
other_player.score <=> score
|
36
|
+
end
|
37
|
+
|
38
|
+
def found_treasure(treasure)
|
39
|
+
@found_treasures[treasure.name] += treasure.points
|
40
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points} points."
|
41
|
+
puts "#{@name}'s treasures: #{@found_treasures}"
|
42
|
+
end
|
43
|
+
|
44
|
+
def points
|
45
|
+
@found_treasures.values.reduce(0, :+)
|
46
|
+
end
|
47
|
+
|
48
|
+
def each_found_treasure
|
49
|
+
@found_treasures.each do |name, points|
|
50
|
+
yield Treasure.new(name, points)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
if __FILE__ == $0
|
57
|
+
player = Player.new("moe")
|
58
|
+
puts player.name
|
59
|
+
puts player.health
|
60
|
+
player.w00t
|
61
|
+
puts player.health
|
62
|
+
player.blam
|
63
|
+
puts player.health
|
64
|
+
puts player
|
65
|
+
end
|
@@ -0,0 +1,18 @@
|
|
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
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
require 'studio_game/spec_helper'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
describe BerserkPlayer do
|
6
|
+
|
7
|
+
before do
|
8
|
+
$stdout = StringIO.new
|
9
|
+
@initial_health = 50
|
10
|
+
@player = BerserkPlayer.new("berserker", @initial_health)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "does not go berserk when w00ted up to 5 times" do
|
14
|
+
1.upto(5) { @player.w00t }
|
15
|
+
|
16
|
+
@player.berserk?.should be_falsey
|
17
|
+
end
|
18
|
+
|
19
|
+
it "goes berserk when w00ted more than 5 times" do
|
20
|
+
1.upto(6) { @player.w00t }
|
21
|
+
|
22
|
+
@player.berserk?.should be_truthy
|
23
|
+
end
|
24
|
+
|
25
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
26
|
+
1.upto(6) { @player.w00t }
|
27
|
+
1.upto(2) { @player.blam }
|
28
|
+
|
29
|
+
@player.health.should == @initial_health + (8 * 15)
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
require 'studio_game/spec_helper'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
describe ClumsyPlayer do
|
7
|
+
before do
|
8
|
+
$stdout = StringIO.new
|
9
|
+
@player = ClumsyPlayer.new("klutz", 100, 10)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "only gets half the point value for each treasure" do
|
13
|
+
@player.points.should == 0
|
14
|
+
|
15
|
+
hammer = Treasure.new(:hammer, 50)
|
16
|
+
@player.found_treasure(hammer)
|
17
|
+
@player.found_treasure(hammer)
|
18
|
+
@player.found_treasure(hammer)
|
19
|
+
|
20
|
+
@player.points.should == 75
|
21
|
+
|
22
|
+
crowbar = Treasure.new(:crowbar, 400)
|
23
|
+
@player.found_treasure(crowbar)
|
24
|
+
|
25
|
+
@player.points.should == 275
|
26
|
+
|
27
|
+
yielded = []
|
28
|
+
@player.each_found_treasure do |treasure|
|
29
|
+
yielded << treasure
|
30
|
+
end
|
31
|
+
|
32
|
+
yielded.should == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "gets w00ted the number of times equal to the w00t factor" do
|
36
|
+
@player.w00t
|
37
|
+
@player.health.should == 100 + 150
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
require 'studio_game/spec_helper'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
describe Game do
|
6
|
+
before do
|
7
|
+
$stdout = StringIO.new
|
8
|
+
@game = Game.new("Knuckleheads")
|
9
|
+
|
10
|
+
@initial_health = 100
|
11
|
+
@player = Player.new("moe", @initial_health)
|
12
|
+
@rounds = 3
|
13
|
+
|
14
|
+
@game.add_player(@player)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'w00ts when high number is rolled' do
|
18
|
+
Die.any_instance.stub(:roll).and_return(5)
|
19
|
+
|
20
|
+
@game.play(@rounds)
|
21
|
+
|
22
|
+
@player.health.should == @initial_health + (@rounds * 15)
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'skips the player when medium number is rolled' do
|
26
|
+
Die.any_instance.stub(:roll).and_return(3)
|
27
|
+
|
28
|
+
@game.play(@rounds)
|
29
|
+
|
30
|
+
@player.health.should == @initial_health
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'blams the player when a low number is rolled' do
|
34
|
+
Die.any_instance.stub(:roll).and_return(2)
|
35
|
+
|
36
|
+
@game.play(@rounds)
|
37
|
+
|
38
|
+
@player.health.should == @initial_health - (@rounds * 10)
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'assigns a treasure for points during a player\'s turn' do
|
42
|
+
@game.play(1)
|
43
|
+
|
44
|
+
@player.points.should_not be_zero
|
45
|
+
end
|
46
|
+
|
47
|
+
it "computes total points as the sum of all player points" do
|
48
|
+
game = Game.new("Knuckleheads")
|
49
|
+
|
50
|
+
player1 = Player.new("moe")
|
51
|
+
player2 = Player.new("larry")
|
52
|
+
|
53
|
+
game.add_player(player1)
|
54
|
+
game.add_player(player2)
|
55
|
+
|
56
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
57
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
58
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
59
|
+
|
60
|
+
game.total_points.should == 500
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
require 'studio_game/spec_helper'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
describe Player do
|
7
|
+
before do
|
8
|
+
$stdout = StringIO.new
|
9
|
+
@initial_health = 150
|
10
|
+
@player = Player.new("moe", @initial_health)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a capitalized name" do
|
14
|
+
@player.name.should == "Moe"
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has an initial health" do
|
18
|
+
@player.health.should == 150
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has a string representation" do
|
22
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
23
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
24
|
+
|
25
|
+
@player.to_s.should == "I'm Moe with health = 150, points = 100 and score = 250"
|
26
|
+
end
|
27
|
+
|
28
|
+
it "computes a score as the sum of its health and points" do
|
29
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
30
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
31
|
+
|
32
|
+
@player.score.should == 250
|
33
|
+
end
|
34
|
+
|
35
|
+
it "increases health by 15 when w00ted" do
|
36
|
+
@player.w00t
|
37
|
+
@player.health.should == (@initial_health + 15)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "decreases health by 10 when blammed" do
|
41
|
+
@player.blam
|
42
|
+
@player.health.should == (@initial_health - 10)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'computes points as a sum of all treasure points' do
|
46
|
+
@player.points.should == 0
|
47
|
+
|
48
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
49
|
+
|
50
|
+
@player.points.should == 50
|
51
|
+
|
52
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
53
|
+
|
54
|
+
@player.points.should == 450
|
55
|
+
|
56
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
57
|
+
|
58
|
+
@player.points.should == 500
|
59
|
+
end
|
60
|
+
|
61
|
+
it "yields each found treasure and its total points" do
|
62
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
63
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
64
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
65
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
66
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
67
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
68
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
69
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
70
|
+
|
71
|
+
yielded = []
|
72
|
+
@player.each_found_treasure do |treasure|
|
73
|
+
yielded << treasure
|
74
|
+
end
|
75
|
+
|
76
|
+
yielded.should == [
|
77
|
+
Treasure.new(:skillet, 200),
|
78
|
+
Treasure.new(:hammer, 50),
|
79
|
+
Treasure.new(:bottle, 25)
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'creates new player from csv string' do
|
84
|
+
player = Player.parse('Moe, 150')
|
85
|
+
player.name.should == 'Moe'
|
86
|
+
player.score.should == 150
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
context "with a health greater than 100" do
|
91
|
+
before do
|
92
|
+
@player = Player.new("moe", 150)
|
93
|
+
end
|
94
|
+
|
95
|
+
it "is strong" do
|
96
|
+
@player.should be_strong
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context 'with a health less than or equal to 100' do
|
101
|
+
before do
|
102
|
+
@player = Player.new("moe", 100)
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'is wimpy' do
|
106
|
+
@player.should_not be_strong
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
context 'when in a collection of players' do
|
111
|
+
before do
|
112
|
+
@player1 = Player.new("moe", 100)
|
113
|
+
@player2 = Player.new("larry", 200)
|
114
|
+
@player3 = Player.new("curly", 300)
|
115
|
+
|
116
|
+
@players = [@player1, @player2, @player3]
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'is sorted by decreasing order' do
|
120
|
+
@players.sort.should == [@player3, @player2, @player1]
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'studio_game/spec_helper'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
describe Treasure do
|
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
|
+
end
|
18
|
+
|
19
|
+
describe TreasureTrove do
|
20
|
+
it 'has six treasures' do
|
21
|
+
TreasureTrove::TREASURES.size.should == 6
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'has a pie worth 5 points' do
|
25
|
+
TreasureTrove::TREASURES[0].should == Treasure.new(:pie, 5)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'has a bottle worth 25 points' do
|
29
|
+
TreasureTrove::TREASURES[1].should == Treasure.new(:bottle, 25)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'has a hammer worth 50 points' do
|
33
|
+
TreasureTrove::TREASURES[2].should == Treasure.new(:hammer, 50)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'has a skillet worth 100 points' do
|
37
|
+
TreasureTrove::TREASURES[3].should == Treasure.new(:skillet, 100)
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'has a broomstick worth 200 points' do
|
41
|
+
TreasureTrove::TREASURES[4].should == Treasure.new(:broomstick, 200)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'has a crowbar worth 400 points' do
|
45
|
+
TreasureTrove::TREASURES[5].should == Treasure.new(:crowbar, 400)
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'returns a random treasure' do
|
49
|
+
treasure = TreasureTrove.random
|
50
|
+
TreasureTrove::TREASURES.should include(treasure)
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: studio_game_421
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Laurence Castaneda
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-20 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: 2.8.0
|
20
|
+
- - "~>"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '2.8'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.8.0
|
30
|
+
- - "~>"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '2.8'
|
33
|
+
description: |-
|
34
|
+
# Studio Game App
|
35
|
+
This gem runs a simple game with user input. You can input the number of rounds you want to play and type 'quit' when finished playing. The app will print game stats after quitting.
|
36
|
+
email: laurence.castaneda@daveramsey.com
|
37
|
+
executables:
|
38
|
+
- studio_game
|
39
|
+
extensions: []
|
40
|
+
extra_rdoc_files: []
|
41
|
+
files:
|
42
|
+
- LICENSE
|
43
|
+
- README.md
|
44
|
+
- bin/high_scores.txt
|
45
|
+
- bin/players.csv
|
46
|
+
- bin/studio_game
|
47
|
+
- lib/studio_game/auditable.rb
|
48
|
+
- lib/studio_game/berserk_player.rb
|
49
|
+
- lib/studio_game/clumsy_player.rb
|
50
|
+
- lib/studio_game/die.rb
|
51
|
+
- lib/studio_game/fave_players.csv
|
52
|
+
- lib/studio_game/game.rb
|
53
|
+
- lib/studio_game/game_turn.rb
|
54
|
+
- lib/studio_game/highscores.csv
|
55
|
+
- lib/studio_game/loaded_die.rb
|
56
|
+
- lib/studio_game/playable.rb
|
57
|
+
- lib/studio_game/player.rb
|
58
|
+
- lib/studio_game/print_players.rb
|
59
|
+
- lib/studio_game/spec_helper.rb
|
60
|
+
- lib/studio_game/treasure_trove.rb
|
61
|
+
- spec/studio_game/berserk_player_spec.rb
|
62
|
+
- spec/studio_game/clumsy_player_spec.rb
|
63
|
+
- spec/studio_game/game_spec.rb
|
64
|
+
- spec/studio_game/player_spec.rb
|
65
|
+
- spec/studio_game/treasure_trove_spec.rb
|
66
|
+
homepage: https://www.laurencecastaneda.tech
|
67
|
+
licenses:
|
68
|
+
- MIT
|
69
|
+
metadata: {}
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '1.9'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.0.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: A basic unpredictable and interactive game
|
89
|
+
test_files:
|
90
|
+
- spec/studio_game/clumsy_player_spec.rb
|
91
|
+
- spec/studio_game/treasure_trove_spec.rb
|
92
|
+
- spec/studio_game/berserk_player_spec.rb
|
93
|
+
- spec/studio_game/player_spec.rb
|
94
|
+
- spec/studio_game/game_spec.rb
|