gameboard 1.0.1 → 1.1.0
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/gameboard/board.rb +29 -2
- data/lib/gameboard/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20d26deb08d61a42eb83cfa3a26f55c0c879926a
|
4
|
+
data.tar.gz: 5aea778474abd40447b8b858429c058e125b59a4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b6d249421f0f528db58637fcee1f9d96e2f790e8ad97bc1cdf7107d8a851845a3787ed3c13dc4fff2632fbd76e54bad726aeb36864b855f12e9b8851768b3f56
|
7
|
+
data.tar.gz: a59ade6b5717365f5fe0ea611e3fdab700863e1d7e939e02e46560622b41205499312708228929936d394258e7d00cbe44e7d4a393a9d222a76e2e7f48993f00
|
data/lib/gameboard/board.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require_relative './cell'
|
2
2
|
module Gameboard
|
3
3
|
class Board
|
4
|
-
attr_reader :
|
4
|
+
attr_reader :height, :width, :board
|
5
5
|
|
6
6
|
def initialize(height:false, width: false, cells: false, preset: false)
|
7
7
|
raise ArgumentError unless ((height.is_a?(Integer) && width.is_a?(Integer)) || !!preset)
|
@@ -15,7 +15,7 @@ module Gameboard
|
|
15
15
|
@board = []
|
16
16
|
width.times do |x|
|
17
17
|
height.times do |y|
|
18
|
-
@board << Cell.new(Coordinate.new(x,y), value:
|
18
|
+
@board << Cell.new(Coordinate.new(x,y), value: cells)
|
19
19
|
end
|
20
20
|
end
|
21
21
|
end
|
@@ -37,5 +37,32 @@ module Gameboard
|
|
37
37
|
cell.coord.position == coord}
|
38
38
|
end
|
39
39
|
|
40
|
+
def horizontal(coords = false)
|
41
|
+
columns = []
|
42
|
+
height.times do |y|
|
43
|
+
columns << board.select { |cell| cell.coord.y == y }.map do |cell|
|
44
|
+
coords ? cell.coord.position : cell.value
|
45
|
+
end
|
46
|
+
end
|
47
|
+
columns
|
48
|
+
end
|
49
|
+
|
50
|
+
def vertical(coords = false)
|
51
|
+
columns = []
|
52
|
+
width.times do |x|
|
53
|
+
columns << board.select { |cell| cell.coord.x == x }.map do |cell|
|
54
|
+
coords ? cell.coord.position : cell.value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
columns
|
58
|
+
end
|
59
|
+
|
60
|
+
def full?
|
61
|
+
@board.none? { |cell| cell.value == cells }
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
attr_reader :cells
|
66
|
+
|
40
67
|
end
|
41
68
|
end
|
data/lib/gameboard/version.rb
CHANGED