public FifteenModel() { ClickCommand = new DelegateCommand<Cell>(Clicked); Cells = new Cell[AreaSize * AreaSize - 1]; NullCell = new Cell(0); CreateArea(); SetPositions(); SetRandomArea(); }
private void CreateArea() { for (int i = 0; i < 15; i++) { Cells[i] = new Cell(i + 1); } }
private void Clicked(Cell cell) { Clicked(cell, true); }
private void Clicked(Cell cell, bool userCall) { if (!CellCanMove(cell)) return; var nullCellRow = NullCell.Row; var nullCellColumn = NullCell.Column; NullCell.Row = cell.Row; NullCell.Column = cell.Column; cell.Row = nullCellRow; cell.Column = nullCellColumn; if (userCall && Finished()) GameFinished(); }
private bool CellCanMove(Cell cell) { return Math.Abs(cell.Column - NullCell.Column) + Math.Abs(cell.Row - NullCell.Row) == 1; }