public static CellModel FindNextCellInDirection(this GridModel grid, CellModel cell, Direction direction) { var vector = Vector.FromDirection(direction); CellModel previous; do { // Progress towards the vector direction until an obstacle is found previous = cell; cell = grid[previous.PosX + vector.x, previous.PosY + vector.y]; } while (cell != null && cell.IsAvailable); return cell; }
public static CellModel FindFarthestPosition(this GridModel grid, CellModel cell, Vector vector, out CellModel next) { CellModel previous; // Progress towards the vector direction until an obstacle is found do { previous = cell; cell = grid[previous.PosX + vector.x, previous.PosY + vector.y]; } while (cell != null && cell.IsAvailable); next = cell; // Used to check if a merge is required return previous; }
public GridModel(int size) { LeanAndMeanModel = true; SizeX = size; SizeY = size; _cells = new List<CellModel>(SizeX * SizeY); for (int i = 0; i < SizeX * SizeY; i++) { var cell = new CellModel(i % SizeY, i / SizeX); var tile = new TileModel(1); tile.Position = cell; _cells.Add(cell); } //Reset(); }
/// <summary> /// Create a deep copy of a grid, history of moves and merges removed. /// </summary> /// <param name="grid"></param> public GridModel(GridModel grid) { SizeX = grid.SizeX; SizeY = grid.SizeY; _cells = new List<CellModel>(SizeX * SizeY); for (int i = 0; i < SizeX * SizeY; i++) { int x = i % SizeY; int y = i / SizeX; var cell = new CellModel(x, y); _cells.Add(cell); var sourceCell = grid[x,y]; if (sourceCell.IsOccupied) { var tileCopy = new TileModel(sourceCell.Tile); tileCopy.Position = cell; } } }
public CellViewModel(CellModel model) { Model = model; }
public static CellModel FindFarthestPosition(this GridModel grid, CellModel cell, Direction direction, out CellModel next) { return FindFarthestPosition(grid, cell, Vector.FromDirection(direction), out next); }
public static CellModel FindFarthestPosition(this GridModel grid, CellModel cell, Vector vector, out CellModel next) { CellModel previous; // Progress towards the vector direction until an obstacle is found do { previous = cell; cell = grid[previous.PosX + vector.x, previous.PosY + vector.y]; }while (cell != null && cell.IsAvailable); next = cell; // Used to check if a merge is required return(previous); }
public static CellModel FindFarthestPosition(this GridModel grid, CellModel cell, Direction direction, out CellModel next) { return(FindFarthestPosition(grid, cell, Vector.FromDirection(direction), out next)); }