rochambeau 1.9.2 → 1.9.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5534247c467138912df8e075d8636234bbb9431b7461f63eaa3d3da50a490316
4
- data.tar.gz: 7388423500ebab9ee5c8fd76c46267cefe4a3b0ba6a5c48908670418bb730385
3
+ metadata.gz: 582a52ab9c2bad5230d33ef100fd22b575bb5839a22e4250c4d3ccde24f2efce
4
+ data.tar.gz: 25e0a11255c8c291c3bf7543bab38d6cd425649450650280c69d4cd773fad1e6
5
5
  SHA512:
6
- metadata.gz: 5ad8f45b117ca0e4161b6e35eea331099db0ab2c0427711f246112a294f650e9cf6f1474d8a555d04881679f52e9b689607747145d6fba515d2d7c8ad28c5443
7
- data.tar.gz: cf06036ffbf2f1b02d06aa9fd744b651b35a59608cea5cc5517b81b02552a5a0c968be21d0941f697fdc47ce157be383882e22e5af188c267528b7136558e727
6
+ metadata.gz: bf332299ddc71492dcc18a08e56bab957882284ae2ce4dd7c81574ff6973174a9c34260ae66bff8d1dc5e458cde2477dded906c87adb6381d458687d2c8c183f
7
+ data.tar.gz: 1d8cee2d6cbdbc50c323562b30167cda230fa2c1874ec1cfe5124e05fbaf1b302406adae8245ed89b299f91fce11d1d7f1a1e304f25b8846f93be6f6057a9130
data/bin/rochambeau CHANGED
@@ -6,10 +6,5 @@
6
6
  # Rochambeau: Entrypoint.
7
7
 
8
8
  require 'rochambeau'
9
- require 'rochambeau/cli'
10
9
 
11
- begin
12
- Rochambeau::Cli.start(ARGV)
13
- rescue Interrupt
14
- # No op.
15
- end
10
+ Rochambeau.execute
data/lib/rochambeau.rb CHANGED
@@ -3,15 +3,28 @@
3
3
 
4
4
  require 'sorbet-runtime'
5
5
  require 'thor'
6
- require 'rochambeau/option'
7
- require 'rochambeau/game_mode'
8
- require 'rochambeau/cli'
9
6
 
10
- class Rochambeau
11
- extend T::Sig
7
+ require_relative 'rochambeau/version'
8
+ require_relative 'rochambeau/option'
9
+ require_relative 'rochambeau/game_mode'
10
+ require_relative 'rochambeau/player'
11
+ require_relative 'rochambeau/cli'
12
12
 
13
- VERSION = '1.9.2'
13
+ module Rochambeau
14
+ extend T::Sig
14
15
 
15
16
  class InvalidOptionError < StandardError
16
17
  end
18
+
19
+ sig { void }
20
+ def self.execute
21
+ Rochambeau::Cli.start(ARGV)
22
+ rescue ArgumentError => e
23
+ warn(e.to_s)
24
+ rescue Interrupt
25
+ # No op.
26
+ end
17
27
  end
28
+
29
+ # Makes this file executable during development.
30
+ Rochambeau.execute if __FILE__ == $PROGRAM_NAME
@@ -1,7 +1,7 @@
1
- # typed: true
1
+ # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- class Rochambeau
4
+ module Rochambeau
5
5
  class Cli < Thor
6
6
  extend T::Sig
7
7
 
@@ -19,48 +19,56 @@ class Rochambeau
19
19
  aliases: ['a'],
20
20
  type: :boolean,
21
21
  default: false,
22
- desc: 'Advanced mode contains the options "Lizard" and "Spock".'
22
+ desc: 'Enable the options "Lizard" and "Spock".'
23
+ option 'players',
24
+ aliases: ['p'],
25
+ type: :numeric,
26
+ enum: [1, 2],
27
+ default: 1,
28
+ desc: 'Choose between 1 player and 2 player modes.'
23
29
  sig { void }
24
30
  def play
25
31
  system 'clear'
26
32
 
27
33
  game_mode =
28
34
  options.advanced ? GameMode::ADVANCED : GameMode::BASIC
35
+ p1, p2 = Cli.get_players(options.players)
29
36
 
30
- choice = input_choice(game_mode)
31
- random = T.cast(game_mode.options.sample, Option)
37
+ puts game_mode.options.map(&:label).join(' · ')
38
+ p1_choice = p1.choose_option(game_mode.options)
39
+ p2_choice = p2.choose_option(game_mode.options)
32
40
 
33
- puts '------'
34
- puts "Bot: #{random}"
35
- puts "You: #{choice}"
36
- puts '------'
41
+ puts <<~CHOICES
42
+ ------
43
+ #{p1.name}: #{p1_choice}
44
+ #{p2.name}: #{p2_choice}
45
+ ------
46
+ CHOICES
37
47
 
38
- puts Option.explain(choice, random) unless random == choice
48
+ puts Option.explain(p1_choice, p2_choice) unless p1_choice == p2_choice
39
49
 
40
- case choice <=> random
41
- when 1
42
- puts 'You won (:'
43
- when -1
44
- puts 'Bot won :('
45
- puts 'Better luck next time.'
46
- else
47
- puts 'Match draw.'
50
+ case p1_choice <=> p2_choice
51
+ when 1 then puts p1.victory_message
52
+ when -1 then puts p2.victory_message
53
+ else puts 'Match draw.'
48
54
  end
49
55
  end
50
56
 
51
57
  default_task :play
52
58
 
53
- private
54
-
55
- no_commands do
56
- def input_choice(game_mode)
57
- T.cast(game_mode, GameMode)
58
- puts game_mode.options.map(&:label).join(' · ')
59
- chosen_initial = ask('Make a choice', {
60
- limited_to: game_mode.options.map(&:initial)
61
- })
62
- Rochambeau::Option.from_initial chosen_initial
59
+ sig { params(count: Integer).returns([Player, Player]) }
60
+ def self.get_players(count)
61
+ case count
62
+ when 1
63
+ return [Player::UnnamedHuman.new, Player::Robot.new]
64
+ when 2
65
+ return [
66
+ Player::NamedHuman.new('Player 1'),
67
+ Player::NamedHuman.new('Player 2'),
68
+ ]
63
69
  end
70
+
71
+ raise ArgumentError, "Unexpected player count: #{count}"
64
72
  end
65
73
  end
66
74
  end
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- class Rochambeau
4
+ module Rochambeau
5
5
  class GameMode < T::Struct
6
6
  extend T::Sig
7
7
 
@@ -1,7 +1,7 @@
1
1
  # typed: strict
2
2
  # frozen_string_literal: true
3
3
 
4
- class Rochambeau
4
+ module Rochambeau
5
5
  class Option
6
6
  extend T::Sig
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rochambeau
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.9.2
4
+ version: 1.9.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jigar Mehta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-17 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sorbet-runtime