Rubymon_FireRed 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 +7 -0
- data/README +1 -0
- data/bin/players.csv +3 -0
- data/bin/studio_game +33 -0
- data/lib/studio_game/auditable.rb +8 -0
- data/lib/studio_game/berserk_player.rb +36 -0
- data/lib/studio_game/clumsy_player.rb +40 -0
- data/lib/studio_game/die.rb +20 -0
- data/lib/studio_game/game.rb +101 -0
- data/lib/studio_game/game_turn.rb +29 -0
- data/lib/studio_game/loaded_die.rb +15 -0
- data/lib/studio_game/playable.rb +17 -0
- data/lib/studio_game/player.rb +73 -0
- data/lib/studio_game/treasure_trove.rb +18 -0
- data/spec/studio_game/berserk_player_spec.rb +30 -0
- data/spec/studio_game/clumsy_player_spec.rb +50 -0
- data/spec/studio_game/game_spec.rb +65 -0
- data/spec/studio_game/player_spec.rb +139 -0
- data/spec/studio_game/treasure_trove_spec.rb +56 -0
- metadata +87 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: de5430b33a9fa7aec024cfdfba95f99605a7b057e5da16d174adcd20597e229a
|
4
|
+
data.tar.gz: e1060793f3128d9facabe33ba11206bb9116457db65f112912f6c729cba160a8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3e701610da8211a2f1afaf78329d072e346a731e785655ef8b84a78cb0497500758dcc41a06a8e6da06deaff8c8b72d96a9f755ddb4c433e95246b1995fbca55
|
7
|
+
data.tar.gz: 498c739aec4c2485471575559e09a4ced463ac4bd4cb0f34cbb90cded993030a49e0961f96a4ec1cfbe50133ec11c753b0a5a34a072e17213ba0676493e2f483
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright (c) 2024 @Guillaume-G9
|
2
|
+
|
3
|
+
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:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
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
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Small Ruby game project made with 'The Pragmatic Studio' Ruby course
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
@@ -0,0 +1,33 @@
|
|
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
|
+
game = StudioGame::Game.new("Pokemon")
|
9
|
+
|
10
|
+
default_player_file = File.join(File.dirname(__FILE__), 'players.csv')
|
11
|
+
game.load_players(ARGV.shift || default_player_file)
|
12
|
+
|
13
|
+
kluts = StudioGame::ClumsyPlayer.new("klutz",105)
|
14
|
+
guts = StudioGame::BerserkPlayer.new("guts",50)
|
15
|
+
game.add_player(kluts)
|
16
|
+
game.add_player(guts)
|
17
|
+
|
18
|
+
loop do
|
19
|
+
puts "\nHow many game rounds? ('quit' to exit)"
|
20
|
+
answer = gets.chomp.downcase
|
21
|
+
|
22
|
+
case answer
|
23
|
+
when /^\d+$/
|
24
|
+
game.play(answer.to_i, game)
|
25
|
+
when "quit", "exit"
|
26
|
+
game.statistics
|
27
|
+
break
|
28
|
+
else
|
29
|
+
puts "Please enter a number or type 'quit' to exit."
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
game.save_high_scores
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class BerserkPlayer < Player
|
5
|
+
|
6
|
+
def initialize(name, health=100)
|
7
|
+
super(name, health)
|
8
|
+
@w00t_count = 0
|
9
|
+
end
|
10
|
+
|
11
|
+
def w00t
|
12
|
+
super
|
13
|
+
@w00t_count += 1
|
14
|
+
puts "#{@player_name} has gone berserk!" if berserk?
|
15
|
+
end
|
16
|
+
|
17
|
+
def berserk?
|
18
|
+
@w00t_count > 5
|
19
|
+
end
|
20
|
+
|
21
|
+
def blam
|
22
|
+
if berserk?
|
23
|
+
w00t
|
24
|
+
else
|
25
|
+
super
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
if __FILE__ == $0
|
32
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
33
|
+
6.times { berserker.w00t }
|
34
|
+
2.times { berserker.blam }
|
35
|
+
puts berserker.player_health
|
36
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require_relative 'player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
class ClumsyPlayer < Player
|
5
|
+
attr_reader :boost_factor
|
6
|
+
|
7
|
+
def initialize(name, health=100, boost_factor = 1)
|
8
|
+
super(name, health)
|
9
|
+
@boost_factor = boost_factor
|
10
|
+
end
|
11
|
+
|
12
|
+
def w00t
|
13
|
+
@boost_factor.times {super}
|
14
|
+
puts "#{@player_name} special ability triggered!"
|
15
|
+
end
|
16
|
+
|
17
|
+
def found_treasure(treasure)
|
18
|
+
half_points = Treasure.new(treasure.name, treasure.points / 2)
|
19
|
+
super(half_points)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
if __FILE__ == $0
|
26
|
+
clumsy = ClumsyPlayer.new("klutz")
|
27
|
+
|
28
|
+
hammer = Treasure.new(:hammer, 50)
|
29
|
+
clumsy.found_treasure(hammer)
|
30
|
+
clumsy.found_treasure(hammer)
|
31
|
+
clumsy.found_treasure(hammer)
|
32
|
+
|
33
|
+
crowbar = Treasure.new(:crowbar, 400)
|
34
|
+
clumsy.found_treasure(crowbar)
|
35
|
+
|
36
|
+
clumsy.each_found_treasure do |treasure|
|
37
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
38
|
+
end
|
39
|
+
puts "#{clumsy.points} grand total points"
|
40
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'game_turn'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
require 'csv'
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
class Game
|
8
|
+
|
9
|
+
attr_reader :game_name
|
10
|
+
|
11
|
+
def initialize(name)
|
12
|
+
@game_name = name
|
13
|
+
@players = []
|
14
|
+
end
|
15
|
+
|
16
|
+
def add_player(player)
|
17
|
+
@players << player
|
18
|
+
end
|
19
|
+
|
20
|
+
def total_points
|
21
|
+
@players.reduce(0) { |sum, player| sum + player.points}
|
22
|
+
end
|
23
|
+
|
24
|
+
def statistics
|
25
|
+
strong, wimpy = @players.partition { |player| player.strong? }
|
26
|
+
|
27
|
+
puts "\n#{ @game_name } statistics: \n - #{ strong.size } strong player(s): "
|
28
|
+
strong.each do |strong_player|
|
29
|
+
GameTurn.print_name_and_health(strong_player)
|
30
|
+
end
|
31
|
+
|
32
|
+
puts "\n - #{ wimpy.size } wimpy player(s): "
|
33
|
+
wimpy.each do |wimpy_player|
|
34
|
+
GameTurn.print_name_and_health(wimpy_player)
|
35
|
+
end
|
36
|
+
|
37
|
+
@players.each do |player|
|
38
|
+
puts "\n#{player.player_name}'s point totals:"
|
39
|
+
player.each_found_treasure do |treasure|
|
40
|
+
puts "#{treasure.points} total #{treasure.name} points"
|
41
|
+
end
|
42
|
+
puts "#{player.points} grand total points"
|
43
|
+
end
|
44
|
+
|
45
|
+
puts "\n#{ @game_name} High Scores: "
|
46
|
+
|
47
|
+
@players.sort.each do |player|
|
48
|
+
puts high_score_entry(player)
|
49
|
+
end
|
50
|
+
|
51
|
+
puts "\n#{total_points} total points from treasures found \nWell played!!"
|
52
|
+
end
|
53
|
+
|
54
|
+
def load_players(filename)
|
55
|
+
CSV.foreach(filename) do |row|
|
56
|
+
player = Player.new(row[0], row[1].to_i)
|
57
|
+
add_player(player)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def high_score_entry(player)
|
62
|
+
formatted_name = player.player_name.ljust(20, '.')
|
63
|
+
"#{formatted_name} #{player.score}"
|
64
|
+
end
|
65
|
+
|
66
|
+
def save_high_scores(filename="high_scores.txt")
|
67
|
+
File.open(filename, "w") do |file|
|
68
|
+
file.puts "#{@game_name} High Scores: "
|
69
|
+
@players.sort.each do |player|
|
70
|
+
file.puts high_score_entry(player)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
def play(rounds, game)
|
76
|
+
if @players.length() > 1
|
77
|
+
puts "There are #{@players.size} players in #{@game_name}"
|
78
|
+
else
|
79
|
+
puts "There is #{@players.size} player in #{@game_name}"
|
80
|
+
end
|
81
|
+
|
82
|
+
treasures = TreasureTrove::TREASURES
|
83
|
+
puts "\nThere are #{treasures.size} treasures in #{@game_name}:"
|
84
|
+
treasures.each do |treasure|
|
85
|
+
puts "- A #{treasure.name} is worth #{treasure.points} points"
|
86
|
+
end
|
87
|
+
|
88
|
+
1.upto(rounds) do |round|
|
89
|
+
#check to see if block was given > if yes > break the loop and exit game
|
90
|
+
if block_given?
|
91
|
+
break if yield
|
92
|
+
end
|
93
|
+
|
94
|
+
puts "\nRound #{round}"
|
95
|
+
@players.each do |player|
|
96
|
+
GameTurn.take_turn(player)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require_relative 'die'
|
2
|
+
require_relative 'player'
|
3
|
+
require_relative 'treasure_trove'
|
4
|
+
require_relative 'game'
|
5
|
+
|
6
|
+
module StudioGame
|
7
|
+
module GameTurn
|
8
|
+
|
9
|
+
def self.take_turn(player)
|
10
|
+
die = Die.new
|
11
|
+
case die.roll
|
12
|
+
|
13
|
+
when 1..2
|
14
|
+
player.blam
|
15
|
+
when 3..4
|
16
|
+
puts "#{ player.player_name } was skipped."
|
17
|
+
else
|
18
|
+
player.w00t
|
19
|
+
end
|
20
|
+
|
21
|
+
treasure = TreasureTrove.random
|
22
|
+
player.found_treasure(treasure)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.print_name_and_health(player)
|
26
|
+
puts "#{ player.player_name } (#{ player.player_health })"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module StudioGame
|
2
|
+
module Playable
|
3
|
+
def blam
|
4
|
+
self.player_health -= 10
|
5
|
+
puts "#{player_name} got blammed!"
|
6
|
+
end
|
7
|
+
|
8
|
+
def w00t
|
9
|
+
self.player_health += 15
|
10
|
+
puts "#{player_name} got w00ted!"
|
11
|
+
end
|
12
|
+
|
13
|
+
def strong?
|
14
|
+
self.player_health > 100
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require_relative 'treasure_trove'
|
2
|
+
require_relative 'playable'
|
3
|
+
|
4
|
+
module StudioGame
|
5
|
+
class Player
|
6
|
+
include Playable
|
7
|
+
|
8
|
+
attr_accessor :player_name, :player_health
|
9
|
+
|
10
|
+
def initialize(name, health=100)
|
11
|
+
@player_name = name.capitalize
|
12
|
+
@player_health = health
|
13
|
+
@found_treasures = Hash.new(0)
|
14
|
+
end
|
15
|
+
|
16
|
+
def say_hello
|
17
|
+
"I'm #{@player_name} with a health of #{@player_health}."
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"I'm #{@player_name} with a health of #{@player_health}."
|
22
|
+
end
|
23
|
+
|
24
|
+
def score
|
25
|
+
@player_health + points
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.from_csv(string)
|
29
|
+
name, health = string.split(',')
|
30
|
+
Player.new(name, Integer(health))
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_s
|
34
|
+
"I'm #{@player_name} with a health of #{@player_health}, #{points} points and a score of #{score}"
|
35
|
+
end
|
36
|
+
|
37
|
+
def name=(new_name)
|
38
|
+
@player_name = new_name.capitalize
|
39
|
+
end
|
40
|
+
|
41
|
+
def <=>(other)
|
42
|
+
other.score <=> score
|
43
|
+
end
|
44
|
+
|
45
|
+
def found_treasure(treasure)
|
46
|
+
@found_treasures[treasure.name] += treasure.points
|
47
|
+
puts "#{@player_name} found a #{treasure.name} worth #{treasure.points} points!"
|
48
|
+
puts "#{@player_name}'s treasures: #{@found_treasures}"
|
49
|
+
end
|
50
|
+
|
51
|
+
def points
|
52
|
+
@found_treasures.values.reduce(0, :+)
|
53
|
+
end
|
54
|
+
|
55
|
+
def each_found_treasure
|
56
|
+
@found_treasures.each do |name, points|
|
57
|
+
yield Treasure.new(name, points)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
|
64
|
+
#prevent this sample codeblock to run when class is called
|
65
|
+
if __FILE__ == $0
|
66
|
+
player = Player.new("moe")
|
67
|
+
puts player.player_name
|
68
|
+
puts player.player_health
|
69
|
+
player.w00t
|
70
|
+
puts player.player_health
|
71
|
+
player.blam
|
72
|
+
puts player.player_health
|
73
|
+
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
|
+
random_treasure = TREASURES.sample
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'studio_game/berserk_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe BerserkPlayer do
|
5
|
+
|
6
|
+
before do
|
7
|
+
@initial_health = 50
|
8
|
+
@player = BerserkPlayer.new("berserker", @initial_health)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "does not go berserk when w00ted up to 5 times" do
|
12
|
+
1.upto(5) { @player.w00t }
|
13
|
+
|
14
|
+
expect(@player.berserk?).to be_falsey
|
15
|
+
end
|
16
|
+
|
17
|
+
it "goes berserk when w00ted more than 5 times" do
|
18
|
+
1.upto(6) { @player.w00t }
|
19
|
+
|
20
|
+
expect(@player.berserk?).to be_truthy
|
21
|
+
end
|
22
|
+
|
23
|
+
it "gets w00ted instead of blammed when it's gone berserk" do
|
24
|
+
1.upto(6) { @player.w00t }
|
25
|
+
1.upto(2) { @player.blam }
|
26
|
+
|
27
|
+
expect(@player.player_health).to be == @initial_health + (8 * 15)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'studio_game/clumsy_player'
|
2
|
+
|
3
|
+
module StudioGame
|
4
|
+
describe ClumsyPlayer do
|
5
|
+
|
6
|
+
context "with a boost factor" do
|
7
|
+
before do
|
8
|
+
@initial_health = 100
|
9
|
+
@boost_factor = 5
|
10
|
+
@player = ClumsyPlayer.new("klutz", @initial_health, @boost_factor)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "has a boost factor" do
|
14
|
+
expect(@player.boost_factor).to be == 5
|
15
|
+
end
|
16
|
+
|
17
|
+
it "gets boost factor number of w00ts when w00ted" do
|
18
|
+
@player.w00t
|
19
|
+
|
20
|
+
expect(@player.player_health).to be == @initial_health + (15 * @boost_factor)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
before do
|
24
|
+
@player = ClumsyPlayer.new("klutz")
|
25
|
+
end
|
26
|
+
|
27
|
+
it "only gets half the point value for each treasure" do
|
28
|
+
expect(@player.points).to be == 0
|
29
|
+
|
30
|
+
hammer = Treasure.new(:hammer, 50)
|
31
|
+
@player.found_treasure(hammer)
|
32
|
+
@player.found_treasure(hammer)
|
33
|
+
@player.found_treasure(hammer)
|
34
|
+
|
35
|
+
expect(@player.points).to be == 75
|
36
|
+
|
37
|
+
crowbar = Treasure.new(:crowbar, 400)
|
38
|
+
@player.found_treasure(crowbar)
|
39
|
+
|
40
|
+
expect(@player.points).to be == 275
|
41
|
+
|
42
|
+
yielded = []
|
43
|
+
@player.each_found_treasure do |treasure|
|
44
|
+
yielded << treasure
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(yielded).to be == [Treasure.new(:hammer, 75), Treasure.new(:crowbar, 200)]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'studio_game/game'
|
2
|
+
require 'studio_game/player'
|
3
|
+
require 'studio_game/die'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
describe Game do
|
7
|
+
|
8
|
+
before do
|
9
|
+
@game = Game.new("Pokémon")
|
10
|
+
|
11
|
+
@initial_health = 100
|
12
|
+
@player = Player.new("ash", @initial_health)
|
13
|
+
|
14
|
+
@game.add_player(@player)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "increases health by 15 when high number is rolled" do
|
18
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(5)
|
19
|
+
|
20
|
+
@game.play(1, @game)
|
21
|
+
expect(@player.player_health).to be == @initial_health + 15
|
22
|
+
end
|
23
|
+
|
24
|
+
it "does nothing when a medium number is rolled" do
|
25
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(4)
|
26
|
+
|
27
|
+
@game.play(1, @game)
|
28
|
+
expect(@player.player_health).to be == @initial_health
|
29
|
+
end
|
30
|
+
|
31
|
+
it "decreases health by 10 when a low number is rolled" do
|
32
|
+
allow_any_instance_of(Die).to receive(:roll).and_return(1)
|
33
|
+
|
34
|
+
@game.play(1, @game)
|
35
|
+
expect(@player.player_health).to be == @initial_health - 10
|
36
|
+
end
|
37
|
+
|
38
|
+
it "computes total points as the sum of all player points" do
|
39
|
+
game = Game.new("Knuckleheads")
|
40
|
+
|
41
|
+
player1 = Player.new("moe")
|
42
|
+
player2 = Player.new("larry")
|
43
|
+
|
44
|
+
game.add_player(player1)
|
45
|
+
game.add_player(player2)
|
46
|
+
|
47
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
48
|
+
player1.found_treasure(Treasure.new(:hammer, 50))
|
49
|
+
player2.found_treasure(Treasure.new(:crowbar, 400))
|
50
|
+
|
51
|
+
expect(game.total_points).to be == 500
|
52
|
+
end
|
53
|
+
|
54
|
+
it "assigns a treasure for points during a player's turn" do
|
55
|
+
game = Game.new("Knuckleheads")
|
56
|
+
player = Player.new("moe")
|
57
|
+
|
58
|
+
game.add_player(player)
|
59
|
+
|
60
|
+
game.play(1,1)
|
61
|
+
|
62
|
+
expect(player.points).not_to be_zero
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,139 @@
|
|
1
|
+
require 'studio_game/player'
|
2
|
+
require 'studio_game/treasure_trove'
|
3
|
+
require 'studio_game/game'
|
4
|
+
|
5
|
+
module StudioGame
|
6
|
+
describe Player do
|
7
|
+
|
8
|
+
before do
|
9
|
+
$stdout = StringIO.new
|
10
|
+
end
|
11
|
+
|
12
|
+
before do
|
13
|
+
@player = Player.new("robert", 325)
|
14
|
+
@initial_health = @player.player_health
|
15
|
+
end
|
16
|
+
|
17
|
+
it "has a capitalized name" do
|
18
|
+
expect(@player.player_name).to be == "Robert"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has an initial health" do
|
22
|
+
expect(@player.player_health).to be == 325
|
23
|
+
end
|
24
|
+
|
25
|
+
it "has a string representation" do
|
26
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
27
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
28
|
+
|
29
|
+
expect(@player.to_s).to be == "I'm Robert with a health of 325, 100 points and a score of 425"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "computes 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(:hammer, 50))
|
35
|
+
|
36
|
+
expect(@player.score).to be == 425
|
37
|
+
end
|
38
|
+
|
39
|
+
it "increases health by 15 when w00ted" do
|
40
|
+
@player.w00t
|
41
|
+
expect(@player.player_health).to be == @initial_health + 15
|
42
|
+
end
|
43
|
+
|
44
|
+
it "can be created from a CSV string" do
|
45
|
+
player = Player.from_csv("larry,150")
|
46
|
+
|
47
|
+
expect(player.player_name).to be == "Larry"
|
48
|
+
expect(player.player_health).to be == 150
|
49
|
+
end
|
50
|
+
|
51
|
+
it "decreases health by 10 when blammed" do
|
52
|
+
@player.blam
|
53
|
+
expect(@player.player_health).to be == @initial_health - 10
|
54
|
+
end
|
55
|
+
|
56
|
+
it "yields each found treasure and its total points" do
|
57
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
58
|
+
@player.found_treasure(Treasure.new(:skillet, 100))
|
59
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
60
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
61
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
62
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
63
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
64
|
+
@player.found_treasure(Treasure.new(:bottle, 5))
|
65
|
+
|
66
|
+
yielded = []
|
67
|
+
@player.each_found_treasure do |treasure|
|
68
|
+
yielded << treasure
|
69
|
+
end
|
70
|
+
|
71
|
+
expect(yielded).to be == [
|
72
|
+
Treasure.new(:skillet, 200),
|
73
|
+
Treasure.new(:hammer, 50),
|
74
|
+
Treasure.new(:bottle, 25)
|
75
|
+
]
|
76
|
+
end
|
77
|
+
|
78
|
+
it "computes points as the sum of all treasure points" do
|
79
|
+
expect(@player.points).to be == 0
|
80
|
+
|
81
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
82
|
+
|
83
|
+
expect(@player.points).to be == 50
|
84
|
+
|
85
|
+
@player.found_treasure(Treasure.new(:crowbar, 400))
|
86
|
+
|
87
|
+
expect(@player.points).to be == 450
|
88
|
+
|
89
|
+
@player.found_treasure(Treasure.new(:hammer, 50))
|
90
|
+
|
91
|
+
expect(@player.points).to be == 500
|
92
|
+
end
|
93
|
+
|
94
|
+
it "assigns a treasure for points during a player's turn" do
|
95
|
+
game = Game.new("Knuckleheads")
|
96
|
+
player = Player.new("moe")
|
97
|
+
|
98
|
+
game.add_player(player)
|
99
|
+
|
100
|
+
game.play(1, game)
|
101
|
+
|
102
|
+
expect(player.points).not_to be_zero
|
103
|
+
end
|
104
|
+
|
105
|
+
context "strong player context" do
|
106
|
+
before do
|
107
|
+
@player = Player.new("joan", 150)
|
108
|
+
end
|
109
|
+
|
110
|
+
it "is a strong player" do
|
111
|
+
expect(@player.strong?).to be == true
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
context "wimpy player context" do
|
116
|
+
before do
|
117
|
+
@player = Player.new("joan", 100)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "is a wimpy player" do
|
121
|
+
expect(@player.strong?).to be == false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "in a collection of players" do
|
126
|
+
before do
|
127
|
+
@player1 = Player.new("moe", 100)
|
128
|
+
@player2 = Player.new("larry", 200)
|
129
|
+
@player3 = Player.new("curly", 300)
|
130
|
+
|
131
|
+
@players = [@player1, @player2, @player3]
|
132
|
+
end
|
133
|
+
|
134
|
+
it "is sorted by decreasing score" do
|
135
|
+
expect(@players.sort).to be == [@player3, @player2, @player1]
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
@@ -0,0 +1,56 @@
|
|
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 be == :hammer
|
12
|
+
end
|
13
|
+
|
14
|
+
it "has a points attribute" do
|
15
|
+
expect(@treasure.points).to be == 50
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
describe TreasureTrove do
|
21
|
+
|
22
|
+
it "has six treasures" do
|
23
|
+
expect(TreasureTrove::TREASURES.size).to be == 6
|
24
|
+
end
|
25
|
+
|
26
|
+
it "has a pie worth 5 points" do
|
27
|
+
expect(TreasureTrove::TREASURES[0]).to be == Treasure.new(:pie, 5)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "has a bottle worth 25 points" do
|
31
|
+
expect(TreasureTrove::TREASURES[1]).to be == Treasure.new(:bottle, 25)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "has a hammer worth 50 points" do
|
35
|
+
expect(TreasureTrove::TREASURES[2]).to be == Treasure.new(:hammer, 50)
|
36
|
+
end
|
37
|
+
|
38
|
+
it "has a skillet worth 100 points" do
|
39
|
+
expect(TreasureTrove::TREASURES[3]).to be == Treasure.new(:skillet, 100)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "has a broomstick worth 200 points" do
|
43
|
+
expect(TreasureTrove::TREASURES[4]).to be == Treasure.new(:broomstick, 200)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "has a crowbar worth 400 points" do
|
47
|
+
expect(TreasureTrove::TREASURES[5]).to be == Treasure.new(:crowbar, 400)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "returns a random treasure" do
|
51
|
+
treasure = TreasureTrove.random
|
52
|
+
expect(TreasureTrove::TREASURES).to include(treasure)
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: Rubymon_FireRed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Guillaume-G9
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-07-10 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: Small Ruby game project made with 'The Pragmatic Studio' Ruby course
|
34
|
+
email: test@gmail.com
|
35
|
+
executables:
|
36
|
+
- studio_game
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- LICENSE
|
41
|
+
- README
|
42
|
+
- bin/players.csv
|
43
|
+
- bin/studio_game
|
44
|
+
- lib/studio_game/auditable.rb
|
45
|
+
- lib/studio_game/berserk_player.rb
|
46
|
+
- lib/studio_game/clumsy_player.rb
|
47
|
+
- lib/studio_game/die.rb
|
48
|
+
- lib/studio_game/game.rb
|
49
|
+
- lib/studio_game/game_turn.rb
|
50
|
+
- lib/studio_game/loaded_die.rb
|
51
|
+
- lib/studio_game/playable.rb
|
52
|
+
- lib/studio_game/player.rb
|
53
|
+
- lib/studio_game/treasure_trove.rb
|
54
|
+
- spec/studio_game/berserk_player_spec.rb
|
55
|
+
- spec/studio_game/clumsy_player_spec.rb
|
56
|
+
- spec/studio_game/game_spec.rb
|
57
|
+
- spec/studio_game/player_spec.rb
|
58
|
+
- spec/studio_game/treasure_trove_spec.rb
|
59
|
+
homepage: https://google.com
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '1.9'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubygems_version: 3.3.26
|
79
|
+
signing_key:
|
80
|
+
specification_version: 4
|
81
|
+
summary: Ruby game
|
82
|
+
test_files:
|
83
|
+
- spec/studio_game/berserk_player_spec.rb
|
84
|
+
- spec/studio_game/clumsy_player_spec.rb
|
85
|
+
- spec/studio_game/game_spec.rb
|
86
|
+
- spec/studio_game/player_spec.rb
|
87
|
+
- spec/studio_game/treasure_trove_spec.rb
|