connect_n 0.0.3 → 0.0.5
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 +4 -4
- data/lib/connect_n/board/board.rb +15 -5
- data/lib/connect_n/game/game.rb +22 -8
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b9c066a9534814a11948195d47f819b9ccf4d725af8cdfe719036d3b4e801ae3
|
4
|
+
data.tar.gz: aab0c4794669f157f77baa64d72d84af77480ae02de7f01551c2ae3b3152129b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4d3f47001ca9bdea6dfee6970c20ba698a77527251713fbe6837dcfd5658c31ed7f8775020dba20779a36320fa572e5efa61e9932019334528c1997d7fc73517
|
7
|
+
data.tar.gz: 83cf8c9207f102b995a68663847c120fd3154e5ded67c957b9a21124428566ad8eb440e53fbf9d7fbc431e905bca40a6d303c6e7b9b5337b4db38423daa074cf
|
@@ -46,9 +46,13 @@ module ConnectN
|
|
46
46
|
row_at(row_num)[col_num]
|
47
47
|
end
|
48
48
|
|
49
|
-
def cols
|
49
|
+
def cols
|
50
|
+
table.transpose.map(&:reverse)
|
51
|
+
end
|
50
52
|
|
51
|
-
def rows
|
53
|
+
def rows
|
54
|
+
table
|
55
|
+
end
|
52
56
|
|
53
57
|
def col_at(n)
|
54
58
|
return unless valid_col?(n)
|
@@ -83,10 +87,16 @@ module ConnectN
|
|
83
87
|
puts
|
84
88
|
end
|
85
89
|
|
86
|
-
def valid_cell?(row_num, col_num)
|
90
|
+
def valid_cell?(row_num, col_num)
|
91
|
+
valid_row?(row_num) && valid_col?(col_num)
|
92
|
+
end
|
87
93
|
|
88
|
-
def valid_row?(n)
|
94
|
+
def valid_row?(n)
|
95
|
+
n.between?(0, rows_amount - 1)
|
96
|
+
end
|
89
97
|
|
90
|
-
def valid_col?(n)
|
98
|
+
def valid_col?(n)
|
99
|
+
n.between?(0, cols_amount - 1)
|
100
|
+
end
|
91
101
|
end
|
92
102
|
end
|
data/lib/connect_n/game/game.rb
CHANGED
@@ -49,17 +49,29 @@ module ConnectN
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
def over?(board, row, col, disc)
|
52
|
+
def over?(board, row, col, disc)
|
53
|
+
win?(board, row, col, disc) || board.filled?
|
54
|
+
end
|
53
55
|
|
54
|
-
def play_again?
|
56
|
+
def play_again?
|
57
|
+
PROMPT.yes? 'Would you like to play again?'
|
58
|
+
end
|
55
59
|
|
56
|
-
def self.save?(input)
|
60
|
+
def self.save?(input)
|
61
|
+
input == ':w'
|
62
|
+
end
|
57
63
|
|
58
|
-
def self.resume?
|
64
|
+
def self.resume?
|
65
|
+
PROMPT.yes? 'Do you want to resume a game?'
|
66
|
+
end
|
59
67
|
|
60
|
-
def self.resume(game)
|
68
|
+
def self.resume(game)
|
69
|
+
game.play
|
70
|
+
end
|
61
71
|
|
62
|
-
def self.load(name, yaml_fn)
|
72
|
+
def self.load(name, yaml_fn)
|
73
|
+
games(yaml_fn)[name.to_sym]
|
74
|
+
end
|
63
75
|
|
64
76
|
def self.games(yaml_fn)
|
65
77
|
YAML.safe_load_file(
|
@@ -76,7 +88,9 @@ module ConnectN
|
|
76
88
|
File.write(yaml_fn, dumped_games)
|
77
89
|
end
|
78
90
|
|
79
|
-
def self.name_game
|
91
|
+
def self.name_game
|
92
|
+
PROMPT.ask 'Name your game : '
|
93
|
+
end
|
80
94
|
|
81
95
|
def self.select_game_name(yaml_fn)
|
82
96
|
games = games(yaml_fn).keys.map.with_index(1) { "#{_2} -> #{_1}" }
|
@@ -104,7 +118,7 @@ module ConnectN
|
|
104
118
|
|
105
119
|
def over(winner)
|
106
120
|
phrase = board.filled? ? 'It is a tie!' : "#{winner.name} has won!"
|
107
|
-
puts TTY::Box.
|
121
|
+
puts TTY::Box.success(phrase)
|
108
122
|
end
|
109
123
|
|
110
124
|
private
|
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
|
+
version: 0.0.5
|
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
|
+
date: 2023-01-12 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:
|
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.
|
77
|
+
rubygems_version: 3.4.3
|
78
78
|
signing_key:
|
79
79
|
specification_version: 4
|
80
80
|
summary: Connect-N!
|