hlockey 2 → 3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,114 @@
1
+ require("hlockey/game")
2
+ require("hlockey/message")
3
+ require("hlockey/player")
4
+
5
+ module Hlockey
6
+ class Weather
7
+ def initialize(game)
8
+ @game = game
9
+ end
10
+
11
+ def to_s
12
+ self.class.to_s.split("::").last
13
+ end
14
+
15
+ def on_game_start() end
16
+
17
+ def on_game_end() end
18
+
19
+ def on_period_end() end
20
+
21
+ def on_action() end
22
+
23
+ def on_goal(scoring_team) end
24
+
25
+ private
26
+
27
+ def worst_player_rand_replace(message, apprx_times_per_game = 1, store_old_in = nil)
28
+ return unless @game.prng.rand(Game::NON_OT_ACTIONS / apprx_times_per_game).zero?
29
+
30
+ team = @game.prng.rand(2).zero? ? @game.home : @game.away
31
+ pos = team.worst_player_pos
32
+
33
+ prev_player = team.roster[pos]
34
+ next_player = Player.new(@game.prng)
35
+
36
+ team.roster[pos] = next_player
37
+ store_old_in[team][pos] ||= prev_player unless store_old_in.nil?
38
+
39
+ @game.stream << Message.send(message, prev_player, next_player)
40
+ end
41
+ end
42
+
43
+ class Chicken < Weather
44
+ def on_game_start
45
+ @chickened_out = { @game.home => {}, @game.away => {} }
46
+ end
47
+
48
+ def on_action
49
+ worst_player_rand_replace(:ChickenedOut, 5, @chickened_out)
50
+ end
51
+
52
+ def on_game_end
53
+ @chickened_out.each { |team, players| team.roster.merge!(players) }
54
+ end
55
+ end
56
+
57
+ class Inclines < Weather
58
+ def on_game_start
59
+ make_incline
60
+ end
61
+
62
+ def on_goal(scoring_team)
63
+ return unless scoring_team == @favored_team
64
+
65
+ @game.score[scoring_team] += @game.prng.rand(0.1..0.5)
66
+ make_incline
67
+ end
68
+
69
+ private
70
+
71
+ def make_incline
72
+ new_favored_team = @game.prng.rand(2).zero? ? :home : :away
73
+ return unless new_favored_team != @favored_team
74
+
75
+ @favored_team = new_favored_team
76
+ @game.stream << Message.InclineFavors(@game.send(@favored_team))
77
+ end
78
+ end
79
+
80
+ class Stars < Weather
81
+ def on_period_end
82
+ return unless @game.score[:home] != @game.score[:away]
83
+
84
+ losing_team = @game.score.min_by { |_k, v| v }.first
85
+ @game.score[losing_team] += 0.5
86
+ @game.stream << Message.StarsPity(@game.send(losing_team))
87
+ end
88
+ end
89
+
90
+ class Sunset < Weather
91
+ def on_game_start
92
+ @score_amt = { home: 0, away: 0 }
93
+ end
94
+
95
+ def on_goal(scoring_team)
96
+ @score_amt[scoring_team] += 1
97
+ @game.score[scoring_team] -= @score_amt[scoring_team] * 0.2
98
+ end
99
+ end
100
+
101
+ class Waves < Weather
102
+ def on_action
103
+ worst_player_rand_replace(:WavesWashedAway)
104
+ end
105
+ end
106
+
107
+ Weather::WEIGHTS = {
108
+ Chicken => 4,
109
+ Inclines => 4,
110
+ Stars => 4,
111
+ Sunset => 4,
112
+ Waves => 3
113
+ }.freeze
114
+ end
data/lib/hlockey.rb CHANGED
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
- require('hlockey/league')
1
+ require("hlockey/league")
metadata CHANGED
@@ -1,39 +1,44 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hlockey
3
3
  version: !ruby/object:Gem::Version
4
- version: '2'
4
+ version: '3'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lavender Perry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-08 00:00:00.000000000 Z
11
+ date: 2023-06-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Hlockey library and console application.
13
+ description: Hlockey library.
14
14
  email: endie2@protonmail.com
15
- executables:
16
- - hlockey
15
+ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - bin/hlockey
19
+ - data/election.yaml
20
+ - data/external/names.txt
21
+ - data/information.yaml
22
+ - data/league.yaml
23
+ - data/links.yaml
21
24
  - lib/hlockey.rb
25
+ - lib/hlockey/constants.rb
22
26
  - lib/hlockey/data.rb
23
- - lib/hlockey/data/election.yaml
24
- - lib/hlockey/data/information.yaml
25
- - lib/hlockey/data/league.yaml
26
- - lib/hlockey/data/links.yaml
27
27
  - lib/hlockey/game.rb
28
+ - lib/hlockey/game/actions.rb
29
+ - lib/hlockey/game/fight.rb
28
30
  - lib/hlockey/league.rb
