Nicks_Studio_Game 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +9 -0
- data/README.md +0 -0
- data/bin/boss_characters.csv +3 -0
- data/bin/players.csv +6 -0
- data/bin/studio_game +25 -0
- data/lib/studio_game/GameTurn.rb +21 -0
- data/lib/studio_game/boss_player.rb +31 -0
- data/lib/studio_game/game.rb +133 -0
- data/lib/studio_game/playable.rb +26 -0
- data/lib/studio_game/player.rb +56 -0
- data/lib/studio_game/super_boss_player.rb +52 -0
- data/lib/studio_game/treasure_trove.rb +23 -0
- data/spec/studio_game/boss_player_spec.rb +36 -0
- data/spec/studio_game/game_spec.rb +34 -0
- data/spec/studio_game/player_spec.rb +130 -0
- data/spec/studio_game/super_boss_player_spec.rb +51 -0
- data/spec/studio_game/treasure_trove_spec.rb +43 -0
- metadata +86 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3cd8c4af724833befc90def692a9c282aef0f9d5d293a8a2dd3a38fbabd9e1a2
|
|
4
|
+
data.tar.gz: d8580b1f4e954327c0ee77d1ce6baa65eb120cac8119895fd33777e08cbae8b8
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: a167386ada226c7a02b1dd81ae8e49707dc84b3426f8abece1a4322981b2611449eaaa07bf08596fc82b4e64aa81367a48ca6381a91bd805738c001b92020fcb
|
|
7
|
+
data.tar.gz: d8d2697b0b9b59e9bc3805b526e6bf69c0f46322c5c468b198488da32f9cad6cdd37869957a611ebcfbd731e8478860e7495ff1d86ae7a651b03fec60e54c0d4
|
data/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Nickolas Teixeira
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
File without changes
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative '../lib/studio_game/game'
|
|
3
|
+
game = StudioGame::Game.new("Nick\'s Game")
|
|
4
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
|
5
|
+
if ARGV.empty?
|
|
6
|
+
game.load_players([default_player_file])
|
|
7
|
+
else
|
|
8
|
+
game.load_players(ARGV)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
loop do
|
|
12
|
+
puts "How many game rounds? (\"quit\" to exit)"
|
|
13
|
+
answer = $stdin.gets.chomp
|
|
14
|
+
case answer
|
|
15
|
+
when /^\d+$/
|
|
16
|
+
game.play(answer.to_i)
|
|
17
|
+
when "quit", "exit"
|
|
18
|
+
game.print_stats
|
|
19
|
+
break
|
|
20
|
+
else
|
|
21
|
+
puts "Please enter a valid number or \"quit\""
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
game.save_high_scores
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
module GameTurn
|
|
5
|
+
def self.take_turn player
|
|
6
|
+
num = roll_dice
|
|
7
|
+
case num
|
|
8
|
+
when 1..2
|
|
9
|
+
player.blam
|
|
10
|
+
when 3..4
|
|
11
|
+
puts "#{player.name} was skipped.".center(40)
|
|
12
|
+
else
|
|
13
|
+
player.w00t
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def self.roll_dice
|
|
18
|
+
rand(1..6)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative 'player'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
class BossPlayer < Player
|
|
8
|
+
def found_treasure treasure
|
|
9
|
+
points = treasure.points * 3
|
|
10
|
+
boss_treasure = Treasure.new(treasure.name, points)
|
|
11
|
+
super boss_treasure
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
if __FILE__ == $0
|
|
17
|
+
boss = BossPlayer.new("klutz")
|
|
18
|
+
|
|
19
|
+
hammer = Treasure.new(:hammer, 50)
|
|
20
|
+
boss.found_treasure(hammer)
|
|
21
|
+
boss.found_treasure(hammer)
|
|
22
|
+
boss.found_treasure(hammer)
|
|
23
|
+
|
|
24
|
+
bazooka = Treasure.new(:bazooka, 400)
|
|
25
|
+
boss.found_treasure(bazooka)
|
|
26
|
+
|
|
27
|
+
boss.each_found_treasure do |treasure|
|
|
28
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
29
|
+
end
|
|
30
|
+
puts "#{boss.points} grand total points"
|
|
31
|
+
end
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative 'player'
|
|
3
|
+
require_relative 'GameTurn'
|
|
4
|
+
require_relative 'treasure_trove'
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
class Game
|
|
8
|
+
attr_reader :name, :players
|
|
9
|
+
def initialize name
|
|
10
|
+
@name = name
|
|
11
|
+
@players = []
|
|
12
|
+
@number_players = 0
|
|
13
|
+
@center = 40
|
|
14
|
+
@alignment = 38
|
|
15
|
+
end
|
|
16
|
+
def add_player player
|
|
17
|
+
@players.push(player)
|
|
18
|
+
@number_players += 1
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def print_game_intro
|
|
22
|
+
puts "-" * @center
|
|
23
|
+
puts "|" + "There are #{@number_players} players in #{@name}".center(@alignment) + "|"
|
|
24
|
+
puts "-" * @center
|
|
25
|
+
end
|
|
26
|
+
def print_game_number num
|
|
27
|
+
puts "*" * @center
|
|
28
|
+
puts "*" + "Playing Game #{num}.".center(@alignment) + "*"
|
|
29
|
+
puts "*" * @center
|
|
30
|
+
end
|
|
31
|
+
def play num_games
|
|
32
|
+
print_game_intro
|
|
33
|
+
print_all_treasures
|
|
34
|
+
1.upto(num_games) do |num|
|
|
35
|
+
print_game_number(num)
|
|
36
|
+
@players.each do |player|
|
|
37
|
+
puts " #{player.name}'s Turn ".center(@center, "-")
|
|
38
|
+
player.found_treasure(find_random_treasures)
|
|
39
|
+
GameTurn.take_turn(player)
|
|
40
|
+
puts
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
print_high_scores
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
def find_random_treasures
|
|
47
|
+
treasures = TreasureTrove::TREASURES
|
|
48
|
+
treasures[rand(treasures.length)]
|
|
49
|
+
end
|
|
50
|
+
def print_all_treasures
|
|
51
|
+
treasures = TreasureTrove::TREASURES
|
|
52
|
+
puts "-" * @center
|
|
53
|
+
puts "|" + "There are #{treasures.length} treasures in this game".center(@alignment) + "|"
|
|
54
|
+
puts "-" * @center
|
|
55
|
+
treasures.each do |t|
|
|
56
|
+
puts "|" + "#{t.name} is worth #{t.points} points.".center(@alignment) + "|"
|
|
57
|
+
end
|
|
58
|
+
puts "-" * @center
|
|
59
|
+
end
|
|
60
|
+
def print_high_scores
|
|
61
|
+
puts "\nPrinting High Scores:"
|
|
62
|
+
high_scores = @players.sort{|a, b| b.score <=> a.score}
|
|
63
|
+
high_scores.each do |player|
|
|
64
|
+
puts "#{player.name}".ljust(@alignment, ".") + "#{player.score}"
|
|
65
|
+
end
|
|
66
|
+
puts "\nTotal Points accumulated #{total_points} from Treasure Trove\n\n"
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def print_weak_strong
|
|
70
|
+
strong, weak = @players.partition{|n| n.strong?}
|
|
71
|
+
puts "Top #{strong.length} STRONG players."
|
|
72
|
+
puts strong.sort
|
|
73
|
+
puts "\nTop #{weak.length} WEAK players."
|
|
74
|
+
puts weak.sort
|
|
75
|
+
puts
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def print_player_stats
|
|
79
|
+
@players.sort.each do |player|
|
|
80
|
+
puts " Player #{player.name}'s point breakdown ".center(@center, "*")
|
|
81
|
+
puts "-" * @center
|
|
82
|
+
player.each_found_treasure do |treasure|
|
|
83
|
+
puts "|" + "#{treasure.name} #{treasure.points} points".center(@alignment) + "|"
|
|
84
|
+
end
|
|
85
|
+
puts "-" * @center
|
|
86
|
+
puts "#{player.name}'s total points: #{player.points}"
|
|
87
|
+
puts "#{player.name}'s total health: #{player.health}"
|
|
88
|
+
puts
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
def print_stats_header
|
|
92
|
+
puts "-" * @center
|
|
93
|
+
puts "|" + "#{@name} Statistics".center(@alignment) + "|"
|
|
94
|
+
puts "-" * @center
|
|
95
|
+
end
|
|
96
|
+
def print_stats
|
|
97
|
+
print_stats_header
|
|
98
|
+
print_weak_strong
|
|
99
|
+
print_player_stats
|
|
100
|
+
end
|
|
101
|
+
def total_points
|
|
102
|
+
@players.reduce(0) { |sum, player| sum + player.points }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def load_players array
|
|
106
|
+
array.each do |file|
|
|
107
|
+
File.readlines(file).each do |line|
|
|
108
|
+
name, health = line.split(",")
|
|
109
|
+
add_player(Player.new(name, Integer(health)))
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
def save_high_scores file_name="high_scores.txt"
|
|
114
|
+
File.open(file_name, "w") do |fd|
|
|
115
|
+
fd.puts "#{@name} High Scores:"
|
|
116
|
+
@players.sort.each do |player|
|
|
117
|
+
fd.puts "#{player.name},#{player.score}"
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
if __FILE__ == $0
|
|
125
|
+
@game = Game.new("Knuckleheads")
|
|
126
|
+
@initial_health = 100
|
|
127
|
+
@player = Player.new("jeff", @initial_health)
|
|
128
|
+
@player2 = Player.new("nick", @initial_health)
|
|
129
|
+
@game.add_player(@player)
|
|
130
|
+
@game.add_player(@player2)
|
|
131
|
+
@game.play(2)
|
|
132
|
+
@game.print_stats
|
|
133
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# it's generally considered a better design if mixins rely on
|
|
3
|
+
# attributes (getter and setter methods) rather than instance variables.
|
|
4
|
+
# That way, if an instance variable changes it doesn't break the mixin.
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
module Playable
|
|
8
|
+
def w00t
|
|
9
|
+
puts "#{name} got w00ted!".center(40)
|
|
10
|
+
self.health += 15
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def blam
|
|
14
|
+
puts "#{name} got blammed!".center(40)
|
|
15
|
+
self.health -= 10
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def strong?
|
|
19
|
+
self.health > 100 ? true : false
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def weak?
|
|
23
|
+
self.health <= 100 ? true : false
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative 'playable'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
class Player
|
|
6
|
+
include Playable
|
|
7
|
+
attr_accessor :name, :health, :score
|
|
8
|
+
def initialize name, health=100, score=0
|
|
9
|
+
@name = name.capitalize
|
|
10
|
+
@health = health
|
|
11
|
+
@found_treasures = Hash.new(0)
|
|
12
|
+
@score = @name.length + @health
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def to_s
|
|
16
|
+
"I'm #{@name} with a health of #{@health} and a score of #{score}"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def random_score
|
|
20
|
+
rand(1..100)
|
|
21
|
+
end
|
|
22
|
+
def use_special_attack opponent
|
|
23
|
+
if opponent.health
|
|
24
|
+
value = random_score
|
|
25
|
+
opponent.health -= value
|
|
26
|
+
puts "Special attack used on #{opponent.name}"
|
|
27
|
+
else
|
|
28
|
+
puts "Cannot attack this player"
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def <=> other
|
|
33
|
+
other.score <=> @score
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def points
|
|
37
|
+
@found_treasures.values.reduce(0, :+)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def score
|
|
41
|
+
@health + points
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def found_treasure treasure
|
|
45
|
+
puts "#{@name} found a #{treasure.name} worth #{treasure.points}.".center(40)
|
|
46
|
+
@found_treasures[treasure.name] += treasure.points
|
|
47
|
+
puts "#{@name}'s treasures #{@found_treasures}.".center(40)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def each_found_treasure
|
|
51
|
+
@found_treasures.each do |name, points|
|
|
52
|
+
yield Treasure.new(name, points)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative 'player'
|
|
3
|
+
require_relative 'treasure_trove'
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
class SuperBossPlayer < Player
|
|
7
|
+
def initialize name, health=100
|
|
8
|
+
super(name, health)
|
|
9
|
+
@w00t_count = 0
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def berserk?
|
|
13
|
+
@w00t_count >= 5
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def w00t
|
|
17
|
+
super
|
|
18
|
+
@w00t_count += 1
|
|
19
|
+
puts "#{@name} is berserk! Health will increase if blammed." if berserk?
|
|
20
|
+
end
|
|
21
|
+
def blam
|
|
22
|
+
berserk? ? w00t : super
|
|
23
|
+
end
|
|
24
|
+
def found_treasure treasure
|
|
25
|
+
points = treasure.points * 1000
|
|
26
|
+
boss_treasure = Treasure.new(treasure.name, points)
|
|
27
|
+
super boss_treasure
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if __FILE__ == $0
|
|
33
|
+
boss = SuperBossPlayer.new("matt")
|
|
34
|
+
|
|
35
|
+
hammer = Treasure.new(:hammer, 50)
|
|
36
|
+
boss.found_treasure(hammer)
|
|
37
|
+
boss.found_treasure(hammer)
|
|
38
|
+
boss.found_treasure(hammer)
|
|
39
|
+
|
|
40
|
+
bazooka = Treasure.new(:bazooka, 400)
|
|
41
|
+
boss.found_treasure(bazooka)
|
|
42
|
+
|
|
43
|
+
boss.each_found_treasure do |treasure|
|
|
44
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
|
45
|
+
end
|
|
46
|
+
puts "#{boss.points} grand total points"
|
|
47
|
+
puts "#{boss.health} total health"
|
|
48
|
+
5.times {boss.w00t}
|
|
49
|
+
puts "#{boss.health} total health"
|
|
50
|
+
2.times {boss.blam}
|
|
51
|
+
puts "#{boss.health} total health"
|
|
52
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
Treasure = Struct.new(:name, :points)
|
|
6
|
+
|
|
7
|
+
module TreasureTrove
|
|
8
|
+
TREASURES = [
|
|
9
|
+
Treasure.new(:Gold, 200),
|
|
10
|
+
Treasure.new(:Silver, 150),
|
|
11
|
+
Treasure.new(:Bronze, 100),
|
|
12
|
+
Treasure.new(:Platinum, 1000)
|
|
13
|
+
]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
if __FILE__ == $0
|
|
18
|
+
items = TreasureTrove::TREASURES
|
|
19
|
+
puts "There are #{items.length} Treasure Items"
|
|
20
|
+
items.each do |item|
|
|
21
|
+
puts "#{item.name} is worth #{item.points} points."
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'studio_game/boss_player'
|
|
3
|
+
require 'studio_game/player'
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
describe BossPlayer do
|
|
7
|
+
before do
|
|
8
|
+
$stdout = StringIO.new
|
|
9
|
+
@boss = BossPlayer.new("Bowser")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it { expect(BossPlayer).to be < Player }
|
|
13
|
+
|
|
14
|
+
it "only gets half the point value for each treasure" do
|
|
15
|
+
expect(@boss.points).to eq(0)
|
|
16
|
+
|
|
17
|
+
lasergun = Treasure.new(:lasergun, 100)
|
|
18
|
+
@boss.found_treasure(lasergun)
|
|
19
|
+
@boss.found_treasure(lasergun)
|
|
20
|
+
@boss.found_treasure(lasergun)
|
|
21
|
+
|
|
22
|
+
expect(@boss.points).to eq(900)
|
|
23
|
+
|
|
24
|
+
cannon = Treasure.new(:cannon, 400)
|
|
25
|
+
@boss.found_treasure(cannon)
|
|
26
|
+
|
|
27
|
+
expect(@boss.points).to eq(2100)
|
|
28
|
+
yielded = []
|
|
29
|
+
@boss.each_found_treasure do |treasure|
|
|
30
|
+
yielded << treasure
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
expect(yielded).to eq([Treasure.new(:lasergun, 900), Treasure.new(:cannon, 1200)])
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
require 'studio_game/game'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
describe Game do
|
|
5
|
+
before do
|
|
6
|
+
@game = Game.new("Knuckleheads")
|
|
7
|
+
@initial_health = 100
|
|
8
|
+
@player = Player.new("moe", @initial_health)
|
|
9
|
+
@player2 = Player.new("nick", @initial_health)
|
|
10
|
+
@game.add_player(@player)
|
|
11
|
+
@game.add_player(@player2)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
it "has a title" do
|
|
15
|
+
expect(@game.name).to eq("Knuckleheads")
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
it 'computes total points as the sum of all player points' do
|
|
19
|
+
game = Game.new("Knuckleheads")
|
|
20
|
+
|
|
21
|
+
player1 = Player.new("moe")
|
|
22
|
+
player2 = Player.new("larry")
|
|
23
|
+
|
|
24
|
+
game.add_player(player1)
|
|
25
|
+
game.add_player(player2)
|
|
26
|
+
|
|
27
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
|
28
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
|
29
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
|
30
|
+
|
|
31
|
+
expect(game.total_points).to eq(500)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'studio_game/player'
|
|
4
|
+
require 'studio_game/GameTurn'
|
|
5
|
+
require 'studio_game/treasure_trove'
|
|
6
|
+
|
|
7
|
+
module StudioGame
|
|
8
|
+
describe Player do
|
|
9
|
+
before do
|
|
10
|
+
# stdout is a global variable, when overwritten
|
|
11
|
+
# it's writes out to the new StringIO object
|
|
12
|
+
# and not the console
|
|
13
|
+
#$stdout = StringIO.new
|
|
14
|
+
@p1_health, @p2_health = 100, 100
|
|
15
|
+
@player = Player.new("nick", @p1_health)
|
|
16
|
+
@player2 = Player.new("jeff", @p2_health)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
it 'has a captialized name' do
|
|
20
|
+
expect(@player.name).to eq("Nick")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'has an initial health' do
|
|
24
|
+
expect(@player.health).to eq(100)
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'has a string representation' do
|
|
28
|
+
@player.found_treasure(Treasure.new(:lightning, 5))
|
|
29
|
+
expect(@player.to_s).to eq("I'm Nick with a health of 100 and a score of 105")
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
it 'computers a score as the sum of its health and points' do
|
|
33
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
34
|
+
@player.found_treasure(Treasure.new(:warchest, 50000))
|
|
35
|
+
expect(@player.score).to eq(50150)
|
|
36
|
+
end
|
|
37
|
+
it 'increase health by 15 when w00ted' do
|
|
38
|
+
@player.w00t
|
|
39
|
+
expect(@player.health).to eq(115)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it 'decreases health by 10 when blammed' do
|
|
43
|
+
@player.blam
|
|
44
|
+
expect(@player.health).to eq(90)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'checks random damage by using special attack' do
|
|
48
|
+
allow_any_instance_of(Player).to receive(:random_score).and_return(50)
|
|
49
|
+
@player.use_special_attack(@player2)
|
|
50
|
+
expect(@player2.health).to eq(@p2_health - 50)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it 'computes points as the sum of all treasure points' do
|
|
54
|
+
expect(@player.points).to eq(0)
|
|
55
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
56
|
+
expect(@player.points).to eq(50)
|
|
57
|
+
@player.found_treasure(Treasure.new(:bazooka, 1000))
|
|
58
|
+
expect(@player.points).to eq(1050)
|
|
59
|
+
@player.found_treasure(Treasure.new(:machine_learning, 5000))
|
|
60
|
+
expect(@player.points).to eq(6050)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
it 'yields each found treasure and its total points' do
|
|
64
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
65
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
|
66
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
|
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
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
71
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
|
72
|
+
|
|
73
|
+
yielded = []
|
|
74
|
+
@player.each_found_treasure do |treasure|
|
|
75
|
+
yielded << treasure
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
expect(yielded).to eq([
|
|
79
|
+
Treasure.new(:skillet, 200),
|
|
80
|
+
Treasure.new(:hammer, 50),
|
|
81
|
+
Treasure.new(:bottle, 25)
|
|
82
|
+
])
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context 'created with a default score' do
|
|
86
|
+
before do
|
|
87
|
+
@player = Player.new("nick", 100, 50)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
it 'has a score of 50' do
|
|
91
|
+
expect(@player.score).to eq(100)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context 'created with a health of 150' do
|
|
96
|
+
before do
|
|
97
|
+
@player = Player.new("jeff", 150)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
it 'is a strong player' do
|
|
101
|
+
expect(@player.strong?).to eq(true)
|
|
102
|
+
expect(@player.strong?).to_not eq(false)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context 'created with health of 75' do
|
|
107
|
+
before do
|
|
108
|
+
@player = Player.new("tim", 75)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it 'is a weak player' do
|
|
112
|
+
expect(@player.weak?).to eq(true)
|
|
113
|
+
expect(@player.weak?).to_not eq(false)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
context 'multiple players' do
|
|
118
|
+
before do
|
|
119
|
+
@player1 = Player.new("nick", 100)
|
|
120
|
+
@player2 = Player.new("jeff", 200)
|
|
121
|
+
@player3 = Player.new("matt", 300)
|
|
122
|
+
@players = [@player1, @player2, @player3]
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
it 'names should be sorted by decreasing score' do
|
|
126
|
+
expect(@players.sort).to eq([@player3, @player2, @player1])
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require 'studio_game/super_boss_player'
|
|
3
|
+
require 'studio_game/player'
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
module StudioGame
|
|
7
|
+
describe SuperBossPlayer do
|
|
8
|
+
before do
|
|
9
|
+
$stdout = StringIO.new
|
|
10
|
+
@superboss = SuperBossPlayer.new("Bowser")
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it { expect(SuperBossPlayer).to be < Player }
|
|
14
|
+
it { expect(SuperBossPlayer).to be < Player}
|
|
15
|
+
|
|
16
|
+
it "only gets half the point value for each treasure" do
|
|
17
|
+
expect(@superboss.points).to eq(0)
|
|
18
|
+
|
|
19
|
+
lasergun = Treasure.new(:lasergun, 10)
|
|
20
|
+
@superboss.found_treasure(lasergun)
|
|
21
|
+
@superboss.found_treasure(lasergun)
|
|
22
|
+
@superboss.found_treasure(lasergun)
|
|
23
|
+
|
|
24
|
+
expect(@superboss.points).to eq(30000)
|
|
25
|
+
|
|
26
|
+
cannon = Treasure.new(:cannon, 100)
|
|
27
|
+
@superboss.found_treasure(cannon)
|
|
28
|
+
|
|
29
|
+
expect(@superboss.points).to eq(130000)
|
|
30
|
+
yielded = []
|
|
31
|
+
@superboss.each_found_treasure do |treasure|
|
|
32
|
+
yielded << treasure
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
expect(yielded).to eq([Treasure.new(:lasergun, 30000), Treasure.new(:cannon, 100000)])
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'should w00t if blammed in berserk mode' do
|
|
39
|
+
6.times {@superboss.w00t}
|
|
40
|
+
expect(@superboss.health).to eq(190)
|
|
41
|
+
2.times {@superboss.blam}
|
|
42
|
+
expect(@superboss.health).to eq(220)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it 'superboss should go berserk after 5 w00ts' do
|
|
46
|
+
expect(@superboss.berserk?).to eq(false)
|
|
47
|
+
5.times{@superboss.w00t}
|
|
48
|
+
expect(@superboss.berserk?).to eq(true)
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require 'studio_game/treasure_trove'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
describe Treasure do
|
|
5
|
+
before do
|
|
6
|
+
@treasure = Treasure.new(:hammer, 50)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
it 'has a name attribute' do
|
|
10
|
+
expect(@treasure.name).to eq(:hammer)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
it 'has a points attribute' do
|
|
14
|
+
expect(@treasure.points).to eq(50)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
describe TreasureTrove do
|
|
19
|
+
before do
|
|
20
|
+
@treasures = TreasureTrove::TREASURES
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
it 'has a trove of 4' do
|
|
24
|
+
expect(@treasures.length).to eq(4)
|
|
25
|
+
end
|
|
26
|
+
it 'has gold worth 200' do
|
|
27
|
+
expect(@treasures[0].name).to eq(:Gold)
|
|
28
|
+
expect(@treasures[0].points).to eq(200)
|
|
29
|
+
end
|
|
30
|
+
it 'has silver worth 150' do
|
|
31
|
+
expect(@treasures[1].name).to eq(:Silver)
|
|
32
|
+
expect(@treasures[1].points).to eq(150)
|
|
33
|
+
end
|
|
34
|
+
it 'has bronze worth 100' do
|
|
35
|
+
expect(@treasures[2].name).to eq(:Bronze)
|
|
36
|
+
expect(@treasures[2].points).to eq(100)
|
|
37
|
+
end
|
|
38
|
+
it 'has platinum worth 1000' do
|
|
39
|
+
expect(@treasures[3].name).to eq(:Platinum)
|
|
40
|
+
expect(@treasures[3].points).to eq(1000)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: Nicks_Studio_Game
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Nickolas Teixeira
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-02-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: '2.8'
|
|
20
|
+
- - ">="
|
|
21
|
+
- !ruby/object:Gem::Version
|
|
22
|
+
version: 2.8.0
|
|
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'
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: 2.8.0
|
|
33
|
+
description: ''
|
|
34
|
+
email: NickolasTeixeira01@gmail.com
|
|
35
|
+
executables:
|
|
36
|
+
- studio_game
|
|
37
|
+
extensions: []
|
|
38
|
+
extra_rdoc_files: []
|
|
39
|
+
files:
|
|
40
|
+
- LICENSE
|
|
41
|
+
- README.md
|
|
42
|
+
- bin/boss_characters.csv
|
|
43
|
+
- bin/players.csv
|
|
44
|
+
- bin/studio_game
|
|
45
|
+
- lib/studio_game/GameTurn.rb
|
|
46
|
+
- lib/studio_game/boss_player.rb
|
|
47
|
+
- lib/studio_game/game.rb
|
|
48
|
+
- lib/studio_game/playable.rb
|
|
49
|
+
- lib/studio_game/player.rb
|
|
50
|
+
- lib/studio_game/super_boss_player.rb
|
|
51
|
+
- lib/studio_game/treasure_trove.rb
|
|
52
|
+
- spec/studio_game/boss_player_spec.rb
|
|
53
|
+
- spec/studio_game/game_spec.rb
|
|
54
|
+
- spec/studio_game/player_spec.rb
|
|
55
|
+
- spec/studio_game/super_boss_player_spec.rb
|
|
56
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
57
|
+
homepage: https://NickolasTeixeira.com
|
|
58
|
+
licenses:
|
|
59
|
+
- MIT
|
|
60
|
+
metadata: {}
|
|
61
|
+
post_install_message:
|
|
62
|
+
rdoc_options: []
|
|
63
|
+
require_paths:
|
|
64
|
+
- lib
|
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
66
|
+
requirements:
|
|
67
|
+
- - ">="
|
|
68
|
+
- !ruby/object:Gem::Version
|
|
69
|
+
version: '2.5'
|
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
71
|
+
requirements:
|
|
72
|
+
- - ">="
|
|
73
|
+
- !ruby/object:Gem::Version
|
|
74
|
+
version: '0'
|
|
75
|
+
requirements: []
|
|
76
|
+
rubyforge_project:
|
|
77
|
+
rubygems_version: 2.7.6
|
|
78
|
+
signing_key:
|
|
79
|
+
specification_version: 4
|
|
80
|
+
summary: Nick's Simple Studio Game
|
|
81
|
+
test_files:
|
|
82
|
+
- spec/studio_game/treasure_trove_spec.rb
|
|
83
|
+
- spec/studio_game/player_spec.rb
|
|
84
|
+
- spec/studio_game/boss_player_spec.rb
|
|
85
|
+
- spec/studio_game/super_boss_player_spec.rb
|
|
86
|
+
- spec/studio_game/game_spec.rb
|