Rename @x and @y to @row and @column in Nikoli.Cell
parent
7a68ed9069
commit
6a8b0425fa
|
@ -96,13 +96,13 @@ class Nikoli.AkariCell extends Nikoli.Cell
|
||||||
return false
|
return false
|
||||||
|
|
||||||
lightLeft: ->
|
lightLeft: ->
|
||||||
@y != 0 && @light(@getRow().slice(0, @y).reverse())
|
@column != 0 && @light(@getRow().slice(0, @column).reverse())
|
||||||
|
|
||||||
lightRight: ->
|
lightRight: ->
|
||||||
@y != (@getRow().length - 1) && @light(@getRow().slice(@y + 1))
|
@column != (@getRow().length - 1) && @light(@getRow().slice(@column + 1))
|
||||||
|
|
||||||
lightUp: ->
|
lightUp: ->
|
||||||
@x != 0 && @light(@getColumn().slice(0, @x).reverse())
|
@row != 0 && @light(@getColumn().slice(0, @row).reverse())
|
||||||
|
|
||||||
lightDown: ->
|
lightDown: ->
|
||||||
@x != (@getColumn().length - 1) && @light(@getColumn().slice(@x + 1))
|
@row != (@getColumn().length - 1) && @light(@getColumn().slice(@row + 1))
|
||||||
|
|
|
@ -113,13 +113,13 @@ class Nikoli.Row
|
||||||
row
|
row
|
||||||
|
|
||||||
class Nikoli.Cell
|
class Nikoli.Cell
|
||||||
constructor: (@x, @y, @game) ->
|
constructor: (@row, @column, @game) ->
|
||||||
@value = @game[@x][@y] if @game? && @valid()
|
@value = @game[@row][@column] if @game? && @valid()
|
||||||
|
|
||||||
create: (value) ->
|
create: (value) ->
|
||||||
cell = document.createElement 'div'
|
cell = document.createElement 'div'
|
||||||
cell.dataset.row = @x
|
cell.dataset.row = @row
|
||||||
cell.dataset.column = @y
|
cell.dataset.column = @column
|
||||||
|
|
||||||
cell.classList.add 'grid-cell'
|
cell.classList.add 'grid-cell'
|
||||||
|
|
||||||
|
@ -127,27 +127,27 @@ class Nikoli.Cell
|
||||||
|
|
||||||
cell
|
cell
|
||||||
|
|
||||||
toString: -> "#{@x};#{@y}"
|
toString: -> "#{@row};#{@column}"
|
||||||
|
|
||||||
getColumn: ->
|
getColumn: ->
|
||||||
column = []
|
column = []
|
||||||
column.push @game[i][@y] for i in [0...@game.length]
|
column.push @game[i][@column] for i in [0...@game.length]
|
||||||
column
|
column
|
||||||
|
|
||||||
getRow: -> @game[@x]
|
getRow: -> @game[@row]
|
||||||
|
|
||||||
adjacentCells: ->
|
adjacentCells: ->
|
||||||
constructor = Object.getPrototypeOf(this).constructor
|
constructor = Object.getPrototypeOf(this).constructor
|
||||||
[
|
[
|
||||||
new constructor(@x + 1, @y, @game),
|
new constructor(@row + 1, @column, @game),
|
||||||
new constructor(@x - 1, @y, @game),
|
new constructor(@row - 1, @column, @game),
|
||||||
new constructor(@x, @y + 1, @game),
|
new constructor(@row, @column + 1, @game),
|
||||||
new constructor(@x, @y - 1, @game)
|
new constructor(@row, @column - 1, @game)
|
||||||
]
|
]
|
||||||
|
|
||||||
valid: (value) ->
|
valid: (value) ->
|
||||||
0 <= @x < @game.length && 0 <= @y < @game[@x].length &&
|
0 <= @row < @game.length && 0 <= @column < @game[@row].length &&
|
||||||
(!value? || value < 0 && @game[@x][@y] < 0 || value >= 0 && @game[@x][@y] >= 0)
|
(!value? || value < 0 && @game[@row][@column] < 0 || value >= 0 && @game[@row][@column] >= 0)
|
||||||
|
|
||||||
duplicatesIn: (array) ->
|
duplicatesIn: (array) ->
|
||||||
array.filter((cell) => cell == @value).length > 1
|
array.filter((cell) => cell == @value).length > 1
|
||||||
|
@ -160,8 +160,8 @@ class Nikoli.Cell
|
||||||
|
|
||||||
squareDuplicates: (from, size) ->
|
squareDuplicates: (from, size) ->
|
||||||
square = []
|
square = []
|
||||||
for i in [from.x...(from.x + size)]
|
for i in [from.row...(from.row + size)]
|
||||||
for j in [from.y...(from.y + size)]
|
for j in [from.column...(from.column + size)]
|
||||||
square.push @game[i][j]
|
square.push @game[i][j]
|
||||||
|
|
||||||
@duplicatesIn square
|
@duplicatesIn square
|
||||||
|
|
|
@ -78,8 +78,8 @@ class Nikoli.NurikabeCell extends Nikoli.Cell
|
||||||
|
|
||||||
isPool: ->
|
isPool: ->
|
||||||
[
|
[
|
||||||
new NurikabeCell(@x, @y + 1, @game),
|
new NurikabeCell(@row, @column + 1, @game),
|
||||||
new NurikabeCell(@x + 1, @y, @game),
|
new NurikabeCell(@row + 1, @column, @game),
|
||||||
new NurikabeCell(@x + 1, @y + 1, @game),
|
new NurikabeCell(@row + 1, @column + 1, @game),
|
||||||
].every (cell) => cell.valid(@value)
|
].every (cell) => cell.valid(@value)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue