connect_n 0.0.4 → 0.0.6

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: 49265f970e5a723c6f5808206701881cd60d2dffc6057e13fcbdbeff85bd4057
4
- data.tar.gz: 93f9b287778e2db06cadb6d59e22cd90b197cdb40c80cee668205ccf348f686b
3
+ metadata.gz: c77d16aeb634e3e518eadd0bc085e3a8eb4e545f5f61fcd04427b36e714fc441
4
+ data.tar.gz: 4e16926c6fd1652d5c4f04749864fe4603356716833fb02a71a36a3740516091
5
5
  SHA512:
6
- metadata.gz: b9bd015765e9cd81654369ec9b39d7fec95474a6d2c63f9f614b5e74d16e78a68c66f3f6453bada7e9beb77aae77a2d19eca963a8bc0944ddff4cb7eecc3751e
7
- data.tar.gz: 757f8514063bba9a249f71d58bd58e151ef97a55b9331417e0fa9d81dff992ad12539249e903d566a03b77ba33fe20bbb104777ea3bc760c38dad78d3e5117b5
6
+ metadata.gz: 05fbc6ebf0c232d844186c7c48720412814341416012bc29cb8eefab993e1bd53f0558d874427d5a1d7dca66393e25c6fefb28f3a9e9f1242992d4b9d05188da
7
+ data.tar.gz: de954704885290af0cab839bc9dd73f82ba320d286cbc77f088ba304e0730d179116500046f3422095b57320fb191c61f0abcb2f1ecfbac0b65c98a217a063a8
@@ -35,7 +35,7 @@ module ConnectN
35
35
  end
36
36
 
37
37
  def draw
38
- table.each{ |row| draw_border || draw_row(row) }
38
+ table.each { |row| draw_border || draw_row(row) }
39
39
  draw_border
40
40
  draw_col_nums
41
41
  end
@@ -74,7 +74,7 @@ module ConnectN
74
74
  end
75
75
 
76
76
  def draw_row(row)
77
- puts '| ' + row.join(' | ') + ' |'
77
+ puts "| #{row.join(' | ')} |"
78
78
  end
79
79
 
80
80
  def draw_col_nums
@@ -94,7 +94,7 @@ module ConnectN
94
94
  def valid_row?(n)
95
95
  n.between?(0, rows_amount - 1)
96
96
  end
97
-
97
+
98
98
  def valid_col?(n)
99
99
  n.between?(0, cols_amount - 1)
100
100
  end
@@ -4,6 +4,7 @@ require_relative '../player/human_player/human_player'
4
4
  require_relative '../player/computer_player/computer_player'
5
5
  require_relative '../game/game'
6
6
  require_relative '../board/board'
7
+ require_relative '../prompt/prompt'
7
8
 
8
9
  module ConnectN
9
10
  class Demo
@@ -13,10 +14,10 @@ module ConnectN
13
14
  @parameters = { human_players: [] }
14
15
  end
15
16
 
16
- def launch
17
- if !Game.games('connect_n_saved_games.yaml').empty? && Game.resume?
17
+ def launch(yaml_fn)
18
+ if !Game.games(yaml_fn).empty? && Game.resume?
18
19
  game_name = Game.select_game_name
19
- @game = Game.load game_name, 'connect_n_saved_games.yaml'
20
+ @game = Game.load game_name, yaml_fn
20
21
  return Game.resume game
21
22
  end
22
23
 
@@ -26,67 +27,28 @@ module ConnectN
26
27
  else
27
28
  single_player_game
28
29
  end
29
- game.play('connect_n_saved_games.yaml')
30
+ game.play(yaml_fn)
30
31
  end
31
32
 
32
33
  private
33
34
 
34
35
  def setup_parameters
35
- parameters[:human_players].push [human_name, disc]
36
+ parameters[:human_players].push [Prompt.ask_for_human_name, Prompt.ask_for_disc]
36
37
 
37
- parameters[:cols_amount] = cols_amount
38
- parameters[:rows_amount] = rows_amount
39
- parameters[:min_to_win] = min_to_win
38
+ parameters[:cols_amount] = Prompt.ask_for_cols_amount
39
+ parameters[:rows_amount] = Prompt.ask_for_rows_amount
40
+ parameters[:min_to_win] = Prompt.ask_for_min_to_win
40
41
 
41
- parameters[:mode] = mode
42
+ parameters[:mode] = Prompt.ask_for_mode
42
43
 
43
44
  if parameters[:mode] == 'multiplayer'
44
- parameters[:human_players].push [human_name => disc]
45
+ parameters[:human_players].push [Prompt.ask_for_human_name, Prompt.ask_for_disc]
45
46
  else
46
- parameters[:difficulty] = difficulty
47
- parameters[:human_starts?] = human_starts?
47
+ parameters[:difficulty] = Prompt.ask_for_difficulty
48
+ parameters[:human_starts?] = Prompt.starts?
48
49
  end
49
50
  end
50
51
 
