Beispiel #1
0
 private void PrepareInput()
 {
     BoardInput.Current.OnSwipe += (pos, dir) => {
         Cell fromCell;
         Cell toCell;
         fromCell = GetCell(pos);
         if (fromCell == null)
         {
             return;
         }
         if (dir == Vector2.left)
         {
             toCell = fromCell.Left;
         }
         else if (dir == Vector2.right)
         {
             toCell = fromCell.Right;
         }
         else if (dir == Vector2.down)
         {
             toCell = fromCell.Down;
         }
         else if (dir == Vector2.up)
         {
             toCell = fromCell.Up;
         }
         else
         {
             throw new Exception("Bad snap direction vector");
         }
         if (toCell == null)
         {
             return;
         }
         Move move = new Move(fromCell, toCell);
         if (move.CanApply())
         {
             move.Apply();
             Combination combination;
             bool        isValid = false;
             if (Combination.Detect(out combination, move.To))
             {
                 combination.Remove();
                 isValid = true;
             }
             if (Combination.Detect(out combination, move.From))
             {
                 combination.Remove();
                 isValid = true;
             }
             if (!isValid)
             {
                 move.Revert();
             }
         }
     };
 }
Beispiel #2
0
 void Update()
 {
     if (RecentlyChangedCells.Count != RecentlyChangedCellsCount)
     {
         RecentlyChangedCellsCount = RecentlyChangedCells.Count;
     }
     else
     {
         var combination = new Combination();
         foreach (var cell in RecentlyChangedCells)
         {
             if (Combination.Detect(out combination, cell))
             {
                 combination.Remove();
             }
         }
         RecentlyChangedCells      = new HashSet <Cell>();
         RecentlyChangedCellsCount = 0;
     }
 }