gabby_studio_game 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9e420ba5cc824544687a2e373d5c8fec45df6044c9fb243fcfc6f44bd953d117
4
+ data.tar.gz: '095495b62e98dc0fcc68da3435f249ab0f790e3ecb8352ca882cc5a0090d07d3'
5
+ SHA512:
6
+ metadata.gz: 7195c5b4f35cb66892fcc781a6a9a1ca0c7804b54f0dd199eeda70c18afc327808b1e4c2b5d68b7e4892b947090f09637a274bb3cab43b78f9f1b1e9449bd499
7
+ data.tar.gz: cc5dd43e7080e9f91444df1b40536b99e1a0738349db9cb979a704187aba60facf5ffe65ea62ee76e0f9ebe1546824ac21b98bf126ce076492227757d565eaee
data/LICENSE.txt ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) <year> <copyright holders>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ Just a good game by me.
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,56 @@
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/beserk_player"
7
+
8
+ player_1 = StudioGame::Player.new("finn", 60)
9
+ player_2 = StudioGame::Player.new("lucy", 90)
10
+ player_3 = StudioGame::Player.new("jase")
11
+ player_4 = StudioGame::Player.new("alex", 125)
12
+
13
+ game = StudioGame::Game.new("Winner Takes All")
14
+
15
+ players_file = File.join(__dir__, "players.csv")
16
+
17
+ clumsy = StudioGame::ClumsyPlayer.new("klutz", 105)
18
+ game.add_player(clumsy)
19
+
20
+ beserker = StudioGame::BerserkPlayer.new("beserker", 50)
21
+ game.add_player(beserker)
22
+
23
+ game.load_players(ARGV.shift || players_file)
24
+ # game.add_player(player_1)
25
+ # game.add_player(player_2)
26
+ # game.add_player(player_3)
27
+ # game.add_player(player_4)
28
+
29
+ loop do
30
+ print "How many rounds would you like to play? ('quit' to exit)"
31
+ answer = gets.chomp.downcase
32
+
33
+ case answer
34
+ when /^\d+$/
35
+ game.play(answer.to_i)
36
+ when "quit", "exit"
37
+ break
38
+ else
39
+ puts "Please type a number for the rounds you want to play or 'quit'"
40
+ end
41
+ end
42
+
43
+ game.print_stats
44
+ game.save_high_scores
45
+
46
+ # player_5 = Player.new("Alvin")
47
+ # player_6 = Player.new("Simon")
48
+ # player_7 = Player.new("Bob")
49
+
50
+ # game = Game.new("Chipmunks")
51
+ # game.add_player(player_5)
52
+ # game.add_player(player_6)
53
+ # game.add_player(player_7)
54
+ # game.play(2)
55
+
56
+ game.print_stats
@@ -0,0 +1,9 @@
1
+ def say_hello(name:, health: 100)
2
+ "I'm #{name} with a health of #{health}"
3
+ end
4
+
5
+ puts say_hello(name:"gabby", health: 60)
6
+ puts say_hello(health: 90, name: "annie")
7
+ puts say_hello(name:"erin")
8
+ puts say_hello(name:"adam", health: 125)
9
+
@@ -0,0 +1,9 @@
1
+ puts "Let's play a game! \n\n \t3 \n \t2 \n \t1 \n\n"
2
+ puts "🚀" * 25
3
+
4
+ player = "finn"
5
+ health_value = 60
6
+
7
+ puts "#{player.capitalize}'s health is #{health_value}".center(50, "*")
8
+
9
+ puts "#{player.capitalize.ljust(30, ".")}#{health_value} health"
@@ -0,0 +1,7 @@
1
+ module StudioGame
2
+ module Auditable
3
+ def audit(number)
4
+ puts "Audit: Rolled a #{number}"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,39 @@
1
+ require_relative "player"
2
+
3
+ module StudioGame
4
+ class BerserkPlayer < Player
5
+
6
+ def initialize(name, health = 100)
7
+ super(name, health)
8
+ @boost_count = 0
9
+ end
10
+
11
+ def beserk?
12
+ @boost_count < 5
13
+ end
14
+
15
+ def boost
16
+ super
17
+ @boost_count += 1
18
+ if beserk?
19
+ puts "#{@name} is beserk!"
20
+ end
21
+ end
22
+
23
+ def drain
24
+ if beserk?
25
+ boost
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ if __FILE__ == $0
34
+ berserker = BerserkPlayer.new("berserker", 50)
35
+ 6.times { berserker.boost }
36
+ 2.times { berserker.drain }
37
+ puts berserker.health
38
+ end
39
+ end
@@ -0,0 +1,27 @@
1
+ require_relative "player"
2
+
3
+ module StudioGame
4
+ class ClumsyPlayer < Player
5
+
6
+ def found_treasure(name, points)
7
+ points = points / 2.0
8
+ super(name, points)
9
+ end
10
+ end
11
+
12
+
13
+
14
+ if __FILE__ == $0
15
+ clumsy = ClumsyPlayer.new("klutz")
16
+
17
+ clumsy.found_treasure("flute", 50)
18
+ clumsy.found_treasure("flute", 50)
19
+ clumsy.found_treasure("flute", 50)
20
+ clumsy.found_treasure("star", 100)
21
+
22
+ clumsy.found_treasures.each do |name, points|
23
+ puts "#{name}: #{points} points"
24
+ end
25
+ puts "#{clumsy.points} total points"
26
+ end
27
+ 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
8
+ attr_reader :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 "No file exists with the name #{from_file}"
22
+ exit 1
23
+ end
24
+
25
+ def add_player(player)
26
+ @players.push(player)
27
+ end
28
+
29
+ def roll_die
30
+ number = rand(1..6)
31
+ audit(number)
32
+ number
33
+ end
34
+
35
+ def play(rounds = 1)
36
+ puts "\nLet's play #{@title}"
37
+
38
+ puts "\nThe treasures you can find today are:"
39
+ puts TreasureTrove.treasure_items
40
+
41
+ puts "\nBefore playing:"
42
+ puts players
43
+
44
+ 1.upto(rounds) do |rounds|
45
+ puts "\nRound #{rounds}:"
46
+
47
+ @players.each do |player|
48
+ number_rolled = roll_die
49
+
50
+ case number_rolled
51
+ when 1..2
52
+ player.drain
53
+ puts "#{player.name} got drained 😩"
54
+ when 3..4
55
+ puts "#{player.name} got skipped"
56
+ else
57
+ player.boost
58
+ puts "#{player.name} got boosted 😁"
59
+ end
60
+
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
+
67
+ puts "\nAfter playing:"
68
+ puts players
69
+ end
70
+
71
+ def sorted_players
72
+ @players.sort_by { |player| player.score}.reverse
73
+ end
74
+
75
+ def print_stats
76
+ puts "\n Winner takes all Stats:"
77
+ puts "-" * 40
78
+ puts sorted_players
79
+ @players.each do |player|
80
+ puts "\n#{player.name}'s treasure point 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
+ name = player.name.ljust(20, ".")
90
+ points = player.score.round.to_s.rjust(5)
91
+ puts "#{name}#{points}"
92
+ end
93
+ end
94
+
95
+ def save_high_scores(to_file = "high_scores.txt")
96
+ File.open(to_file, "w") do |file|
97
+ file.puts "#{@title} High Scores"
98
+ sorted_players.each do |player|
99
+ name = player.name.ljust(20, ".")
100
+ points = player.score.round.to_s.rjust(5)
101
+ file.puts "#{name}#{points}"
102
+ end
103
+ end
104
+ end
105
+
106
+
107
+ end
108
+ end
@@ -0,0 +1,12 @@
1
+ module StudioGame
2
+ module Playable
3
+
4
+ def drain
5
+ self.health -= 10
6
+ end
7
+
8
+ def boost
9
+ self.health += 15
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,54 @@
1
+ require_relative "playable"
2
+
3
+ module StudioGame
4
+ class Player
5
+ include Playable
6
+ attr_accessor :name
7
+ attr_accessor :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 name=(new_name)
17
+ @name = new_name.capitalize
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 "Ignore invalid health #{health}"
25
+ Player.new(name)
26
+ end
27
+
28
+ def found_treasure(name, points)
29
+ @found_treasures[name] += points
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 = "I'm #{@name} I have health: #{@health}, points: #{points} and score: #{score}. I found #{@found_treasures}"
41
+ end
42
+
43
+ # Example code to demonstrate what it does:
44
+ if __FILE__ == $0
45
+ player = Player.new("jase")
46
+ puts player.name
47
+ puts player.health
48
+ player.boost
49
+ puts player.health
50
+ player.drain
51
+ puts player.health
52
+ end
53
+
54
+ 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
+
16
+ def self.random_treasure
17
+ TREASURES.sample
18
+ end
19
+
20
+ def self.treasure_items
21
+ TREASURES.map {|treasure| "A #{treasure.name} is worth #{treasure.points} points" }
22
+ end
23
+ end
24
+ end
metadata ADDED
@@ -0,0 +1,56 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gabby_studio_game
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Gabby Finnegan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-02-07 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email: gabrielle@cronofy.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/Lesson example codes/Lesson 6.rb
25
+ - lib/studio_game/Lesson example codes/Lessons 1-5.rb
26
+ - lib/studio_game/auditable.rb
27
+ - lib/studio_game/beserk_player.rb
28
+ - lib/studio_game/clumsy_player.rb
29
+ - lib/studio_game/game.rb
30
+ - lib/studio_game/playable.rb
31
+ - lib/studio_game/player.rb
32
+ - lib/studio_game/treasure_trove.rb
33
+ homepage: https://gabbystudiogame.com
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: A really great game
56
+ test_files: []