Ejemplo n.º 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;
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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();
        }
Ejemplo n.º 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;
         }
     }
 }
Ejemplo n.º 5
0
 public CellViewModel(CellModel model)
 {
     Model = model;
 }
Ejemplo n.º 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);
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
 }