Exemplo n.º 1
0
        private bool mergeDown()
        {
            bool performedMerge = false;

            // merge any similar numbers (start the top and move down)
            for (int x = 0; x <= size - 1; x++)
            {
                for (int y = 0; y <= size - 1; y++)
                {
                    _2048Tile tile = getTileAt(x, y);
                    if (y < size - 1)
                    {
                        _2048Tile upTile = (getTileAt(x, y + 1));
                        if (upTile.getValue() == tile.getValue())
                        {
                            Score += upTile.getValue();
                            upTile.setValue(upTile.getValue() * 2);
                            tile.setValue(0);
                            performedMerge = true;
                        }
                    }
                }
            }
            return(performedMerge);
        }
Exemplo n.º 2
0
        private bool mergeRight()
        {
            bool performedMerge = false;

            // merge any similar numbers (start right go left)
            for (int x = size - 1; x >= 0; x--)
            {
                for (int y = size - 1; y >= 0; y--)
                {
                    _2048Tile tile = getTileAt(x, y);
                    if (x < size - 1)
                    {
                        _2048Tile rightTile = (getTileAt(x + 1, y));
                        if (rightTile.getValue() == tile.getValue())
                        {
                            Score += rightTile.getValue();
                            rightTile.setValue(rightTile.getValue() * 2);
                            tile.setValue(0);
                            performedMerge = true;
                        }
                    }
                }
            }
            return(performedMerge);
        }
Exemplo n.º 3
0
        private bool mergeUp()
        {
            bool performedMerge = false;

            // merge any similar numbers (start the bottom and move up)
            for (int x = size - 1; x >= 0; x--)
            {
                for (int y = size - 1; y >= 0; y--)
                {
                    _2048Tile tile = getTileAt(x, y);
                    if (y > 0)
                    {
                        _2048Tile upTile = (getTileAt(x, y - 1));
                        if (upTile.getValue() == tile.getValue())
                        {
                            Score += upTile.getValue();
                            upTile.setValue(upTile.getValue() * 2);
                            tile.setValue(0);
                            performedMerge = true;
                        }
                    }
                }
            }
            return(performedMerge);
        }
Exemplo n.º 4
0
        private bool mergeLeft()
        {
            bool performedMerge = false;

            // merge any similar numbers (start left go right)
            for (int x = 0; x <= size - 1; x++)
            {
                for (int y = 0; y <= size - 1; y++)
                {
                    _2048Tile tile = getTileAt(x, y);
                    if (x > 0)
                    {
                        _2048Tile leftTile = (getTileAt(x - 1, y));
                        if (leftTile.getValue() == tile.getValue())
                        {
                            Score += leftTile.getValue();
                            leftTile.setValue(leftTile.getValue() * 2);
                            tile.setValue(0);
                            performedMerge = true;
                        }
                    }
                }
            }
            return(performedMerge);
        }