Esempio n. 1
0
        private void moveDown()
        {
            int rowNumber = 0;

            for (int x = size - 1; x >= 0; x--)
            {
                List <int> tileValues = new List <int>();

                for (int i = size - 1; i >= 0; i--)
                {
                    if (getTileAt(x, i).getValue() > 0)
                    {
                        tileValues.Add(getTileAt(x, i).getValue());
                    }
                }
                for (int i = tileValues.Count; i <= size - 1; i++)
                {
                    tileValues.Insert(0, 0);
                }


                for (int i = 0; i <= size - 1; i++)
                {
                    _2048Tile tile = getTileAt(x, i);
                    tile.setValue(int.Parse(tileValues[i].ToString()));
                }
                rowNumber++;
            }
            foreach (List <_2048Tile> row in _tiles)
            {
            }
        }
Esempio n. 2
0
        public void addRandomTile()
        {
            List <_2048Tile> emptyTiles = new List <_2048Tile>();

            for (int x = 0; x <= 3; x++)
            {
                for (int y = 0; y <= 3; y++)
                {
                    _2048Tile tile = getTileAt(x, y);
                    //tile.updateBackgroundColor(Color.FromArgb(238, 228, 218));
                    if (tile.value == 0)
                    {
                        emptyTiles.Add(tile);
                    }
                }
            }

            if (emptyTiles.Count > 0)
            {
                Random rand = new Random();

                _2048Tile randomTile = emptyTiles.ElementAt(rand.Next(emptyTiles.Count));
                randomTile.setValue(2);
                randomTile.updateBackgroundColor(Color.Gainsboro);
            }
        }
Esempio n. 3
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);
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        private void moveRight()
        {
            int rowNumber = 0;

            foreach (List <_2048Tile> row in _tiles)
            {
                List <int> tileValues = new List <int>();
                for (int i = 0; i <= size - 1; i++)
                {
                    if (row[i].getValue() > 0)
                    {
                        tileValues.Add(row[i].getValue());
                    }
                }
                for (int i = tileValues.Count; i <= size - 1; i++)
                {
                    tileValues.Insert(0, 0);
                }

                for (int i = 0; i <= size - 1; i++)
                {
                    _2048Tile tile = getTileAt(i, rowNumber);
                    tile.setValue(int.Parse(tileValues[i].ToString()));
                }
                rowNumber++;
            }
        }
Esempio n. 6
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);
        }
Esempio n. 7
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);
        }