Esempio n. 1
0
        internal bool Move(Game2048 game)
        {
            isMoving = false;

            if (checkMerger(game))
            {
                return(false);
            }

            if (moveX == 0 && moveY == 0)
            {
                return(false);
            }

            Vector2   nextPosition = new Vector2(position.X + moveX, position.Y + moveY);
            Rectangle nextBox      = game.getTileSquare(new Vector2(nextPosition.X, nextPosition.Y));


            if (moveX == 0 && moveY == 0)
            {
                return(false);
            }

            bool inBounds = nextBox.X - game.drawMarginSize >= game.drawPosition.X && nextBox.Y - game.drawMarginSize >= game.drawPosition.Y && nextBox.X + nextBox.Width + game.drawMarginSize <= game.drawBoardSize + game.drawPosition.X && nextBox.Y + nextBox.Height + game.drawMarginSize <= game.drawBoardSize + game.drawPosition.Y;

            if (!inBounds)
            {
                snapToGrid();
                return(false);
            }

            Vector2 next = new Vector2(GridPosition.X + (moveX < 0 ? -1 : moveX > 0 ? 1 : 0), GridPosition.Y + (moveY < 0 ? -1 : moveY > 0 ? 1 : 0));

            Tile collision = game.Tiles.Find(t => t != this && t.value > 0 && (t.value != value || hasmerged || t.hasmerged) && t.position == t.GridPosition && t.GridPosition == next && getDistance(t.GetCenter(game), GetCenter(game)) <= (t.value == value ? getDistance(t.GetGridCenter(game), GetGridCenter(game)) : getDistance(t.GetGridCenter(game), GetGridCenter(game))));

            if (collision is Tile)
            {
                snapToGrid();
                return(false);
            }



            isMoving = true;
            position = nextPosition;

            return(true);
        }
Esempio n. 2
0
 internal Point GetGridCenter(Game2048 game)
 {
     return(game.getTileSquare(GridPosition).Center);
 }