51
- def cols_amount
52
- PROMPT.ask 'How many columns do you want in the board?', convert: :int, default: 7
53
- end
54
-
55
- def rows_amount
56
- PROMPT.ask 'How many rows do you want in the board?', convert: :int, default: 6
57
- end
58
-
59
- def min_to_win
60
- PROMPT.ask(
61
- 'Minimum number of aligned similar discs necessary to win : ',
62
- convert: :int,
63
- default: 4
64
- )
65
- end
66
-
67
- def difficulty
68
- PROMPT.slider 'Difficulty : ', [*0..10], default: 0
69
- end
70
-
71
- def mode
72
- PROMPT.select('Choose a game mode : ', ['Single Player', 'Multiplayer']).downcase
73
- end
74
-
75
- def human_starts?
76
- PROMPT.yes? 'Do you wanna play first?'
77
- end
78
-
79
- def disc
80
- PROMPT.ask 'Enter a character that will represent your disc : ', default: '🔥' do |q|
81
- q.validate(/^.?$/)
82
- q.messages[:valid?] = 'Please enter a single character.'
83
- end
84
- end
85
-
86
- def human_name
87
- PROMPT.ask 'Enter your name : ', default: ENV['USER']
88
- end
89
-
90
52
  def multiplayer_game
91
53
  human_players = multiplayer_players
92
54
  board = Board.new(
@@ -95,8 +57,8 @@ module ConnectN
95
57
  )
96
58
  Game.new(
97
59
  board: board,
98
- first_player: players.first,
99
- second_player: players.last,
60
+ first_player: human_players.first,
61
+ second_player: human_players.last,
100
62
  min_to_win: parameters[:min_to_win]
101
63
  )
102
64
  end
@@ -14,7 +14,7 @@ module ConnectN
14
14
 
15
15
  attr_reader :board, :players, :min_to_win
16
16
 
17
- PERMITTED_CLASSES = [Symbol, Game, Board, HumanPlayer, ComputerPlayer]
17
+ PERMITTED_CLASSES = [Symbol, Game, Board, HumanPlayer, ComputerPlayer].freeze
18
18
 
19
19
  def initialize(
20
20
  board:,
@@ -118,7 +118,7 @@ module ConnectN
118
118
 
119
119
  def over(winner)
120
120
  phrase = board.filled? ? 'It is a tie!' : "#{winner.name} has won!"
121
- puts TTY::Box.sucess(phrase)
121
+ puts TTY::Box.success(phrase)
122
122
  end
123
123
 
124
124
  private
@@ -1,8 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'tty-prompt'
4
-
5
3
  require_relative '../player'
4
+ require_relative '../../prompt/prompt'
6
5
 
7
6
  module ConnectN
8
7
  class HumanPlayer < Player
@@ -14,7 +13,7 @@ module ConnectN
14
13
  end
15
14
 
16
15
  def pick
17
- input = PROMPT.ask('Please enter a column number : ')
16
+ input = Prompt.ask_for_pick
18
17
  input == save_key ? input : input.to_i - 1
19
18
  end
20
19
  end
@@ -3,5 +3,59 @@
3
3
  require 'tty-prompt'
4
4
 
5
5
  module ConnectN
6
- PROMPT = TTY::Prompt.new
6
+ module Prompt
7
+ PROMPT = TTY::Prompt.new
8
+
9
+ def self.ask_for_cols_amount(
10
+ prompt: 'How many columns do you want in the board?',
11
+ default: 7
12
+ )
13
+ PROMPT.ask prompt, convert: :int, default: default
14
+ end
15
+
16
+ def self.ask_for_rows_amount(
17
+ prompt: 'How many rows do you want in the board?',
18
+ default: 6
19
+ )
20
+ PROMPT.ask prompt, convert: :int, default: default
21
+ end
22
+
23
+ def self.ask_for_min_to_win(
24
+ prompt: 'Minimum number of aligned similar discs necessary to win : ',
25
+ default: 4
26
+ )
27
+ PROMPT.ask(prompt, convert: :int, default: default)
28
+ end
29
+
30
+ def self.ask_for_difficulty(prompt: 'Difficulty : ', levels: [*0..10], default: 5)
31
+ PROMPT.slider prompt, levels, default: default
32
+ end
33
+
34
+ def self.ask_for_mode(prompt: 'Choose a game mode : ')
35
+ PROMPT.select(prompt, ['Single Player', 'Multiplayer']).downcase
36
+ end
37
+
38
+ def self.starts?(prompt: 'Do you wanna play first?')
39
+ PROMPT.yes? prompt
40
+ end
41
+
42
+ def self.ask_for_disc(
43
+ prompt: 'Enter a character that will represent your disc : ',
44
+ default: '🔥',
45
+ error_msg: 'Please enter a single character.'
46
+ )
47
+ PROMPT.ask prompt, default: default do |q|
48
+ q.validate(/^.?$/)
49
+ q.messages[:valid?] = error_msg
50
+ end
51
+ end
52
+
53
+ def self.ask_for_name(prompt: 'Enter your name : ', default: ENV['USER'])
54
+ PROMPT.ask prompt, default: default
55
+ end
56
+
57
+ def self.ask_for_pick(prompt: 'Please enter a column number : ')
58
+ PROMPT.ask prompt
59
+ end
60
+ end
7
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: connect_n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lhoussaine (Jee-El) Ghallou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-11 00:00:00.000000000 Z
11
+ date: 2023-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-box
@@ -67,14 +67,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
- version: 3.0.0
70
+ version: 2.7.0
71
71
  required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  requirements: []
77
- rubygems_version: 3.4.1
77
+ rubygems_version: 3.4.3
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Connect-N!