studio_game_trideep 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 +7 -0
- data/LICENSE.txt +5 -0
- data/README.md +0 -0
- data/bin/players.csv +5 -0
- data/bin/studio_game +27 -0
- data/lib/studio_game/auditable.rb +7 -0
- data/lib/studio_game/berserk_player.rb +27 -0
- data/lib/studio_game/clumsy_player.rb +18 -0
- data/lib/studio_game/game.rb +92 -0
- data/lib/studio_game/playable.rb +9 -0
- data/lib/studio_game/player.rb +51 -0
- data/lib/studio_game/treasure_trove.rb +22 -0
- metadata +50 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ff1bbed9c6631102ff6f481657782988a9812ad9af8f7cb29effb4205868df13
|
|
4
|
+
data.tar.gz: 7b5558e8144ac00e488320f67c722c7be80fb5f8fc909a071b9fae6e292b7700
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 7889225afd819d0910d7ace110d9040b21b9b788c8851cf5b3b65116fc7585e8fd482c0fc58984490e35b0552eca915bb0d31d40d7fa8ac90cb08b8a664ec454
|
|
7
|
+
data.tar.gz: 4360770bfdf186ada5990c4d502e0e9272cbfd0e348a1b0988329e8d2836561241bfe29402f5e5063cc6c2476c60c448c5e13f2fec69359c936edd8503af7ccd
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
Copyright 2025 Trideep Roy
|
|
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.
|
|
4
|
+
|
|
5
|
+
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
|
File without changes
|
data/bin/players.csv
ADDED
data/bin/studio_game
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
game = StudioGame::Game.new("Winner Takes All")
|
|
8
|
+
players_file = File.join(__dir__, "players.csv")
|
|
9
|
+
game.load_players(ARGV.shift || players_file)
|
|
10
|
+
klutz = StudioGame::ClumsyPlayer.new("klutz", 105, 3)
|
|
11
|
+
game.add_player(klutz)
|
|
12
|
+
berserker = StudioGame::BerserkPlayer.new("berserker", 50)
|
|
13
|
+
game.add_player(berserker)
|
|
14
|
+
loop do
|
|
15
|
+
print "How many rounds? ('quit' to exit) "
|
|
16
|
+
answer = gets.chomp.downcase
|
|
17
|
+
case answer
|
|
18
|
+
when /^\d+$/
|
|
19
|
+
game.play(answer.to_i)
|
|
20
|
+
when "quit", "exit"
|
|
21
|
+
game.stats
|
|
22
|
+
break
|
|
23
|
+
else
|
|
24
|
+
puts "Please enter a number or quit to exit."
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
game.save_high_scores
|
|
@@ -0,0 +1,27 @@
|
|
|
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 boost
|
|
11
|
+
@boost_count += 1
|
|
12
|
+
super
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def berserk?
|
|
16
|
+
@boost_count >= 5
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def drain
|
|
20
|
+
if berserk?
|
|
21
|
+
boost
|
|
22
|
+
else
|
|
23
|
+
super
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require_relative "player"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class ClumsyPlayer < Player
|
|
5
|
+
def initialize(name, health = 100, boost_factor = 1)
|
|
6
|
+
super(name, health)
|
|
7
|
+
@boost_factor = boost_factor
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def found_treasure(name, points)
|
|
11
|
+
super(name, points/2.0)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def boost
|
|
15
|
+
@boost_factor.times { super }
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require_relative "treasure_trove.rb"
|
|
2
|
+
require_relative "auditable"
|
|
3
|
+
|
|
4
|
+
module StudioGame
|
|
5
|
+
class Game
|
|
6
|
+
include Auditable
|
|
7
|
+
attr_reader :players, :title
|
|
8
|
+
|
|
9
|
+
def initialize(title)
|
|
10
|
+
@players = []
|
|
11
|
+
@title = title
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def load_players(from_file)
|
|
15
|
+
File.readlines(from_file, chomp: true).each do |line|
|
|
16
|
+
player = Player.from_csv(line)
|
|
17
|
+
add_player(player)
|
|
18
|
+
end
|
|
19
|
+
rescue Errno::ENOENT => e
|
|
20
|
+
puts "Could not load players from '#{from_file}'."
|
|
21
|
+
exit 1
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def save_high_scores(to_file = "high_scores.txt")
|
|
25
|
+
File.open(to_file, "w") do |file|
|
|
26
|
+
file.puts "#{title} high scores:"
|
|
27
|
+
file.puts get_high_scores
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def add_player(player)
|
|
32
|
+
@players.push(player)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def roll_dice
|
|
36
|
+
loaded_die = [1,1,2,5,6,6]
|
|
37
|
+
dice = rand(1..6)
|
|
38
|
+
dice = loaded_die.sample
|
|
39
|
+
audit(dice)
|
|
40
|
+
dice
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def play(rounds=1)
|
|
44
|
+
puts "\nLet's play #{@title}"
|
|
45
|
+
puts "List of treasures: "
|
|
46
|
+
TreasureTrove::TREASURES.each { |t| puts "A #{t.name} is worth #{t.points} points." }
|
|
47
|
+
1.upto(rounds) do |round|
|
|
48
|
+
puts "\nRound #{round}"
|
|
49
|
+
@players.each do |player|
|
|
50
|
+
dice = roll_dice
|
|
51
|
+
case dice
|
|
52
|
+
when 1..2
|
|
53
|
+
player.drain
|
|
54
|
+
puts "#{player.name} got drained"
|
|
55
|
+
when 5..6
|
|
56
|
+
player.boost
|
|
57
|
+
puts "#{player.name} got boosted"
|
|
58
|
+
else
|
|
59
|
+
puts "#{player.name} got skipped"
|
|
60
|
+
end
|
|
61
|
+
treasure = TreasureTrove.random_treasure
|
|
62
|
+
player.found_treasure(treasure.name, treasure.points)
|
|
63
|
+
puts "#{player.name} found #{treasure.name} worth #{treasure.points}."
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def get_high_scores
|
|
69
|
+
@players
|
|
70
|
+
.sort_by { |p| p.score }
|
|
71
|
+
.reverse
|
|
72
|
+
.map { |p| "#{p.name.ljust(20, '.')} #{p.score.to_s.rjust(7)}"}
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def stats
|
|
76
|
+
header = "\n#{@title} Stats: "
|
|
77
|
+
puts header
|
|
78
|
+
puts '-' * header.length
|
|
79
|
+
puts @players
|
|
80
|
+
@players.each do |p|
|
|
81
|
+
puts "\n#{p.name}'s treasure point totals: "
|
|
82
|
+
p.found_treasures.each { |treasure, points| puts "#{treasure}: #{points}" }
|
|
83
|
+
puts "total: #{p.points}"
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
puts "\nHigh scores: "
|
|
87
|
+
puts get_high_scores
|
|
88
|
+
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require_relative "playable"
|
|
2
|
+
|
|
3
|
+
module StudioGame
|
|
4
|
+
class Player
|
|
5
|
+
include Playable
|
|
6
|
+
|
|
7
|
+
attr_reader :name, :found_treasures
|
|
8
|
+
attr_accessor :health
|
|
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 self.from_csv(line)
|
|
17
|
+
name, health = line.split(",")
|
|
18
|
+
Player.new(name, Integer(health))
|
|
19
|
+
rescue ArgumentError
|
|
20
|
+
puts "Unable to read #{name}'s health. Will use default value for health."
|
|
21
|
+
Player.new(name)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def to_s
|
|
25
|
+
"I'm #{@name} with health = #{@health}, points = #{points}, and score = #{score}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def name=(new_name)
|
|
29
|
+
@name = new_name.capitalize
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def points = @found_treasures.values.sum
|
|
33
|
+
|
|
34
|
+
def score = @health + points
|
|
35
|
+
|
|
36
|
+
def found_treasure(name, points)
|
|
37
|
+
@found_treasures[name] += points
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if __FILE__ == $0
|
|
44
|
+
player = StudioGame::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
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
|
|
2
|
+
module StudioGame
|
|
3
|
+
module TreasureTrove
|
|
4
|
+
|
|
5
|
+
Treasure = Data.define(:name, :points)
|
|
6
|
+
|
|
7
|
+
TREASURES = [
|
|
8
|
+
Treasure.new('Pie', 10),
|
|
9
|
+
Treasure.new('Coin', 25),
|
|
10
|
+
Treasure.new('Flute', 50),
|
|
11
|
+
Treasure.new('Compass', 65),
|
|
12
|
+
Treasure.new('Key', 80),
|
|
13
|
+
Treasure.new('Crown', 90),
|
|
14
|
+
Treasure.new('Star', 100)
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
def self.random_treasure
|
|
18
|
+
TREASURES.sample
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
end
|
|
22
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: studio_game_trideep
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Trideep Roy
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
email: trideepraj.roychoudhury@gmail.com
|
|
13
|
+
executables:
|
|
14
|
+
- studio_game
|
|
15
|
+
extensions: []
|
|
16
|
+
extra_rdoc_files: []
|
|
17
|
+
files:
|
|
18
|
+
- LICENSE.txt
|
|
19
|
+
- README.md
|
|
20
|
+
- bin/players.csv
|
|
21
|
+
- bin/studio_game
|
|
22
|
+
- lib/studio_game/auditable.rb
|
|
23
|
+
- lib/studio_game/berserk_player.rb
|
|
24
|
+
- lib/studio_game/clumsy_player.rb
|
|
25
|
+
- lib/studio_game/game.rb
|
|
26
|
+
- lib/studio_game/playable.rb
|
|
27
|
+
- lib/studio_game/player.rb
|
|
28
|
+
- lib/studio_game/treasure_trove.rb
|
|
29
|
+
homepage: ''
|
|
30
|
+
licenses:
|
|
31
|
+
- MIT
|
|
32
|
+
metadata: {}
|
|
33
|
+
rdoc_options: []
|
|
34
|
+
require_paths:
|
|
35
|
+
- lib
|
|
36
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: 3.4.4
|
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
requirements: []
|
|
47
|
+
rubygems_version: 3.6.7
|
|
48
|
+
specification_version: 4
|
|
49
|
+
summary: Command-line game of random chance.
|
|
50
|
+
test_files: []
|