studio_game_octo 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7d942130545a0d0be1421ca9bda2b71e4c8e2aa4a6962cf4c67ccf9153d7907d
4
+ data.tar.gz: 2fe969cb183bcd1f7c1e49d85fa8c2625d30f4039b516d05a7ad6b0ca12b2e1f
5
+ SHA512:
6
+ metadata.gz: 10fc0aa4095cd703b7ddc9ddf0b9cea808c66850316582985c7219f80b7e400155f1154f8752b99ce09227a8ee044f718177fbfe19b4c7aaaa4f2615f4b472b8
7
+ data.tar.gz: 19bc6b16c21b48c5a066c98e5721af9a102cfc189550dce1d01471b55bd4a356d487437df8cf0b7984dde6aa10d8252908a4ec4738b7df7fa45b6ae19908d343
data/LICENSE ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2025 octo
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.md ADDED
@@ -0,0 +1,71 @@
1
+ # Studio Game
2
+
3
+ A Ruby-based text game where players compete in rounds, rolling dice to
4
+ gain or lose health, and collecting treasures to accumulate points.
5
+
6
+ ## Setup
7
+
8
+ ```bash
9
+ bundle install
10
+ ```
11
+
12
+ ## Running the Game
13
+
14
+ ```bash
15
+ ruby studio_game.rb [path/to/players.csv]
16
+ ```
17
+
18
+ The game will prompt you for the number of rounds to play. Type `quit` or
19
+ `exit` to end the game and see final stats.
20
+
21
+ ### Player Types
22
+
23
+ - **Regular Players**: Standard health and treasure collection
24
+ - **Clumsy Players**: Treasures worth half points, optional boost
25
+ multiplier
26
+ - **Berserk Players**: After 5 boosts, drains become boosts instead
27
+
28
+ ## Testing
29
+
30
+ ```bash
31
+ # Run all tests
32
+ ruby test/studio_game/all_tests.rb
33
+
34
+ # Run individual test files
35
+ ruby test/studio_game/player_test.rb
36
+
37
+ # Auto-run tests on file changes
38
+ bundle exec guard
39
+ ```
40
+
41
+ ## Linting
42
+
43
+ ```bash
44
+ bundle exec rubocop
45
+ ```
46
+
47
+ ## Game Mechanics
48
+
49
+ - **Dice Rolls**: Each round, players roll a die (1-6)
50
+ - **1-2**: Drained (-10 health)
51
+ - **3-4**: Skipped (no change)
52
+ - **5-6**: Boosted (+15 health)
53
+ - **Treasures**: Players find random treasures each round worth 10-100
54
+ points
55
+ - **Score**: Health + treasure points
56
+ - **Output**: High scores saved to `high_scores.txt` when game ends
57
+
58
+ ## Project Structure
59
+
60
+ ```
61
+ lib/studio_game/
62
+ ├── player.rb # Base player class
63
+ ├── berserk_player.rb # Berserk player subclass
64
+ ├── clumsy_player.rb # Clumsy player subclass
65
+ ├── game.rb # Game engine
66
+ └── treasure_trove.rb # Treasure definitions
67
+ ```
68
+
69
+ ## License
70
+
71
+ Educational project from The Pragmatic Studio.
data/bin/players.csv ADDED
@@ -0,0 +1,6 @@
1
+ finn balor, 59
2
+ pepa pig, 48
3
+ einn lalor, 59
4
+ cinn ialor, 59
5
+ nepa nig, 48
6
+ repa big, 48
data/bin/studio_game ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ # $stdout.sync = true
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
+ players_file = File.join(__dir__, 'players.csv')
9
+ game = StudioGame::Game.new('Winner Takes All')
10
+ game.load_players(ARGV.shift || players_file)
11
+ game.add_player(StudioGame::ClumsyPlayer.new('klonky'))
12
+ game.add_player(StudioGame::BerserkPlayer.new('GORRRR'))
13
+
14
+ loop do
15
+ print "\nHow many rounds? "
16
+
17
+ answer = gets.chomp.downcase
18
+
19
+ case answer
20
+ when /^\d+$/
21
+ game.play(answer.to_i)
22
+ when 'quit', 'exit'
23
+ game.print_stats
24
+ break
25
+ else
26
+ puts "Type the number or rounds or 'quit' to exit"
27
+ end
28
+ end
29
+
30
+ game.save_high_scores
@@ -0,0 +1,5 @@
1
+ module Auditable
2
+ def audit(number)
3
+ puts "Audit: Rolled a #{number}"
4
+ end
5
+ end
@@ -0,0 +1,32 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ # A berserk player whose treasures are worth half the normal amount
5
+ class BerserkPlayer < Player
6
+ def initialize(name, health = 25)
7
+ name = "#{name} 😈"
8
+ @boost_count = 0
9
+ super(name, health)
10
+ end
11
+
12
+ def berserk?
13
+ @boost_count >= 5
14
+ end
15
+
16
+ def boost
17
+ super
18
+ berserk? ? puts('😈😈😈') : @boost_count += 1
19
+ end
20
+
21
+ def drain
22
+ berserk? ? boost : super
23
+ end
24
+ end
25
+ end
26
+
27
+ if __FILE__ == $PROGRAM_NAME
28
+ berserker = StudioGame::BerserkPlayer.new('MYRKUR', 50)
29
+ 6.times { berserker.boost }
30
+ 2.times { berserker.drain }
31
+ puts berserker.health
32
+ end
@@ -0,0 +1,36 @@
1
+ require_relative 'player'
2
+
3
+ module StudioGame
4
+ # A clumsy player whose treasures are worth half the normal amount
5
+ class ClumsyPlayer < Player
6
+ def initialize(name, health = 100, boost_factor = 1)
7
+ name = "#{name} 🥴"
8
+ super(name, health)
9
+ @boost_factor = boost_factor
10
+ end
11
+
12
+ def found_treasure(name, points)
13
+ super(name, points / 2)
14
+ end
15
+
16
+ def boost
17
+ @boost_factor.times { super }
18
+ end
19
+ end
20
+ end
21
+
22
+ if __FILE__ == $PROGRAM_NAME
23
+ clumsy = StudioGame::ClumsyPlayer.new('klutz', 100, 3)
24
+
25
+ clumsy.found_treasure('flute', 50)
26
+ clumsy.found_treasure('flute', 50)
27
+ clumsy.found_treasure('flute', 50)
28
+ clumsy.found_treasure('star', 100)
29
+ clumsy.boost
30
+ clumsy.boost
31
+
32
+ clumsy.found_treasures.each do |name, points|
33
+ puts "#{name}: #{points} points"
34
+ end
35
+ puts "#{clumsy.score} total points"
36
+ end
@@ -0,0 +1,134 @@
1
+ require_relative 'treasure_trove'
2
+ require_relative 'player'
3
+ require_relative 'auditable'
4
+ require 'csv'
5
+
6
+ module StudioGame
7
+ class Game
8
+ include Auditable
9
+ attr_reader :name, :players
10
+
11
+ def initialize(name)
12
+ @name = name
13
+ @players = []
14
+ end
15
+
16
+ def add_player(player)
17
+ @players << player
18
+ end
19
+
20
+ def load_players(from_file = 'players.csv')
21
+ CSV.foreach(from_file) do |line|
22
+ add_player(Player.from_csv(line))
23
+ end
24
+ rescue StandardError
25
+ puts "The file #{from_file} doesn't exist"
26
+ exit 1
27
+ end
28
+
29
+ def roll_die
30
+ number = rand(1..6)
31
+ audit(number)
32
+ number
33
+ end
34
+
35
+ def process_roll(roll, player)
36
+ case roll
37
+ when (1..2)
38
+ player.drain
39
+ puts "#{player.name} got drained ⏬"
40
+ when (3..4)
41
+ puts "#{player.name} got skipped 🤨"
42
+ when (5..6)
43
+ player.boost
44
+ puts "#{player.name} got boosted ⏫"
45
+ end
46
+ end
47
+
48
+ def print_separator
49
+ puts
50
+ 30.times { print '*' }
51
+ print "\n\n"
52
+ end
53
+
54
+ def print_next_round(round)
55
+ print_separator
56
+ puts "BEGIN ROUND #{round}"
57
+ print_separator
58
+ end
59
+
60
+ def players_status
61
+ @players.each { |player| puts player }
62
+ end
63
+
64
+ def sorted_players
65
+ @players.sort_by(&:score).reverse
66
+ end
67
+
68
+ def high_score_entry(player)
69
+ # Count emojis (they take 2 visual columns but count as 1 char)
70
+ emoji_count = player.name.scan(/\p{Emoji}/).size
71
+ # Adjust padding to account for emoji visual width
72
+ padding = 30 - emoji_count
73
+ name = player.name.ljust(padding, '.')
74
+ score = player.score.round.to_s.rjust(5)
75
+ "#{name}#{score}"
76
+ end
77
+
78
+ def high_scores
79
+ puts "\n #{@title} HIGH SCORES "
80
+ sorted_players.each do |player|
81
+ puts high_score_entry(player)
82
+ end
83
+ end
84
+
85
+ def save_high_scores(to_file = 'high_scores.txt')
86
+ File.open(to_file, 'w') do |file|
87
+ file.puts "#{@title} High Scores:"
88
+ sorted_players.each do |player|
89
+ file.puts high_score_entry(player)
90
+ end
91
+ end
92
+ end
93
+
94
+ def print_stats
95
+ puts "\n -.-.- #{@name}: FINAL GAME STATS -.-.-"
96
+ puts sorted_players
97
+ players.each do |player|
98
+ puts "#{player.name} found:"
99
+ player.found_treasures.each do |treasure, points|
100
+ print "#{treasure} -> #{points}, "
101
+ end
102
+ print "Total points -> #{player.found_treasures.values.sum}."
103
+ puts
104
+ end
105
+ high_scores
106
+ end
107
+
108
+ def play(rounds = 1)
109
+ 1.upto(rounds) do |round|
110
+ print_next_round(round)
111
+ puts "🔥🔥 Let The Game of #{@name} Begin! 📯📯\n\n"
112
+
113
+ puts TreasureTrove.treasure_items
114
+
115
+ puts "\nPlayers, present yourselves!"
116
+ players_status
117
+ puts
118
+
119
+ @players.each do |player|
120
+ roll = roll_die
121
+ process_roll(roll, player)
122
+ treasure = TreasureTrove.random_treasure
123
+ puts "#{player.name} found a #{treasure.name}" \
124
+ " worth #{treasure.points} points"
125
+ player.found_treasure(treasure.name, treasure.points)
126
+ end
127
+
128
+ puts "\nPlayers, state your status!!"
129
+ players_status
130
+ end
131
+ print_stats
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,11 @@
1
+ module StudioGame
2
+ module Playable
3
+ def boost
4
+ self.health += 15
5
+ end
6
+
7
+ def drain
8
+ self.health -= 10
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,52 @@
1
+ require_relative 'playable'
2
+
3
+ module StudioGame
4
+ class Player
5
+ include Playable
6
+ attr_accessor :health
7
+ attr_reader :name, :found_treasures
8
+
9
+ def initialize(name, health = 100)
10
+ @name = name.strip.gsub(/\w+/) { |word| word.capitalize }
11
+ @health = health.to_i
12
+ @found_treasures = Hash.new(0)
13
+ end
14
+
15
+ def self.from_csv(line)
16
+ Player.new(line.first, Integer(line.last))
17
+ rescue ArgumentError
18
+ puts "Wrong information: #{line}, defaulting player's health to 100"
19
+ Player.new(line.first, 100)
20
+ end
21
+
22
+ def name=(new_name)
23
+ @name = new_name.capitalize
24
+ end
25
+
26
+ def to_s
27
+ "I'm #{@name} with health = #{health}, points #{points} and score #{score}"
28
+ end
29
+
30
+ def score
31
+ @health + points
32
+ end
33
+
34
+ def found_treasure(name, points)
35
+ @found_treasures[name] += points
36
+ end
37
+
38
+ def points
39
+ @found_treasures.values.sum
40
+ end
41
+ end
42
+ end
43
+
44
+ if __FILE__ == $0
45
+ player = StudioGame::Player.new('jase')
46
+ puts player
47
+ puts player.score
48
+ player.boost
49
+ puts player.score
50
+ player.drain
51
+ puts player.score
52
+ end
@@ -0,0 +1,22 @@
1
+ module StudioGame
2
+ module TreasureTrove
3
+ Treasure = Data.define(:name, :points)
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
+ ].freeze
13
+
14
+ def self.random_treasure
15
+ TREASURES.sample
16
+ end
17
+
18
+ def self.treasure_items
19
+ TREASURES.map { |t| "A #{t.name} is worth #{t.points} points." }
20
+ end
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: studio_game_octo
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - octo
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 2025-10-30 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: csv
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '0'
26
+ description: A game of treasure trove
27
+ email: octo@github.com
28
+ executables:
29
+ - studio_game
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - LICENSE
34
+ - README.md
35
+ - bin/players.csv
36
+ - bin/studio_game
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://git.simonblanco.xyz/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.4.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.7.2
63
+ specification_version: 4
64
+ summary: A game of treasure trove
65
+ test_files: []