Пример #1
0
        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;
        }
Пример #2
0
        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;
        }
Пример #3
0
        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();
        }
Пример #4
0
 /// <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;
         }
     }
 }
Пример #5
0
 public CellViewModel(CellModel model)
 {
     Model = model;
 }
Пример #6
0
 public static CellModel FindFarthestPosition(this GridModel grid, CellModel cell, Direction direction, out CellModel next)
 {
     return FindFarthestPosition(grid, cell, Vector.FromDirection(direction), out next);
 }
Пример #7
0
        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);
        }
Пример #8
0
 public static CellModel FindFarthestPosition(this GridModel grid, CellModel cell, Direction direction, out CellModel next)
 {
     return(FindFarthestPosition(grid, cell, Vector.FromDirection(direction), out next));
 }