public void DragOver(MathTask task) { var selectedSquare = board[selectedMathTask.Row, selectedMathTask.Col]; var destinationSquare = board[task.Row, task.Col]; var indexOfSelectedSquare = Squares.IndexOf(selectedSquare); var indexOfDestinationSquare = Squares.IndexOf(destinationSquare); var newSelectedSquare = new Square( selectedSquare.Row, selectedSquare.Col, selectedSquare.Color, new Empty(selectedSquare.Row, selectedSquare.Col)); Squares[indexOfSelectedSquare] = newSelectedSquare; selectedMathTask.Row = destinationSquare.Row; selectedMathTask.Col = destinationSquare.Col; var newDestinationSwuare = new Square( destinationSquare.Row, destinationSquare.Col, destinationSquare.Color, selectedMathTask); Squares[indexOfDestinationSquare] = newDestinationSwuare; this.board[selectedSquare.Row, selectedSquare.Col] = newSelectedSquare; this.board[destinationSquare.Row, destinationSquare.Col] = newDestinationSwuare; Task.Run(() => { MessageBox.Show(task.ToString()); }); }
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; }
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; }
public string Encrypt(string clearText) { StringBuilder cipher = new StringBuilder(); int[] squIndices = new int[clearText.Length]; int[] rowIndices = new int[clearText.Length]; int[] colIndices = new int[clearText.Length]; for (int i = 0; i < clearText.Length; i++) { int index = Squares.IndexOf(clearText[i]); squIndices[i] = index / 9; rowIndices[i] = (index - squIndices[i] * 9) / 3; colIndices[i] = (index - squIndices[i] * 9) % 3; } for (int i = 0; i < clearText.Length; i += Group) { int max = Group; if (i + Group > clearText.Length) { max = clearText.Length - i; } for (int j = 0; j < 3 * max; j += 3) { int squ = (j < max ? squIndices[i + j] : (j < 2 * max ? rowIndices[i + j - max] : colIndices[i + j - 2 * max])); int row = (j + 1 < max ? squIndices[i + j + 1] : (j + 1 < 2 * max ? rowIndices[i + j - max + 1] : colIndices[i + j - 2 * max + 1])); int col = (j + 2 < max ? squIndices[i + j + 2] : (j + 2 < 2 * max ? rowIndices[i + j - max + 2] : colIndices[i + j - 2 * max + 2])); cipher.Append(Squares[squ * 9 + row * 3 + col]); } } return(cipher.ToString()); }
public string Decrypt(string cipherText) { StringBuilder clear = new StringBuilder(); int[] squIndices = new int[cipherText.Length]; int[] rowIndices = new int[cipherText.Length]; int[] colIndices = new int[cipherText.Length]; int k = 0; int l = 0; int n = 0; for (int i = 0; i < cipherText.Length; i += Group) { int max = Group; if (i + Group > cipherText.Length) { max = cipherText.Length - i; } int m = 0; for (int j = 0; j < max; j++) { int c = Squares.IndexOf(cipherText[i + j]); int squ = c / 9; int row = (c - squ * 9) / 3; int col = (c - squ * 9) % 3; if (m < max) { squIndices[n++] = squ; } else if (m < 2 * max) { rowIndices[k++] = squ; } else { colIndices[l++] = squ; } m++; if (m < max) { squIndices[n++] = row; } else if (m < 2 * max) { rowIndices[k++] = row; } else { colIndices[l++] = row; } m++; if (m < max) { squIndices[n++] = col; } else if (m < 2 * max) { rowIndices[k++] = col; } else { colIndices[l++] = col; } m++; } } for (k = 0; k < cipherText.Length; k++) { clear.Append(Squares[squIndices[k] * 9 + rowIndices[k] * 3 + colIndices[k]]); } return(clear.ToString()); }