ultimate_adventure_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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 481762432d1bd59d1169d57f4b4067995baf392d8bdcb761a301ecd6ce4f148a
4
+ data.tar.gz: ce3494449f47126f029c5d3524eba39255dbef8361bee36a5a6d82e91741dff2
5
+ SHA512:
6
+ metadata.gz: 10fb0e3c002f71fb1002d862df3274d3a0c04a3d0764844695092ba2714194c71d06c257a12212f26134d9bc07d1301a3a6cc020ecf8312d7074b642853c74f9
7
+ data.tar.gz: d4cd0fa5ccf3ca40e256c9f5877cd8205563a671a9da307b2fbfc27275c7076bc408a6098f8f8e852dfa410b3b80b934c7d00df7c4fe1a103fb103ee619d3fcc
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Edgar Cardenas
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,10 @@
1
+ # studio_game
2
+
3
+ A fun and interactive game implemented as a Ruby gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'studio_game', '~> 1.0.0'
data/bin/players.csv ADDED
@@ -0,0 +1,4 @@
1
+ Finn,60
2
+ Lucy,90
3
+ Jase,100
4
+ Alex,125
data/bin/studio_game ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative "../lib/studio_game/player"
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
+
8
+ # Assuming Player and other classes are in the StudioGame module
9
+ player_1 = StudioGame::Player.new("finn", 60)
10
+ player_2 = StudioGame::Player.new("lucy", 90)
11
+ player_3 = StudioGame::Player.new("jase")
12
+ player_4 = StudioGame::Player.new("alex", 125)
13
+
14
+ game = StudioGame::Game.new("Winner Takes All")
15
+
16
+ players_file = ARGV.shift || File.join(__dir__, "players.csv")
17
+ game.load_players(players_file)
18
+
19
+ game.print_stats
20
+
21
+ loop do
22
+ print "\nHow many game rounds? ('quit' to exit) "
23
+ answer = gets.chomp.downcase
24
+
25
+ case answer
26
+ when /^\d+$/
27
+ game.play(answer.to_i)
28
+ when "quit", "exit"
29
+ game.print_stats
30
+ break
31
+ else
32
+ puts "Please enter a number or 'quit'"
33
+ end
34
+ end
35
+
36
+ clumsy = StudioGame::ClumsyPlayer.new("klutz", 105)
37
+ game.add_player(clumsy)
38
+
39
+ berserk = StudioGame::BerserkPlayer.new("berserker", 50)
40
+ game.add_player(berserk)
41
+
42
+ game.save_high_scores
@@ -0,0 +1,8 @@
1
+
2
+ module StudioGame
3
+ module Auditable
4
+ def audit(number)
5
+ puts "Audit: Rolled a #{number}"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,32 @@
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
+
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,24 @@
1
+ require_relative "player"
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+ def found_treasure(name, points)
6
+ points = points / 2.0
7
+ super(name, points)
8
+ end
9
+ end
10
+
11
+ if __FILE__ == $0
12
+ clumsy = ClumsyPlayer.new("klutz")
13
+
14
+ clumsy.found_treasure("flute", 50)
15
+ clumsy.found_treasure("flute", 50)
16
+ clumsy.found_treasure("flute", 50)
17
+ clumsy.found_treasure("star", 100)
18
+
19
+ clumsy.found_treasures.each do |name, points|
20
+ puts "#{name}: #{points} points"
21
+ end
22
+ puts "#{clumsy.points} total points"
23
+ end
24
+ end
@@ -0,0 +1,108 @@
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
+ end
13
+
14
+ def add_player(player)
15
+ @players << player
16
+ end
17
+ def load_players(from_file)
18
+ File.readlines(from_file, chomp: true).each do |line|
19
+ player = Player.from_csv(line)
20
+ add_player(player)
21
+ end
22
+ rescue Errno::ENOENT
23
+ puts "Whoops, #{from_file} not found"
24
+ end
25
+
26
+ def save_high_scores(to_file = "high_scores.txt")
27
+ File.open(to_file, "w") do |file|
28
+ file.puts "#{@title} High Scores:"
29
+
30
+ # Sort players by score in descending order
31
+ sorted_players.each do |player|
32
+ file.puts "#{player.name.ljust(20, '.')} #{player.score.to_s.rjust(5)}"
33
+ end
34
+ end
35
+ end
36
+
37
+ def print_stats
38
+ puts "#{@title} Game Stats:"
39
+ puts "-" * 30
40
+
41
+ puts "Players' Scores:"
42
+ sorted_players.each do |player|
43
+ puts "#{player.name.ljust(20, '.')} #{player.score.to_s.rjust(5)}"
44
+ end
45
+
46
+
47
+ @players.each do |player|
48
+ puts "\n#{player.name}'s treasure point totals:"
49
+ player.found_treasures.each do |name, points|
50
+ puts "#{name}: #{points}"
51
+ end
52
+ puts "total: #{player.points}"
53
+ end
54
+
55
+ puts "\nHigh Scores:"
56
+ sorted_players.each do |player|
57
+ name = player.name.ljust(20, ".")
58
+ score = player.score.to_s.rjust(5)
59
+ puts "#{name}#{score}"
60
+ end
61
+ end
62
+
63
+ def sorted_players
64
+ @players.sort_by { |player| player.score }.reverse
65
+ end
66
+
67
+ def play(rounds = 1)
68
+ puts "\nLet's play #{@title}!"
69
+
70
+ puts "Treasures available in the game:"
71
+ puts TreasureTrove.treasure_items
72
+
73
+ puts "\nBefore playing:"
74
+ puts @players
75
+
76
+ 1.upto(rounds) do |round|
77
+ puts "\nRound #{round}:"
78
+
79
+ @players.each do |player|
80
+ case roll_die
81
+ when 1..2
82
+ player.drain
83
+ puts "#{player.name} got drained 😩"
84
+ when 3..4
85
+ puts "#{player.name} got skipped"
86
+ else
87
+ player.boost
88
+ puts "#{player.name} got boosted 😁"
89
+ end
90
+ treasure = TreasureTrove.random_treasure
91
+ player.found_treasure(treasure.name, treasure.points)
92
+ puts "#{player.name} found a #{treasure.name} worth #{treasure.points} points"
93
+ end
94
+ end
95
+
96
+ puts "\nAfter playing:"
97
+ puts @players
98
+ end
99
+
100
+ private
101
+ def roll_die
102
+ number = rand(1..6)
103
+ audit(number)
104
+ number
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,11 @@
1
+ module StudioGame
2
+ module Playable
3
+ def drain
4
+ self.health -= 10
5
+ end
6
+
7
+ def boost
8
+ self.health += 15
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
+
7
+ attr_accessor :name, :health
8
+ attr_reader :found_treasures
9
+
10
+ def initialize(name, health = 100)
11
+ @name = name.capitalize
12
+ @health = health
13
+ @found_treasures = Hash.new(0)
14
+ end
15
+
16
+ def found_treasure(name, points)
17
+ @found_treasures[name] += points
18
+ end
19
+
20
+ def self.from_csv(line)
21
+ name, health = line.split(',')
22
+ Player.new(name, Integer(health))
23
+ rescue ArgumentError
24
+ puts "Ignored invalid health: #{health}"
25
+ Player.new(name)
26
+ end
27
+
28
+ def to_s
29
+ "I'm #{@name} with a health = #{@health}, points #{points}, and a score = #{score}: "
30
+ end
31
+
32
+
33
+ def score
34
+ @health + points
35
+ end
36
+
37
+ def points
38
+ @found_treasures.values.sum
39
+ end
40
+ end
41
+
42
+
43
+ if __FILE__ == $0
44
+ player = Player.new("jase")
45
+ puts player.name
46
+ puts player.health
47
+ player.boost
48
+ puts player.health
49
+ player.drain
50
+ puts player.health
51
+ end
52
+ end
@@ -0,0 +1,24 @@
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} points" }
20
+ end
21
+
22
+
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,54 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ultimate_adventure_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Edgar Cardenas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: edgarpalomeque7@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/edgarcardenas7/adventure_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.4.10
51
+ signing_key:
52
+ specification_version: 4
53
+ summary: An exciting adventure game
54
+ test_files: []