29
- - lib/hlockey/messages.rb
31
+ - lib/hlockey/message.rb
32
+ - lib/hlockey/player.rb
30
33
  - lib/hlockey/team.rb
34
+ - lib/hlockey/utils.rb
31
35
  - lib/hlockey/version.rb
32
- homepage: https://hlockey.herokuapp.com
36
+ - lib/hlockey/weather.rb
37
+ homepage: https://github.com/Hlockey/lib
33
38
  licenses:
34
39
  - LicenseRef-LICENSE.md
35
40
  metadata:
36
- source_code_uri: https://github.com/Hlockey/hlockey
41
+ source_code_uri: https://github.com/Hlockey/lib
37
42
  post_install_message:
38
43
  rdoc_options: []
39
44
  require_paths:
@@ -49,8 +54,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
54
  - !ruby/object:Gem::Version
50
55
  version: '0'
51
56
  requirements: []
52
- rubygems_version: 3.3.7
57
+ rubygems_version: 3.4.10
53
58
  signing_key:
54
59
  specification_version: 4
55
- summary: Hlockey season 2.
60
+ summary: Hlockey season 3.
56
61
  test_files: []
data/bin/hlockey DELETED
@@ -1,104 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # frozen_string_literal: true
4
-
5
- require('hlockey')
6
-
7
- def menu_input(default, *choices)
8
- puts('Please enter a number...')
9
- # Adding 1 to i when printing choices
10
- # to avoid confusing a non-numerical input with the first choice
11
- choices.each_with_index { |choice, i| puts("#{(i + 1).to_s.rjust(2)} - #{choice}") }
12
- puts("anything else - #{default}")
13
-
14
- # Subtract 1 here to undo adding 1 earlier
15
- STDIN.gets.to_i - 1
16
- end
17
-
18
- # Each element from choices should implement to_s
19
- def menu_input_elem(choices)
20
- i = menu_input('Back', *choices)
21
- choices[i] unless i.negative?
22
- end
23
-
24
- def emoji_team(team)
25
- "#{team.emoji} #{team}"
26
- end
27
-
28
- puts('Please wait...')
29
-
30
- PRINT_TEAM_W_L = Proc.new do |team|
31
- puts(" #{emoji_team(team).ljust(26)} #{team.w_l}")
32
- end
33
-
34
- league = Hlockey::League.new
35
-
36
- puts(Hlockey::Messages.SeasonStarts(league.start_time)) if Time.now < league.start_time
37
-
38
- loop do
39
- league.update_state
40
-
41
- puts(Hlockey::Messages.SeasonDay(league.day))
42
-
43
- case menu_input('Exit', 'Games', 'Standings', 'Team info', 'Election', 'Information')
44
- when 0 # Games
45
- if league.games.empty?
46
- puts(Hlockey::Messages.NoGames)
47
- next
48
- end
49
-
50
- game = menu_input_elem(league.games)
51
- next if game.nil?
52
-
53
- puts("#{game.home.emoji} #{game} #{game.away.emoji}")
54
- loop do
55
- league.update_state
56
-
57
- game.stream.each(&method(:puts))
58
-
59
- break unless game.in_progress
60
-
61
- game.stream.clear
62
- sleep(5)
63
- end
64
- when 1 # Standings
65
- if league.champion_team
66
- puts(Hlockey::Messages.SeasonChampion(league.champion_team))
67
- elsif league.playoff_teams
68
- puts('Playoffs')
69
- league.playoff_teams.each(&PRINT_TEAM_W_L)
70
- end
71
-
72
- league.divisions.each do |name, teams|
73
- puts(name)
74
- teams.each(&PRINT_TEAM_W_L)
75
- end
76
- when 2 # Team info
77
- team = menu_input_elem(league.teams)
78
- next if team.nil?
79
-
80
- puts(emoji_team(team))
81
- team.roster.each do |pos, player|
82
- puts(" #{Hlockey.pos_name(pos)}:\n #{player}")
83
- player.stats.each { |stat, value| puts(" #{stat}: #{value.round(1)}") }
84
- end
85
- puts(" wins: #{team.wins}")
86
- puts(" losses: #{team.losses}")
87
- when 3 # Election
88
- election = Hlockey.load_data('election')
89
- election.each do |category, options|
90
- puts(category)
91
- options.each { |name, description| puts(" #{name}: #{description}") }
92
- end
93
- puts('Go to the website (https://hlockey.herokuapp.com) to vote.')
94
- when 4 # Information
95
- Hlockey.load_data('information').each do |title, info|
96
- puts(title)
97
- info.each_line { |l| puts(" #{l}") }
98
- end
99
- puts('Links')
100
- Hlockey.load_data('links').each { |site, link| puts(" #{site}: #{link}") }
101
- else
102
- exit
103
- end
104
- end