trevor_game 1.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: 8594d318a127548c8a8b7637d01ede04bba9768ff0fa8f6acaf9995c36253b40
4
+ data.tar.gz: d68f30c7b017cc933a2b656c1b944030a54ed7ef2e3e097e1f99b4b628945726
5
+ SHA512:
6
+ metadata.gz: 44ea0d75c4bdf666c5236a5db6f97136b6297e49ba89eafe8e918008b30b5bc307461ab9a7fcb1fee7ce6415edfad2be1948223305b0b95598318c297a2930b7
7
+ data.tar.gz: 94c77258725fc2366110258d045b3d1f7b77dce8dd9dd33bf7ee22301ab5b467cb26b092021bd5b8f5d3d69fc91a2aee1b9eace03ff7223f8d7c3d35dc52f0ee
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2025 MIT
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,4 @@
1
+ This cli program
2
+ install ruby
3
+ install gem
4
+ gem install trevor_game
@@ -0,0 +1,9 @@
1
+ MayhemFest Iteration: 1 with 23 rounds
2
+ klutz...............3365 + save high scores
3
+ dumby...............1943 + save high scores
4
+ Rocket..............1441 + save high scores
5
+ Gamora..............1391 + save high scores
6
+ Drax................1214 + save high scores
7
+ uloktulo............1138 + save high scores
8
+ Starlord............1128 + save high scores
9
+ Groot...............1075 + save high scores
data/bin/players.csv ADDED
@@ -0,0 +1,5 @@
1
+ Starlord,50
2
+ Gamora,75
3
+ Rocket,100
4
+ Drax,125
5
+ Groot,80
data/bin/studio_game ADDED
@@ -0,0 +1,91 @@
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/berserker"
7
+
8
+
9
+ # puts __FILE__ + ' run' # stays the same
10
+ # puts $0 + ' run' #changes
11
+ #
12
+ # p (__dir__ + " dir")
13
+ # p ($0 + " $0")
14
+ # p (__FILE__ + " __FILE__")
15
+ #
16
+ players_file = File.join(__dir__, "players.csv")
17
+ # the absolute path to the directory where the current file lives is stored in the __dir__ variable
18
+
19
+
20
+ game_1 = Studio_game::Game.new("MayhemFest")
21
+
22
+ game_1.load_players(ARGV.shift || players_file)
23
+ game_1.players_<<(Studio_game::ClumsyPlayer.new("klutz", 105))
24
+ clumsy = Studio_game::ClumsyPlayer.new("dumby", 98)
25
+ game_1.add_player(clumsy)
26
+ berseker = Studio_game::Berserker.new("uloktulo", 50)
27
+ game_1.add_player(berseker)
28
+
29
+ puts game_1.high_score_entry(Studio_game::Player.new("jimbi", 1000))
30
+
31
+ def reset_stats(game_name)
32
+ game_name.players_.each do |k|
33
+ k.reset_health
34
+ end
35
+ game_name.players_.each {|r| r.clear_treasure}
36
+ end
37
+
38
+ loop do
39
+ print "\nHow many times do you want to play #{game_1.game_name}: ('quit', to end)"
40
+ plays = gets.chomp.downcase
41
+ case plays
42
+ when /^\d+$/
43
+ game_1.play_the_game(plays.to_i)
44
+ game_1.save_high_scores()
45
+
46
+ when "exit", "quit", "end", "e", "q"
47
+ game_1.print_stats
48
+ puts clumsy.boost_factor
49
+ break
50
+ else
51
+ print"please enter a number or 'quit'"
52
+ end
53
+ end
54
+
55
+ reset_stats(game_1)
56
+ puts '-' * 50 + "new game"
57
+
58
+
59
+ game_2 = Studio_game::Game.new("Nuclear city")
60
+
61
+ players_file = File.join(__dir__, "players.csv")
62
+
63
+
64
+ game_2.load_players(players_file)
65
+
66
+ loop do
67
+ print "\nHow many rounds do you want to play #{game_2.game_name}?: ('quit', to end) "
68
+ plays = gets.chomp.downcase
69
+ case plays
70
+ when /^\d+$/
71
+ game_2.play_the_game(plays.to_i)
72
+ game_2.save_high_scores()
73
+ game_2.print_stats
74
+ reset_stats(game_2)
75
+ when "exit", "end", "quit", "e", "q"
76
+ break
77
+ else
78
+ print"please enter a number or 'quit'"
79
+ end
80
+ end
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
@@ -0,0 +1,10 @@
1
+ module Studio_game
2
+ module Auditable
3
+
4
+ def audit(roll=0)
5
+ puts "Audit: Rolled a #{roll}"
6
+ return roll
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,37 @@
1
+ require_relative 'player'
2
+ module Studio_game
3
+ class Berserker < Player
4
+ def initialize(name, health = 100, tracker=0)
5
+ @tracker = tracker
6
+ super(name, health)
7
+ end
8
+
9
+ def boost
10
+ @tracker += 1
11
+ super()
12
+ puts "#{@name} is BErSERKKKKK! " if berserk?
13
+ end
14
+
15
+ def berserk?
16
+ @tracker >= 6 ? true : false
17
+ end
18
+
19
+ def drain
20
+ if @tracker >= 6
21
+ boost
22
+ else
23
+ super
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+
30
+ if __FILE__ == $0
31
+ b1 = Berserker.new("jambo", 50, 0)
32
+ 6.times { b1.boost}
33
+ 20.times { b1.drain}
34
+
35
+ puts b1.health
36
+ p Berserker.ancestors
37
+ end
@@ -0,0 +1,44 @@
1
+
2
+ require_relative 'player'
3
+ module Studio_game
4
+ class ClumsyPlayer < Player
5
+ attr_reader :boost_factor
6
+ def initialize(name, health, boost_factor=10)
7
+ super(name, health)
8
+ @boost_factor = boost_factor
9
+ end
10
+
11
+ def boost = @boost_factor.times { super }
12
+
13
+ def found_treasure(name, points)
14
+ points = points/2
15
+ super(name, points)
16
+ end
17
+
18
+
19
+ def print_treasures
20
+ @found_treasures.each do |key, value|
21
+ puts "found a #{key} worth #{value} points"
22
+ end
23
+ end
24
+
25
+
26
+ end
27
+ end
28
+
29
+ if __FILE__ == $0
30
+ clumsy = ClumsyPlayer.new("klutz", 70, 50)
31
+
32
+ clumsy.found_treasure("flute", 50)
33
+ clumsy.found_treasure("flute", 50)
34
+ clumsy.found_treasure("flute", 50)
35
+ clumsy.found_treasure("star", 100)
36
+ clumsy.boost
37
+
38
+ clumsy.found_treasures.each do |name, points|
39
+ puts "#{name}: #{points} points"
40
+ clumsy.treasure_total(points)
41
+ end
42
+ puts "#{clumsy.score} total score"
43
+ puts "#{clumsy.sum} total treasure points"
44
+ end
@@ -0,0 +1,143 @@
1
+
2
+ require_relative "./treasure_trove"
3
+ require_relative "./player"
4
+ require_relative "auditable"
5
+
6
+ module Studio_game
7
+ class Game
8
+ include Auditable
9
+ attr_reader :game_name
10
+ attr_accessor :players_
11
+ def initialize(game_name)
12
+ @game_name = game_name
13
+ @game_round = 0
14
+ @players_ = []
15
+ @test_string = ''
16
+ @round_count = 0
17
+ end
18
+
19
+ def load_players(from_file)
20
+ File.readlines(from_file, chomp: true).each do |l|
21
+ p = Player.load_players_(l)
22
+ @players_ << p
23
+ end
24
+ rescue Errno::ENOENT
25
+ puts "#{from_file} does not exist ..."
26
+ exit 1
27
+ end
28
+
29
+ def game_round_count = @game_round += 1
30
+
31
+ def save_high_scores(to_file = "high_scores.txt")
32
+ File.open(to_file, "a") do |file|
33
+ file.puts "#{@game_name} Iteration: #{ game_round_count} with #{@round_count} rounds"
34
+ sorted_players.each do |l|
35
+ file.puts high_score_entry(l, "save high scores")
36
+ end
37
+ end
38
+ end
39
+
40
+ def round_count
41
+ @round_count
42
+ end
43
+
44
+ def roll = rand(1..6) # not needed
45
+
46
+ def roll_die
47
+ # number = [1,1,2,5,6,6].sample
48
+ number = rand(1..6)
49
+ audit(number) # audit is called on the Auditable module
50
+ return number
51
+ end
52
+
53
+
54
+ def to_s = "#{@game_name} is the name of the game"
55
+
56
+ def add_player(player)
57
+ @players_ << player
58
+ end
59
+
60
+ def play_the_game(rounds = 1)
61
+ @round_count = rounds
62
+ puts Treasure_Trove.treasure_items
63
+ 1.upto(@round_count) do |i|
64
+ puts '*' * 10 + " #{@game_name} " + '*' * 10 + " round #{i}"
65
+ puts "the following treasures are in the map:"
66
+ Treasure_Trove::TREASURES.each do |treasure|
67
+ puts "·"*30 + "#{treasure.name} worth #{treasure.points} points" + "·"*30
68
+ end
69
+ puts ("Before the carnage").upcase + "\n"
70
+ @players_.each { |k| puts "#{k.name} starting score: #{k.score}"}
71
+ @players_.each do |pdd|
72
+ case roll_die
73
+ when 1..2
74
+ pdd.drain
75
+ puts "#{pdd.name} got drained 😩 " \
76
+ "Health now at #{pdd.health}"
77
+ when 3..4
78
+ puts "#{pdd.name} got skipped"
79
+ else
80
+ pdd.boost
81
+ puts "#{pdd.name} got boosted 😁 " \
82
+ "Health now at #{pdd.health}"
83
+ end
84
+ item_found = Treasure_Trove.random_treasure
85
+ pdd.found_treasure(item_found.name, item_found.points)
86
+ pdd.treasure_total(item_found.points)
87
+ puts "#{pdd.name} found a #{item_found.name} worth #{item_found.points} points"
88
+ end
89
+ puts (("After the carnage".upcase) +"\n")
90
+ puts @players_
91
+ end
92
+ end
93
+
94
+
95
+ def sorted_players
96
+ sort_players = []
97
+ sort_players = @players_.sort_by { |player| player.score }.reverse
98
+ puts "--High Scores--"
99
+ sort_players.each do |iter|
100
+ padding = 12
101
+ name_length = iter.name.length
102
+ dot_count = padding - name_length
103
+ puts "#{iter.name}" + "." * dot_count + "#{iter.score}"
104
+ end
105
+ end
106
+
107
+ def print_stats
108
+ game_name_len = @game_name.length
109
+ left_padding = 30
110
+ right_padding = 40 - game_name_len
111
+ puts "ª"*left_padding + " #{@game_name} " + "ª"*right_padding
112
+ puts "ª"*left_padding + " Stats: " + "ª"*34
113
+ print_score
114
+ listy = @players_.sort_by{|t| t.score}.reverse
115
+ listy.each {|ele| puts high_score_entry(ele, "print stats")}
116
+ end
117
+
118
+ def high_score_entry(player_obj, b = "yes")
119
+ name = player_obj.name.ljust(12, '.')
120
+ score = player_obj.score.to_s.rjust(12, '.')
121
+ "#{name}#{score} + #{b}"
122
+ end
123
+
124
+
125
+ def print_score
126
+ @dot_count = 0
127
+ @players_.each do |player|
128
+ total_value = 0
129
+ puts "#{player.name} treasure totals: " + "\n"
130
+ player.found_treasures.each do | item |
131
+ padding = 15
132
+ name_length = (item[0].length) + 1
133
+ @dot_count = padding - name_length
134
+ puts "#{item[0]}:" + "." * @dot_count + "#{item[1]}" + "\n"
135
+ total_value += item[1]
136
+ end
137
+ puts "total:" + "." * 9 + "$#{total_value}" + "\n"
138
+ end
139
+ end
140
+ end
141
+ end
142
+
143
+
@@ -0,0 +1,10 @@
1
+ module Playable
2
+ def boost
3
+ self.health+=15 # self. relies on the health attr_accessor attribute
4
+ # you dont need to rely on @health to be an instance variable
5
+ end
6
+
7
+ def drain
8
+ self.health-=10
9
+ end
10
+ end
@@ -0,0 +1,81 @@
1
+ require_relative "./treasure_trove"
2
+ require_relative "./game"
3
+ require_relative "playable"
4
+ module Studio_game
5
+ class Player
6
+ include Playable
7
+ attr_reader :score, :found_treasures, :sum
8
+ attr_accessor :name, :health
9
+
10
+ def initialize(name, health = 100)
11
+ @name = name
12
+ @health = health
13
+ @start_health = health
14
+ @score = @health + @name.length
15
+ @found_treasures = Hash.new(0)
16
+ @sum = 0
17
+ end
18
+
19
+ def self.load_players_(line)
20
+ name, health = line.split(',')
21
+ Player.new(name, Integer(health))
22
+ rescue ArgumentError
23
+ puts "ignored invalid health: #{health}"
24
+ Player.new(name)
25
+ end
26
+
27
+ def found_treasure(name, pointsy)
28
+ @found_treasures[name] += pointsy
29
+
30
+ end
31
+
32
+ def treasure_total(treasure_value)
33
+ @sum += treasure_value
34
+ end
35
+
36
+
37
+ def clear_treasure
38
+ @found_treasures = Hash.new(0)
39
+ @sum = 0
40
+ end
41
+
42
+ def reset_health
43
+ puts 'beginning health: ' + @start_health.to_s
44
+ puts 'working health: ' + @health.to_s
45
+ @health = @start_health
46
+ #@health = 100
47
+ end
48
+
49
+ def name=(new_name)
50
+ @name = new_name.capitalize
51
+ end
52
+
53
+ def score = @health + @name.length + @sum
54
+
55
+ def to_s = "I'm #{@name} with a health of #{@health} and a score of #{score} and #{@sum} points and I found #{@found_treasures}"
56
+
57
+
58
+
59
+ end
60
+ end
61
+
62
+ # puts __FILE__ + ' source' # this is always the same file path
63
+ # puts $0 + ' source' # this $0 changes depending on where it is called use this to see if the file was ran directly
64
+
65
+ if __FILE__ == $0
66
+ player = Player.new("jase", 100)
67
+ p player.name
68
+
69
+
70
+ ## puts player.health
71
+ ## player.boost
72
+ ## puts player.health
73
+ ## player.drain
74
+ ## puts player.health
75
+ ## player.reset_health
76
+ ## puts player.health
77
+ ##
78
+ ## puts __FILE__
79
+ ## puts __dir__
80
+ end
81
+
@@ -0,0 +1 @@
1
+ game_test
@@ -0,0 +1,45 @@
1
+
2
+
3
+ module Studio_game
4
+ module Treasure_Trove
5
+
6
+ Treasure = Data.define(:name, :points)
7
+ # Treasure is a Data Constant Object b/c it is capitalized, Data.define creates immutable object attributes
8
+ # Treasure is an Immutable Constant
9
+ TREASURES = [ # this is a constanct b/c it is all caps and defined outside a method
10
+ Treasure.new("pie", 10),
11
+ Treasure.new("coin", 25),
12
+ Treasure.new("flute", 50),
13
+ Treasure.new("compass", 65),
14
+ Treasure.new("key", 80),
15
+ Treasure.new("crown", 90),
16
+ Treasure.new("star", 100),
17
+ Treasure.new("shit", 0)
18
+ ]
19
+
20
+
21
+ def self.random_treasure #need self because this is a class method not an instance method of a class object
22
+ TREASURES.sample
23
+ end
24
+
25
+ def self.treasure_items
26
+ Treasure_Trove::TREASURES.map{ |ele| ele.name}
27
+ end
28
+
29
+ end
30
+ end
31
+
32
+
33
+ if __FILE__ == $0
34
+
35
+ puts Treasure_Trove::Treasure.class
36
+ puts Treasure_Trove::TREASURES.class
37
+ len = (Treasure_Trove::TREASURES.length)-1
38
+ 0.upto(len) do |iter|
39
+ puts ("#{Treasure_Trove::TREASURES[iter].points}, #{Treasure_Trove::TREASURES[iter].name}")
40
+ end
41
+ puts Treasure_Trove.random_treasure
42
+ puts Treasure_Trove::Treasure.class
43
+ puts Treasure_Trove.treasure_items
44
+
45
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: trevor_game
3
+ version: !ruby/object:Gem::Version
4
+ version: '1.0'
5
+ platform: ruby
6
+ authors:
7
+ - Trevor Muench
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-04-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: trevormuench1@gmail.com
15
+ executables:
16
+ - studio_game
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.txt
21
+ - README.md
22
+ - bin/high_scores.txt
23
+ - bin/players.csv
24
+ - bin/studio_game
25
+ - lib/studio_game/auditable.rb
26
+ - lib/studio_game/berserker.rb
27
+ - lib/studio_game/clumsy_player.rb
28
+ - lib/studio_game/game.rb
29
+ - lib/studio_game/playable.rb
30
+ - lib/studio_game/player.rb
31
+ - lib/studio_game/tempCodeRunnerFile.rb
32
+ - lib/studio_game/treasure_trove.rb
33
+ homepage: https://internet.com/games
34
+ licenses:
35
+ - MIT
36
+ metadata: {}
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 3.2.0
46
+ required_rubygems_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubygems_version: 3.4.10
53
+ signing_key:
54
+ specification_version: 4
55
+ summary: cli game
56
+ test_files: []