treasure_hunter_z 2.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 +7 -0
- data/README.md +16 -0
- data/bin/players.csv +5 -0
- data/bin/studio_game +41 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +33 -0
- data/lib/studio_game/clumsy_player.rb +35 -0
- data/lib/studio_game/game.rb +115 -0
- data/lib/studio_game/playable.rb +11 -0
- data/lib/studio_game/player.rb +51 -0
- data/lib/studio_game/treasure_trove.rb +22 -0
- metadata +54 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ecf1d2653dc58cda79d029cdd1f2312c1a9a034d340d85442d71839b21f3e180
|
|
4
|
+
data.tar.gz: f3a29b1495da3048714a93eadbca06a699f98030a765a91c26a57a990d50c97c
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e2c88c09d3cefc725811eca86cebc13c587f47de833056fc5fbd9625304f92dc8c0b355af75a1d3809c7c2c43f99061024690ef547f479c53f3b0edfb4b823a5
|
|
7
|
+
data.tar.gz: def4760dfc1c7a3f004c542cfa927be1631f48567996ee0b35474b497792aacf606760d98e7d878e58e316995c72f358f0808d7687fc5e93299fa9ac876e7f4e
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright (c) <year> <copyright holders>
|
|
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,16 @@
|
|
|
1
|
+
# Installation
|
|
2
|
+
|
|
3
|
+
# Rules and Gameplay
|
|
4
|
+
- The game revolves around characters or players that have various attributes.
|
|
5
|
+
- Health
|
|
6
|
+
- Points
|
|
7
|
+
|
|
8
|
+
- Characters can collect treasures of different kinds, each with their own point values.
|
|
9
|
+
|
|
10
|
+
- At the end of the rounds played, the player with the most total points wins.
|
|
11
|
+
|
|
12
|
+
# Playing
|
|
13
|
+
- To play/run the game, use the the following command: `studio_game`.
|
|
14
|
+
|
|
15
|
+
- You will be prompted to input how many rounds you would like to play. This is to be an integer value, as a numerical character.
|
|
16
|
+
- If you are done playing, or simply do not want to play, you must enter the following command: `quit`.
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
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/berserk_player"
|
|
7
|
+
|
|
8
|
+
def say_hello(name:, health: 100)
|
|
9
|
+
"Hello, I'm #{name.capitalize} and I have #{health}"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
player_1 = StudioGame::Player.new("finn andre", 60)
|
|
13
|
+
player_2 = StudioGame::Player.new("lucy spielberg", 90)
|
|
14
|
+
player_3 = StudioGame::Player.new("jase just")
|
|
15
|
+
player_4 = StudioGame::Player.new("alex bremter", 125)
|
|
16
|
+
|
|
17
|
+
game = StudioGame::Game.new("Winner Takes All")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
file_path = File.join(__dir__, ARGV.shift || "players.csv")
|
|
21
|
+
game.load_players(file_path)
|
|
22
|
+
game.add_player(StudioGame::ClumsyPlayer.new("Klutz", 105))
|
|
23
|
+
game.add_player(StudioGame::BerserkPlayer.new("RAGE MONSRER", 105))
|
|
24
|
+
game.play(3)
|
|
25
|
+
|
|
26
|
+
loop do
|
|
27
|
+
print "Welcome! How many rounds of the game would you like to play (please enter a number or 'exit' to quit): "
|
|
28
|
+
answer = gets.chomp.downcase
|
|
29
|
+
|
|
30
|
+
case answer
|
|
31
|
+
when /^\d+$/
|
|
32
|
+
game.play(answer.to_i)
|
|
33
|
+
when "exit", "quit"
|
|
34
|
+
break
|
|
35
|
+
else
|
|
36
|
+
puts "You entered #{answer}. Please enter a numeric value or 'exit'"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
game.save_high_scores
|
|
40
|
+
|
|
41
|
+
game.print_stats
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require_relative "Player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class BerserkPlayer < Player
|
|
5
|
+
|
|
6
|
+
def initialize(name, points)
|
|
7
|
+
super(name, points)
|
|
8
|
+
@boost_count = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def berserk?
|
|
12
|
+
@boost_count > 5
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def boost
|
|
16
|
+
super
|
|
17
|
+
@boost_count += 1
|
|
18
|
+
puts "Berserker is berserk!" if berserk?
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def drain
|
|
22
|
+
berserk? ? boost : super
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# if __FILE__ == $0
|
|
29
|
+
# berserker = BerserkPlayer.new("berserker", 50)
|
|
30
|
+
# 6.times { berserker.boost}
|
|
31
|
+
# 2.times { berserker.drain}
|
|
32
|
+
# puts berserker.health
|
|
33
|
+
# end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require_relative "Player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
|
|
6
|
+
def initialize(name, points, boost_factor=5)
|
|
7
|
+
super(name, points)
|
|
8
|
+
@boost_factor = boost_factor
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def found_treasure(name, points)
|
|
12
|
+
points = points /2
|
|
13
|
+
super(name, points)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def boost
|
|
17
|
+
@boost_factor.times { super }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
# if __FILE__ == $0
|
|
23
|
+
# clumsy = ClumsyPlayer.new("klutz")
|
|
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
|
+
|
|
30
|
+
# clumsy.found_treasures.each do |name, points|
|
|
31
|
+
# puts "#{name}: #{points} points"
|
|
32
|
+
# end
|
|
33
|
+
|
|
34
|
+
# puts "#{clumsy.points} total points"
|
|
35
|
+
# end
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
require_relative "treasure_trove"
|
|
2
|
+
require_relative "Player"
|
|
3
|
+
require_relative "Auditable"
|
|
4
|
+
|
|
5
|
+
module StudioGame
|
|
6
|
+
class Game
|
|
7
|
+
include Auditable
|
|
8
|
+
attr_reader :title, :players
|
|
9
|
+
|
|
10
|
+
def initialize(title)
|
|
11
|
+
@title = title
|
|
12
|
+
@players = []
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def load_players(from_file)
|
|
16
|
+
File.readlines(from_file, chomp: true).each do |line|
|
|
17
|
+
player = Player.from_csv(line)
|
|
18
|
+
add_player(player)
|
|
19
|
+
end
|
|
20
|
+
rescue Errno::ENOENT
|
|
21
|
+
puts "Sorry #{from_file} does not exist"
|
|
22
|
+
exit 1
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_player(player)
|
|
26
|
+
@players << player
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def roll_die
|
|
30
|
+
roll_value = rand(1..6)
|
|
31
|
+
audit(roll_value)
|
|
32
|
+
roll_value
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def play(rounds = 1)
|
|
36
|
+
puts "\nLet's play #{@title}!"
|
|
37
|
+
puts "-"*20
|
|
38
|
+
puts "\n"
|
|
39
|
+
|
|
40
|
+
puts "The available treasures are"
|
|
41
|
+
puts TreasureTrove.treasure_items
|
|
42
|
+
|
|
43
|
+
puts "\nBefore playing:"
|
|
44
|
+
puts @players
|
|
45
|
+
|
|
46
|
+
1.upto(rounds) do |round_number|
|
|
47
|
+
puts "\nThis is round #{round_number}"
|
|
48
|
+
|
|
49
|
+
@players.each do |player|
|
|
50
|
+
number_rolled = roll_die
|
|
51
|
+
|
|
52
|
+
case number_rolled
|
|
53
|
+
when 1..2
|
|
54
|
+
player.drain
|
|
55
|
+
puts "#{player.name} got drained 😩"
|
|
56
|
+
when 3..4
|
|
57
|
+
puts "#{player.name} got skipped"
|
|
58
|
+
else
|
|
59
|
+
player.boost
|
|
60
|
+
puts "#{player.name} got boosted 😁"
|
|
61
|
+
end
|
|
62
|
+
found_treasure = TreasureTrove.random_treasure
|
|
63
|
+
player.found_treasure(found_treasure.name, found_treasure.points)
|
|
64
|
+
puts "#{player.name} found #{found_treasure.name} worth #{found_treasure.points} points"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
puts "\nAfter playing:"
|
|
69
|
+
puts @players
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
def print_stats
|
|
74
|
+
puts "\n#{@title} Stats: "
|
|
75
|
+
puts "-" * 30
|
|
76
|
+
|
|
77
|
+
sorted_players
|
|
78
|
+
|
|
79
|
+
@players.each do |player|
|
|
80
|
+
puts "\n#{player.name}'s treasure points totals:"
|
|
81
|
+
player.found_treasures.each do |name, points|
|
|
82
|
+
puts "#{name}: #{points}"
|
|
83
|
+
end
|
|
84
|
+
puts "total: #{player.points}"
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
puts "\nHigh Scores: "
|
|
88
|
+
sorted_players.each do |player|
|
|
89
|
+
puts high_score_entry(player)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def high_score_entry(player)
|
|
94
|
+
name = player.name.ljust(20, '.')
|
|
95
|
+
score = player.score.round.to_s.rjust(5)
|
|
96
|
+
"#{name}#{score}"
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def save_high_scores(write_file = "high_scores.txt")
|
|
100
|
+
File.open(write_file, 'w') do |file|
|
|
101
|
+
file.puts "#{@title} High Scores:"
|
|
102
|
+
file.puts "-" * 30
|
|
103
|
+
sorted_players.each do |player|
|
|
104
|
+
file.puts high_score_entry(player)
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def sorted_players
|
|
111
|
+
@players.sort_by { |player| player.score }.reverse
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
end
|
|
115
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require_relative "playable"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
|
|
7
|
+
attr_accessor :name, :health, :found_treasures
|
|
8
|
+
|
|
9
|
+
def initialize(name, health = 100)
|
|
10
|
+
# @name = name.split(" ").map { |name| name.capitalize }.join(" ")
|
|
11
|
+
@name = name.gsub(/\w+/) { |word| word.capitalize }
|
|
12
|
+
@health = health
|
|
13
|
+
@found_treasures = Hash.new(0)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def self.from_csv(line)
|
|
17
|
+
name, health = line.split(",")
|
|
18
|
+
player = Player.new(name, Integer(health))
|
|
19
|
+
rescue ArgumentError
|
|
20
|
+
puts "Whoopsies there. the #{health} is invalid. We've set you up with a default health of 100; woo!"
|
|
21
|
+
player = Player.new(name, 100)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def found_treasure(name, points)
|
|
25
|
+
@found_treasures[name] += points
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def name=(new_name)
|
|
29
|
+
@name = new_name.capitalize
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def points
|
|
33
|
+
@found_treasures.values.sum
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def score
|
|
37
|
+
@health + points
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_s
|
|
41
|
+
"I'm #{@name}! My health = #{@health}, points = #{points}, score = #{score}"
|
|
42
|
+
end
|
|
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
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module TreasureTrove
|
|
2
|
+
|
|
3
|
+
Treasure = Data.define(:name, :points)
|
|
4
|
+
|
|
5
|
+
TREASURES = [
|
|
6
|
+
Treasure.new("pie", 10),
|
|
7
|
+
Treasure.new("coin", 25),
|
|
8
|
+
Treasure.new("flute", 50),
|
|
9
|
+
Treasure.new("compass", 65),
|
|
10
|
+
Treasure.new("key", 80),
|
|
11
|
+
Treasure.new("crown", 90),
|
|
12
|
+
Treasure.new("star", 100),
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
def self.random_treasure
|
|
16
|
+
TREASURES.sample
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def self.treasure_items
|
|
20
|
+
TREASURES.map { |treasure| "A #{treasure.name} is worth #{treasure.points} points" }
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: treasure_hunter_z
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 2.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alex Zuniga
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2024-10-17 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description:
|
|
14
|
+
email: rthe3rd.z@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://rthe3rd.github.io/portfolio/
|
|
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.11
|
|
51
|
+
signing_key:
|
|
52
|
+
specification_version: 4
|
|
53
|
+
summary: Fun treasure seeking game
|
|
54
|
+
test_files: []
|