gameboard 3.3.0 → 3.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/gameboard/board.rb +27 -1
- 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: 76a2c121404f3a2b813bfea13c03ee703bf80cdc
|
4
|
+
data.tar.gz: 87fed90228c76fd036d1dbba598be427e77bfe25
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 260a7d4efc6d7f8fbe6106a912743177727ecfc722edde0a51c9e79f5ef3c18eb8f9296b654e2bb1f3b56890c2086108a57c340261efd6da3a5f64bde56098e6
|
7
|
+
data.tar.gz: 1929e29c05557e9cc156d2cc85429586b135fad9ecbff8208b877a1cbc6a969e99d15bfa94b78fd34f86476fa04ba109a3845eff39d476f06d34821deba73bd7
|
data/README.md
CHANGED
@@ -26,6 +26,7 @@
|
|
26
26
|
- Methods, for modifying Board data:
|
27
27
|
- Gameboard::Board.randomize(value)
|
28
28
|
- Gameboard::Board.set_cell([x,y], value)
|
29
|
+
- Gameboard::Board.flip (rage reset the board)
|
29
30
|
|
30
31
|
- Methods for returning different arrangements of cells of the on the board:
|
31
32
|
- Gameboard::Board.horizontal
|
data/lib/gameboard/board.rb
CHANGED
@@ -69,6 +69,7 @@ module Gameboard
|
|
69
69
|
raise ArgumentError unless ((height.is_a?(Integer) && width.is_a?(Integer)) || !!preset)
|
70
70
|
@height = height
|
71
71
|
@width = width
|
72
|
+
@nailed = false
|
72
73
|
@cells = cells || nil
|
73
74
|
preset ? load_game(preset) : new_board
|
74
75
|
end
|
@@ -207,6 +208,10 @@ module Gameboard
|
|
207
208
|
diagonals
|
208
209
|
end
|
209
210
|
|
211
|
+
def empty?
|
212
|
+
board.all? { |cell| cell.value == cells }
|
213
|
+
end
|
214
|
+
|
210
215
|
# Public: Find a cell at given coordinate.
|
211
216
|
#
|
212
217
|
# coord - An X,Y coordinate passed as an Array.
|
@@ -235,6 +240,14 @@ module Gameboard
|
|
235
240
|
board.find {|cell| cell.coord.position == coord}
|
236
241
|
end
|
237
242
|
|
243
|
+
# Public: Resets the board unless nailed down. All pieces will be set
|
244
|
+
# to the default value.
|
245
|
+
#
|
246
|
+
def flip
|
247
|
+
raise "The Board is Nailed to the Table" unless !nailed_down?
|
248
|
+
board.each {|cell| cell.value = cells}
|
249
|
+
end
|
250
|
+
|
238
251
|
# Public: Check if the gameboard is full relative to the default cell.
|
239
252
|
#
|
240
253
|
#
|
@@ -303,10 +316,21 @@ module Gameboard
|
|
303
316
|
rows
|
304
317
|
end
|
305
318
|
|
319
|
+
# Public: Nail the board down so it can't be flipped.
|
320
|
+
def nail_down
|
321
|
+
@nailed = true
|
322
|
+
end
|
323
|
+
|
324
|
+
# Public: Return whether the board is nailed down.
|
325
|
+
def nailed_down?
|
326
|
+
!!nailed
|
327
|
+
end
|
328
|
+
|
306
329
|
# Public: Return all valid neighbors of a given coordinate.
|
307
330
|
#
|
308
331
|
# point - The X,Y coordinate neighbors should be based off of.
|
309
|
-
# coords - An optional boolean to return an array of coordinate
|
332
|
+
# coords - An optional boolean to return an array of coordinate
|
333
|
+
# pairs
|
310
334
|
#
|
311
335
|
#
|
312
336
|
# Examples
|
@@ -401,6 +425,8 @@ module Gameboard
|
|
401
425
|
attr_reader :board
|
402
426
|
# Internal: Returns the default gameboard cell value
|
403
427
|
attr_reader :cells
|
428
|
+
# Internal: Stores whether the board is nailed down
|
429
|
+
attr_reader :nailed
|
404
430
|
|
405
431
|
# Internal: return a diagonal array given a starting point and a
|
406
432
|
# slope.
|
data/lib/gameboard/version.rb
CHANGED