Esempio n. 1
0
        private void PushRow(List <SquareViewModel> row, MoveDirection direction)
        {
            int pos      = 0;
            int desiredX = direction == MoveDirection.Right ? (Width - 1) : 0;

            if (desiredX != row[0].XRequest)
            {
                row[0].XRequest = desiredX;
                ChangeOccured   = true;
            }

            for (int i = 1; i < row.Count; i++)
            {
                if (row[i].Value == row[pos].Value && !row[pos].CreatedInThisTurn)
                {
                    row[pos].Value       *= 2;
                    boardContainer.Score += row[pos].Value;

                    row[pos].CreatedInThisTurn = true;

                    Squares.ElementAt(Squares.IndexOf(row[i])).ToBeRemoved = true;
                    row[i].XRequest = direction == MoveDirection.Right ? (Width - 1) - pos : pos;
                    row.RemoveAt(i);

                    i--;

                    ChangeOccured = true;
                }
                else
                {
                    pos++;
                    desiredX = direction == MoveDirection.Right ? (Width - 1) - pos : pos;
                    if (desiredX != row[i].XRequest)
                    {
                        row[i].XRequest = desiredX;
                        ChangeOccured   = true;
                    }
                }
            }

            foreach (SquareViewModel item in row)
            {
                item.CreatedInThisTurn = false;
            }

            lastMove = direction;
        }
Esempio n. 2
0
        private void PushCol(List <SquareViewModel> col, MoveDirection direction)
        {
            int pos      = 0;
            int desiredY = direction == MoveDirection.Bottom ? (Height - 1) : 0;

            if (desiredY != col[0].Y)
            {
                col[0].YRequest = desiredY;
                ChangeOccured   = true;
            }

            for (int i = 1; i < col.Count; i++)
            {
                if (col[i].Value == col[pos].Value && !col[pos].CreatedInThisTurn)
                {
                    col[pos].Value            *= 2;
                    boardContainer.Score      += col[pos].Value;
                    col[pos].CreatedInThisTurn = true;

                    Squares.ElementAt(Squares.IndexOf(col[i])).ToBeRemoved = true;
                    col[i].YRequest = direction == MoveDirection.Bottom ? (Height - 1) - pos : pos;
                    col.RemoveAt(i);

                    i--;
                    ChangeOccured = true;
                }
                else
                {
                    pos++;
                    desiredY = direction == MoveDirection.Bottom ? (Height - 1) - pos : pos;
                    if (desiredY != col[i].YRequest)
                    {
                        col[i].YRequest = desiredY;
                        ChangeOccured   = true;
                    }
                }
            }

            foreach (SquareViewModel item in col)
            {
                item.CreatedInThisTurn = false;
            }

            lastMove = direction;
        }