martzens_studio_game 1.0.2
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 +21 -0
- data/README.md +9 -0
- data/bin/players.csv +5 -0
- data/bin/studio_game +43 -0
- data/lib/studio_game/auditable.rb +5 -0
- data/lib/studio_game/berserk_player.rb +24 -0
- data/lib/studio_game/clumsy_player.rb +16 -0
- data/lib/studio_game/game.rb +107 -0
- data/lib/studio_game/playable.rb +9 -0
- data/lib/studio_game/player.rb +43 -0
- data/lib/studio_game/treasure_trove.rb +21 -0
- data/lib/studio_game.rb +5 -0
- metadata +65 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 8161de32b0b87a903d11bbffdd17677d995387ab13e9bc1112e28e6a8f4cc6e3
|
|
4
|
+
data.tar.gz: b5f152a88bcbaa42d0b7267b6282e9629ad8f0ad0d6ac51a5faa6b0d7ed1bcbe
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 056b50a5a297098b80b0cb1d241bdf11465dc20976e20f6b58d53cb101de1a6fbb8f3e4faa822b93f3fe59e96ed29a9162ac3232c94e524204a97ba114d68bd4
|
|
7
|
+
data.tar.gz: 924c42c5268a18830d41304523fdd633413a09d7697b525cd231aee3b3a964f74267773e1d73c86f7bd9e7b1a1f8b04ff952602e5b71bb831bee14611561f0b2
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Martzen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Studio Game
|
|
2
|
+
|
|
3
|
+
## About the Game
|
|
4
|
+
|
|
5
|
+
Studio Game is a fun and interactive Ruby-based game where players compete to collect treasures and achieve the highest score. Players can encounter various challenges, including clumsy or berserk behavior, which adds an element of unpredictability to the gameplay. The game also features a treasure trove system, where players can find and collect different treasures to boost their scores.
|
|
6
|
+
|
|
7
|
+
## License
|
|
8
|
+
|
|
9
|
+
This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require_relative "../lib/studio_game/game"
|
|
4
|
+
require_relative "../lib/studio_game/clumsy_player"
|
|
5
|
+
require_relative "../lib/studio_game/berserk_player"
|
|
6
|
+
|
|
7
|
+
puts ""
|
|
8
|
+
puts "Let's play"
|
|
9
|
+
puts ""
|
|
10
|
+
|
|
11
|
+
def emojis(number = 25)
|
|
12
|
+
emoji = "👾"
|
|
13
|
+
puts emoji * number
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
game = StudioGame::Game.new("Winner Takes All")
|
|
17
|
+
players_file = File.join(__dir__, "players.csv")
|
|
18
|
+
game.load_players(ARGV.shift || players_file)
|
|
19
|
+
|
|
20
|
+
clumsy = StudioGame::ClumsyPlayer.new("klutz", 10, 3)
|
|
21
|
+
game.add_player(clumsy)
|
|
22
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
23
|
+
game.add_player(berserker)
|
|
24
|
+
|
|
25
|
+
emojis()
|
|
26
|
+
|
|
27
|
+
loop do
|
|
28
|
+
print "\nHow many game rounds? ('q, quit' to exit) "
|
|
29
|
+
answer = gets.chomp.downcase
|
|
30
|
+
|
|
31
|
+
case answer
|
|
32
|
+
when /^\d+$/ # types number
|
|
33
|
+
game.play(answer.to_i)
|
|
34
|
+
when "q", "quit", "exit" # types quit
|
|
35
|
+
game.print_stats
|
|
36
|
+
break
|
|
37
|
+
else
|
|
38
|
+
puts "Please enter a number or 'quit'"
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
game.save_high_scores
|
|
43
|
+
emojis()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
require_relative 'player'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class BerserkPlayer < Player
|
|
5
|
+
def initialize(name, health = 100)
|
|
6
|
+
super(name, health)
|
|
7
|
+
@boost_count = 0
|
|
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
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
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 boost
|
|
13
|
+
@boost_factor.times { super }
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
require_relative 'treasure_trove'
|
|
2
|
+
require_relative 'auditable'
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
class Game
|
|
6
|
+
include Auditable
|
|
7
|
+
attr_reader :title, :players
|
|
8
|
+
|
|
9
|
+
def initialize(title)
|
|
10
|
+
@title = title
|
|
11
|
+
@players = []
|
|
12
|
+
@treasures_found = Hash.new(0)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def roll_dice
|
|
16
|
+
number = rand(1..6)
|
|
17
|
+
audit(number)
|
|
18
|
+
number
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def add_player(player)
|
|
22
|
+
@players << player
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def load_players(from_file)
|
|
26
|
+
File.readlines(from_file, chomp: true).each do |line|
|
|
27
|
+
player = Player.from_csv(line)
|
|
28
|
+
add_player(player)
|
|
29
|
+
end
|
|
30
|
+
rescue Errno::ENOENT
|
|
31
|
+
puts "Whoops, #{from_file} not found!"
|
|
32
|
+
exit 1
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def sorted_players
|
|
36
|
+
@players.sort_by { |player| player.score }.reverse
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def print_stats
|
|
40
|
+
puts "\n Game Stats:"
|
|
41
|
+
puts "-" * 30
|
|
42
|
+
puts sorted_players
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def high_score_entry(player)
|
|
46
|
+
name = player.name.ljust(20, ".")
|
|
47
|
+
score = player.score.round.to_s.rjust(5)
|
|
48
|
+
"#{name}#{score}"
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def save_high_scores(to_file = "high_scores.txt")
|
|
52
|
+
File.open(to_file, "w") do |file|
|
|
53
|
+
file.puts "#{@title} High Scores:"
|
|
54
|
+
sorted_players.each do |player|
|
|
55
|
+
file.puts high_score_entry(player)
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def play(rounds = 1)
|
|
61
|
+
puts "Before playing:"
|
|
62
|
+
puts @players
|
|
63
|
+
puts ""
|
|
64
|
+
|
|
65
|
+
puts "The following treasures can be found:"
|
|
66
|
+
puts TreasureTrove.treasure_items
|
|
67
|
+
|
|
68
|
+
rounds.times do |round|
|
|
69
|
+
puts "\nRound #{round+1}:"
|
|
70
|
+
@players.each do |player|
|
|
71
|
+
number_rolled = roll_dice()
|
|
72
|
+
case number_rolled
|
|
73
|
+
when 1..2
|
|
74
|
+
player.drain
|
|
75
|
+
puts "#{player.name} got drained 😩"
|
|
76
|
+
when 3..4
|
|
77
|
+
puts "#{player.name} got skipped 😐"
|
|
78
|
+
else
|
|
79
|
+
player.boost
|
|
80
|
+
puts "#{player.name} got boosted 😁"
|
|
81
|
+
end
|
|
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
|
+
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
puts ""
|
|
90
|
+
puts "After playing:"
|
|
91
|
+
puts @players
|
|
92
|
+
|
|
93
|
+
@players.each do |player|
|
|
94
|
+
puts "\n#{player.name}'s treasure point totals:"
|
|
95
|
+
player.found_treasures.each do |name, points|
|
|
96
|
+
puts "#{name}: #{points}"
|
|
97
|
+
end
|
|
98
|
+
puts "total: #{player.points}"
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
puts "\nHigh Scores:"
|
|
102
|
+
sorted_players.each do |player|
|
|
103
|
+
puts high_score_entry(player)
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
require_relative 'playable'
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
attr_reader :found_treasures
|
|
7
|
+
attr_accessor :name, :health
|
|
8
|
+
|
|
9
|
+
def initialize(name, health=100)
|
|
10
|
+
@name = name.split(" ").map { |word| word.capitalize }.join(" ")
|
|
11
|
+
@health = health
|
|
12
|
+
@found_treasures = Hash.new(0)
|
|
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 score
|
|
20
|
+
@health + @name.length
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def name=(new_name)
|
|
24
|
+
@name = new_name.capitalize
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def found_treasure(name, points)
|
|
28
|
+
@found_treasures[name.capitalize] += points
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def points
|
|
32
|
+
@found_treasures.values.sum
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def self.from_csv(line)
|
|
36
|
+
name, health = line.split(',')
|
|
37
|
+
Player.new(name, Integer(health))
|
|
38
|
+
rescue ArgumentError
|
|
39
|
+
puts "Ignored invalid health: #{health}"
|
|
40
|
+
Player.new(name)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module TreasureTrove
|
|
2
|
+
Treasure = Data.define(:name, :points)
|
|
3
|
+
|
|
4
|
+
TREASURES = [
|
|
5
|
+
Treasure.new("pie", 10),
|
|
6
|
+
Treasure.new("coin", 25),
|
|
7
|
+
Treasure.new("flute", 50),
|
|
8
|
+
Treasure.new("compass", 65),
|
|
9
|
+
Treasure.new("key", 80),
|
|
10
|
+
Treasure.new("crown", 90),
|
|
11
|
+
Treasure.new("star", 100)
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
def self.random_treasure
|
|
15
|
+
TREASURES.sample
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def self.treasure_items
|
|
19
|
+
TREASURES.map { |treasure| "A #{treasure.name} is worth #{treasure.points} points" }
|
|
20
|
+
end
|
|
21
|
+
end
|
data/lib/studio_game.rb
ADDED
metadata
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: martzens_studio_game
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.2
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- iMartzen
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: simplecov
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.22.0
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.22.0
|
|
26
|
+
email: gem@martzen.nl
|
|
27
|
+
executables:
|
|
28
|
+
- studio_game
|
|
29
|
+
extensions: []
|
|
30
|
+
extra_rdoc_files: []
|
|
31
|
+
files:
|
|
32
|
+
- LICENSE
|
|
33
|
+
- README.md
|
|
34
|
+
- bin/players.csv
|
|
35
|
+
- bin/studio_game
|
|
36
|
+
- lib/studio_game.rb
|
|
37
|
+
- lib/studio_game/auditable.rb
|
|
38
|
+
- lib/studio_game/berserk_player.rb
|
|
39
|
+
- lib/studio_game/clumsy_player.rb
|
|
40
|
+
- lib/studio_game/game.rb
|
|
41
|
+
- lib/studio_game/playable.rb
|
|
42
|
+
- lib/studio_game/player.rb
|
|
43
|
+
- lib/studio_game/treasure_trove.rb
|
|
44
|
+
homepage: https://github.com/iMartzen/studio_game
|
|
45
|
+
licenses:
|
|
46
|
+
- MIT
|
|
47
|
+
metadata: {}
|
|
48
|
+
rdoc_options: []
|
|
49
|
+
require_paths:
|
|
50
|
+
- lib
|
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
|
+
requirements:
|
|
53
|
+
- - ">="
|
|
54
|
+
- !ruby/object:Gem::Version
|
|
55
|
+
version: 3.2.0
|
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
|
+
requirements:
|
|
58
|
+
- - ">="
|
|
59
|
+
- !ruby/object:Gem::Version
|
|
60
|
+
version: '0'
|
|
61
|
+
requirements: []
|
|
62
|
+
rubygems_version: 3.6.7
|
|
63
|
+
specification_version: 4
|
|
64
|
+
summary: A simple game to play with friends
|
|
65
|
+
test_files: []
|