player_hub 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.txt +23 -0
- data/README.md +31 -0
- data/bin/players.csv +5 -0
- data/bin/studio_game +38 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +32 -0
- data/lib/studio_game/clumsy_player.rb +37 -0
- data/lib/studio_game/game.rb +99 -0
- data/lib/studio_game/playable.rb +11 -0
- data/lib/studio_game/player.rb +55 -0
- data/lib/studio_game/treasure_trove.rb +23 -0
- metadata +54 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 84fbab4b8bfa8c68ca22878459d1032b68c8186cf0c0a9700ef382060dad613b
|
|
4
|
+
data.tar.gz: 506e9954b1d4b4a76b95f3addfaa51364c7afe6e08a041a1a7744289c72dcc5d
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 84ace15fab0fdae84abc7921d64bfc8191f6268526ee10e4f1ec90030d927bc90a620ab345924424b42c76028fdcd472a28aac7f3d3cef09139a771251df8bb7
|
|
7
|
+
data.tar.gz: bad396fb470f96b07b7189c8d9dab71b831e60af76ec461db5e987adf9a0190b05f9a5f38131aec2d5294d32f31e2b84513e6226c4c16702d42b4f69874c2782
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
### (MIT License):
|
|
3
|
+
|
|
4
|
+
```
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Studio Game
|
|
2
|
+
|
|
3
|
+
This is an educational game project created as part of The Pragmatic Studio's Ruby course. The project demonstrates the basics of Ruby programming and serves as a hands-on exercise for learning Ruby.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- Different types of players with unique abilities
|
|
8
|
+
- Gameplay mechanics including scoring and leveling
|
|
9
|
+
- Modular code structure for easy expansion and maintenance
|
|
10
|
+
|
|
11
|
+
## Getting Started
|
|
12
|
+
|
|
13
|
+
### Prerequisites
|
|
14
|
+
|
|
15
|
+
- Ruby version 3.2.0 or higher
|
|
16
|
+
|
|
17
|
+
### Installation
|
|
18
|
+
|
|
19
|
+
1. Clone the repository:
|
|
20
|
+
```bash
|
|
21
|
+
git clone https://github.com/danielpcar9/studio_game
|
|
22
|
+
cd studio_game
|
|
23
|
+
2. Install dependencies: bundle install
|
|
24
|
+
|
|
25
|
+
3. Run the game: bin/studio_game
|
|
26
|
+
|
|
27
|
+
4. Running tests: ruby test/studio_game/all_tests.rb
|
|
28
|
+
|
|
29
|
+
ruby test/studio_game/all_tests.rb
|
|
30
|
+
|
|
31
|
+
Contributions are welcome! Please fork the repository and create a pull request with your changes.
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
require_relative "../lib/studio_game/game"
|
|
3
|
+
require_relative "../lib/studio_game/clumsy_player"
|
|
4
|
+
require_relative "../lib/studio_game/berserk_player"
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
game = StudioGame::Game.new("Guardians")
|
|
8
|
+
|
|
9
|
+
players_file = File.join(__dir__, "players.csv")
|
|
10
|
+
|
|
11
|
+
klutz = StudioGame::ClumsyPlayer.new("klutz", 105)
|
|
12
|
+
berserk = StudioGame::BerserkPlayer.new("berserk", 50)
|
|
13
|
+
|
|
14
|
+
game.add_player(klutz)
|
|
15
|
+
game.add_player(berserk)
|
|
16
|
+
|
|
17
|
+
game.load_players(ARGV.shift || players_file)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
loop do
|
|
21
|
+
print "\nHow many game rounds? ('quit' to exit)"
|
|
22
|
+
answer = gets.chomp.downcase
|
|
23
|
+
|
|
24
|
+
case answer
|
|
25
|
+
when /^\d+$/
|
|
26
|
+
puts game.play(answer.to_i)
|
|
27
|
+
when "quit", exit
|
|
28
|
+
game.print_stats
|
|
29
|
+
break
|
|
30
|
+
else
|
|
31
|
+
puts "Please enter a number or 'quit'"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
game.save_high_scores
|
|
36
|
+
game.play(3)
|
|
37
|
+
game.print_stats
|
|
38
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require_relative "player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class BerserkPlayer < Player
|
|
5
|
+
def initialize(name, health = 150)
|
|
6
|
+
@boost_count = 0
|
|
7
|
+
super(name, health)
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def berserk?
|
|
11
|
+
@boost_count > 5
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def boost
|
|
15
|
+
super
|
|
16
|
+
@boost_count += 1
|
|
17
|
+
puts "#{name} is berserk!" if berserk?
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def drain
|
|
21
|
+
berserk? ? boost : super
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
if __FILE__ == $0
|
|
27
|
+
berserker = BerserkPlayer.new("berserker", 50)
|
|
28
|
+
6.times { berserker.boost }
|
|
29
|
+
2.times { berserker.drain }
|
|
30
|
+
puts berserker.health
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require_relative "player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
|
|
6
|
+
def initialize(name, health = 100, boost_factor = 1)
|
|
7
|
+
@boost_factor = boost_factor
|
|
8
|
+
super(name, health)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def boost
|
|
12
|
+
@boost_factor.times { super }
|
|
13
|
+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def found_treasure(name, points)
|
|
17
|
+
points = points / 2.0
|
|
18
|
+
@found_treasures[name] += points
|
|
19
|
+
super(name, points)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __FILE__ == $0
|
|
25
|
+
clumsy = ClumsyPlayer.new("klutz")
|
|
26
|
+
|
|
27
|
+
clumsy.found_treasure("flute", 50)
|
|
28
|
+
clumsy.found_treasure("flute", 50)
|
|
29
|
+
clumsy.found_treasure("flute", 50)
|
|
30
|
+
clumsy.found_treasure("star", 100)
|
|
31
|
+
|
|
32
|
+
clumsy.found_treasures.each do |name, points|
|
|
33
|
+
puts "#{name}: #{points} points"
|
|
34
|
+
end
|
|
35
|
+
puts "#{clumsy.points} total points"
|
|
36
|
+
end
|
|
37
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
require_relative "player"
|
|
2
|
+
require_relative "treasure_trove"
|
|
3
|
+
require_relative "auditable"
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
class Game
|
|
7
|
+
include Auditable
|
|
8
|
+
|
|
9
|
+
attr_reader :title, :players
|
|
10
|
+
|
|
11
|
+
def initialize(title)
|
|
12
|
+
@title = title
|
|
13
|
+
@players = []
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def add_player(player)
|
|
17
|
+
@players << player
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def load_players(from_file)
|
|
21
|
+
|
|
22
|
+
File.readlines(from_file, chomp: true).each do |line|
|
|
23
|
+
player = Player.from_csv(line)
|
|
24
|
+
add_player(player)
|
|
25
|
+
end
|
|
26
|
+
rescue Errno::ENOENT
|
|
27
|
+
puts "Whoops, #{from_file} not found! "
|
|
28
|
+
exit 1
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def save_high_scores(to_file = "high_scores.txt")
|
|
33
|
+
File.open(to_file, "w") do |file|
|
|
34
|
+
file.puts "#{@title} High Scores:"
|
|
35
|
+
sorted_players.each do |player|
|
|
36
|
+
file.puts "#{player.name.ljust(20, '.')}#{player.score.round.to_s.rjust(5)}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def print_stats
|
|
42
|
+
puts "\nGame stats:"
|
|
43
|
+
puts "-" * 20
|
|
44
|
+
sorted_players.each { |player| puts player }
|
|
45
|
+
|
|
46
|
+
@players.each do |player|
|
|
47
|
+
puts "\n#{player.name}'s treasure point totals:"
|
|
48
|
+
player.found_treasures.each { |name, points| puts "#{name}: #{points}" }
|
|
49
|
+
puts "total: #{player.score}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def sorted_players
|
|
54
|
+
@players.sort_by { |player| player.score }.reverse
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def play(rounds = 1)
|
|
58
|
+
puts "\n#{title} game is starting!"
|
|
59
|
+
puts "\nThe following treasures can be found:"
|
|
60
|
+
|
|
61
|
+
puts TreasureTrove.treasure_items
|
|
62
|
+
|
|
63
|
+
puts "\nBefore playing:"
|
|
64
|
+
puts @players
|
|
65
|
+
|
|
66
|
+
1.upto(rounds) do |round|
|
|
67
|
+
puts "\nRound #{round} is starting!"
|
|
68
|
+
|
|
69
|
+
@players.each do |player|
|
|
70
|
+
number_rolled = roll_die
|
|
71
|
+
case number_rolled
|
|
72
|
+
when 1..2
|
|
73
|
+
player.drain
|
|
74
|
+
puts "#{player.name} got drained!😫"
|
|
75
|
+
when 3..4
|
|
76
|
+
puts "#{player.name} got skipped!😒"
|
|
77
|
+
else
|
|
78
|
+
player.boost
|
|
79
|
+
puts "#{player.name} got boosted!😁"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
treasure = TreasureTrove.random_treasure
|
|
83
|
+
player.found_treasure(treasure.name, treasure.points)
|
|
84
|
+
puts "#{player.name} found a #{treasure.name} worth #{treasure.points} points"
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
puts "\nAfter playing:"
|
|
89
|
+
puts @players
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
def roll_die
|
|
93
|
+
number = rand(1..6)
|
|
94
|
+
audit(number)
|
|
95
|
+
number
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
end
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
require_relative "playable"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
attr_accessor :name, :health
|
|
7
|
+
attr_reader :found_treasures
|
|
8
|
+
|
|
9
|
+
def name=(new_name)
|
|
10
|
+
@name = new_name.capitalize
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def initialize(name, health = 100)
|
|
14
|
+
@name = name.capitalize
|
|
15
|
+
@health = health
|
|
16
|
+
@found_treasures = Hash.new(0)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def found_treasure(name, points)
|
|
20
|
+
@found_treasures[name] += points
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def points
|
|
24
|
+
@found_treasures.values.sum
|
|
25
|
+
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def self.from_csv(line)
|
|
29
|
+
|
|
30
|
+
name, health = line.split(",")
|
|
31
|
+
Player.new(name, Integer(health))
|
|
32
|
+
rescue ArgumentError
|
|
33
|
+
puts "Ignored Invalid health: #{health}"
|
|
34
|
+
Player.new(name)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def to_s
|
|
38
|
+
"I'm #{@name} with a health = #{@health}, score = #{score}, and points = #{points}"
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def score
|
|
42
|
+
@health + name.length + points
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
if __FILE__ == $0
|
|
47
|
+
player = Player.new("jase")
|
|
48
|
+
puts player.name
|
|
49
|
+
puts player.health
|
|
50
|
+
player.boost
|
|
51
|
+
puts player.health
|
|
52
|
+
player.drain
|
|
53
|
+
puts player.health
|
|
54
|
+
end
|
|
55
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module StudioGame
|
|
2
|
+
module TreasureTrove
|
|
3
|
+
|
|
4
|
+
Treasure = Data.define(:name, :points)
|
|
5
|
+
|
|
6
|
+
TREASURES = [
|
|
7
|
+
Treasure.new("pie", 10),
|
|
8
|
+
Treasure.new("coin", 25),
|
|
9
|
+
Treasure.new("flute", 50),
|
|
10
|
+
Treasure.new("compass", 65),
|
|
11
|
+
Treasure.new("key", 80),
|
|
12
|
+
Treasure.new("crown", 90),
|
|
13
|
+
Treasure.new("star", 100)
|
|
14
|
+
]
|
|
15
|
+
def self.random_treasure
|
|
16
|
+
TREASURES.sample
|
|
17
|
+
end
|
|
18
|
+
def self.treasure_items
|
|
19
|
+
TREASURES.map { |treasure| "A #{treasure.name} is worth #{treasure.points}" }
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: player_hub
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Daniel Cardenas
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-07-22 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email: eldanypalomo@gmail.com
|
|
15
|
+
executables:
|
|
16
|
+
- studio_game
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE.txt
|
|
21
|
+
- README.md
|
|
22
|
+
- bin/players.csv
|
|
23
|
+
- bin/studio_game
|
|
24
|
+
- lib/studio_game/auditable.rb
|
|
25
|
+
- lib/studio_game/berserk_player.rb
|
|
26
|
+
- lib/studio_game/clumsy_player.rb
|
|
27
|
+
- lib/studio_game/game.rb
|
|
28
|
+
- lib/studio_game/playable.rb
|
|
29
|
+
- lib/studio_game/player.rb
|
|
30
|
+
- lib/studio_game/treasure_trove.rb
|
|
31
|
+
homepage: https://github.com/danielpcar9/studio_game
|
|
32
|
+
licenses:
|
|
33
|
+
- MIT
|
|
34
|
+
metadata: {}
|
|
35
|
+
post_install_message:
|
|
36
|
+
rdoc_options: []
|
|
37
|
+
require_paths:
|
|
38
|
+
- lib
|
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
40
|
+
requirements:
|
|
41
|
+
- - ">="
|
|
42
|
+
- !ruby/object:Gem::Version
|
|
43
|
+
version: 3.2.0
|
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
45
|
+
requirements:
|
|
46
|
+
- - ">="
|
|
47
|
+
- !ruby/object:Gem::Version
|
|
48
|
+
version: '0'
|
|
49
|
+
requirements: []
|
|
50
|
+
rubygems_version: 3.5.10
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 4
|
|
53
|
+
summary: An educational sample game project from The pragmatic studio course
|
|
54
|
+
test_files: []
|