예제 #1
0
        public static Coordinates[,] GetTIlesDistinationCoordinates(TilesMovePlan mp)
        {
            int n = mp.MovesMap.GetLength(0);
            int m = mp.MovesMap.GetLength(1);

            int[,] sm         = (int[, ])mp.SourceMatrix.Clone(); // source matrix
            Coordinates[,] mv = new Coordinates[n, m];            // move vectors
            Coordinates[,] dc = new Coordinates[n, m];            // destination coordinates
            int[,] dm         = new int[n, m];                    // destination matrix
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    mv[i, j] = new Coordinates(
                        GetVerticalMoveByDirection(mp.Direction, mp.MovesMap[i, j]),
                        GetHorizontalMoveByDirection(mp.Direction, mp.MovesMap[i, j])
                        );                                                       // get move vector
                    dc[i, j] = Coordinates.Sum(new Coordinates(i, j), mv[i, j]); // get coordinates of destination

                    dm[dc[i, j].Row, dc[i, j].Column] += sm[i, j];               // increase number in destination
                    sm[i, j] -= sm[i, j];                                        // reduce source number
                }
            }

            mp.MoveVectorsMatrix          = mv;
            mp.TileDistinationCoordinates = dc;
            mp.DestinationMatrix          = dm;

            return(dc);
        }
예제 #2
0
파일: GameBoard.cs 프로젝트: xblad/2048-wpf
        public static bool CheckAndSetGameStateGameOver(TilesMovePlan mp)
        {
            if (mp.IsBlindAlleyForAnyDirection()) // check all posible directions
            {
                return(SetGameStateGameOver());
            }

            return(false);
        }
예제 #3
0
        public static TilesMovePlan GetTilesMovePlan(MoveDirection direction, int[,] sourceMatrix)
        {
            // rotate source matrix (Top || Right || Bottom --> Left)
            sourceMatrix = MatrixOperations.RotateMatrix(sourceMatrix, (uint)direction, MatrixOperations.RotationDirection.ACW);
            TilesMovePlan mp = GetTilesMovePlan(sourceMatrix); // perform all calculation for left direction

            // rotate all move plan matrices back (Left --> Top || Right || Bottom)
            mp.SourceMatrix = MatrixOperations.RotateMatrix(sourceMatrix, (uint)direction);
            mp.MovesMap     = MatrixOperations.RotateMatrix(mp.MovesMap, (uint)direction);
            mp.DoublingMap  = MatrixOperations.RotateMatrix(mp.DoublingMap, (uint)direction);
            mp.DeletionMap  = MatrixOperations.RotateMatrix(mp.DeletionMap, (uint)direction);
            mp.Direction    = direction;

            return(mp);
        }
예제 #4
0
 public bool IsBlindAlleyForAnyDirection() // check all possible directions
 {
     TilesMovePlan[] mps = new TilesMovePlan[4];
     for (int i = 0; i < 4; i++)
     {
         mps[i] = MovesHandling.GetTilesMovePlan((MovesHandling.MoveDirection)i, SourceMatrix);
     }
     foreach (TilesMovePlan mp in mps)
     {
         if (!mp.IsBlindAlley())
         {
             return(false);
         }
     }
     return(true);
 }
예제 #5
0
파일: GameBoard.cs 프로젝트: xblad/2048-wpf
 public static void UpdateTileStates(TilesMovePlan mp) // update tile state based on move plan maps
 {
     foreach (Tile t in gameBoardGrid.Children.OfType <Tile>())
     {
         if (Convert.ToBoolean(mp.DeletionMap[Grid.GetRow(t), Grid.GetColumn(t)]))
         {
             t.CurrentState = Tile.State.Delete;
         }
         else if (Convert.ToBoolean(mp.DoublingMap[Grid.GetRow(t), Grid.GetColumn(t)]))
         {
             t.CurrentState = Tile.State.Multiply;
         }
         else
         {
             t.CurrentState = Tile.State.Normal;
         }
     }
 }
예제 #6
0
파일: GameBoard.cs 프로젝트: xblad/2048-wpf
 public static void SetNewCoordinatesToTilesInGrid(TilesMovePlan mp) // translate tile to new location in the context of move plan
 {
     gameBoardGrid.Children.OfType <Tile>()
     .ToList().ForEach(x => { GamePage.TranslateTile(x, mp); });
 }