/// <summary> /// Returns the shift direction as specified by the specified string, or null if none was specified. /// If the string has no length, then the defaultDir will be returned. /// </summary> private static ShiftDirection?GetShiftDirection(string str, ShiftDirection defaultDir) { if (str.Length == 0) { return(defaultDir); } else if (str.Length > 1) { return(null); } else { switch (str[0]) { case 'l': return(ShiftDirection.Left); case 'r': return(ShiftDirection.Right); case 'u': return(ShiftDirection.Up); case 'd': return(ShiftDirection.Down); default: return(null); } } }
public T Shift(ShiftDirection sd, T inp) { if (Count == 0) { throw new IndexOutOfRangeException("Cannot shift list that contains zero elements"); } int length = this.Count; T val = default(T); switch (sd) { case ShiftDirection.Left: val = this[length - 1]; for (int i = 1; i < length; i++) { this[i] = this[i - 1]; } this[0] = inp; break; case ShiftDirection.Right: val = this[0]; for (int i = 0; i < length - 1; i++) { this[i] = this[i + 1]; } this[length - 1] = inp; break; } return(val); }
private int GetByteToShift(byte[] passwordBytes, int shiftOffset, ShiftDirection shiftDirection) { var byteToShift = 0; var bytesLength = passwordBytes.Length; shiftOffset = Math.Abs(shiftOffset); if (shiftOffset > bytesLength) { if (shiftDirection == ShiftDirection.Left) { byteToShift = bytesLength - 1; } } else { if (shiftDirection == ShiftDirection.Left) { byteToShift = shiftOffset - 1; } else { byteToShift = bytesLength - shiftOffset; } } return(byteToShift); }
/// <summary> /// Modifies this board in-place by shifting those cards that can be shifted or merged in the specified direction. /// </summary> /// <param name="newCardCells">The possible locations for a new card will be added to this array.</param> /// <returns>Whether anything was able to be shifted.</returns> public unsafe bool ShiftInPlace(ShiftDirection dir, IntVector2D *newCardCells) { ulong oldBoard = _board; switch (dir) { case ShiftDirection.Left: ShiftLeft(newCardCells); break; case ShiftDirection.Right: ShiftRight(newCardCells); break; case ShiftDirection.Up: ShiftUp(newCardCells); break; case ShiftDirection.Down: ShiftDown(newCardCells); break; default: throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } return(oldBoard != _board); }
public virtual string HashAndShift(string input, string salt, ShiftDirection shiftDirection, int shiftFactor, int shiftOffset, bool killSalt) { byte[] shiftedBytes; var hashedPassword = HashPassword(input, salt); if (killSalt) { hashedPassword = hashedPassword.TrimStart(salt.ToCharArray()); } var passwordBytes = Encoding.UTF8.GetBytes(hashedPassword); var byteToShift = GetByteToShift(passwordBytes, shiftOffset, shiftDirection); switch (shiftDirection) { case ShiftDirection.Right: shiftedBytes = ShiftRight(passwordBytes, byteToShift, shiftFactor); break; default: shiftedBytes = ShiftLeft(passwordBytes, byteToShift, shiftFactor); break; } return(Encoding.UTF8.GetString(shiftedBytes)); }
private void SetShiftDirection(XPathNavigator nav) { var value = nav.GetAttribute("shiftDirection", string.Empty); if (value.HasValue()) { _shiftDirection = (ShiftDirection)Enum.Parse(typeof(ShiftDirection), value, true); } }
public ShiftButton(ShiftInterface inter, Rectangle rectangle, int index, ShiftDirection direction) : base(rectangle, rotationForShiftDirection(direction), arrowButton, arrowButtonPressed) { _direction = direction; _index = index; _interface = inter; setTargets(ButtonWasToggledDown, buttonWasToggledUp); }
public void test_move_z() { Camera _cam = new Camera(new Vector3(0, 0, 0), new Vector3(1, 1, 1)); ShiftDirection dir = ShiftDirection.ZAxis; _cam.Move(dir, -10); Assert.AreEqual(new Vector3(0, 0, -10), _cam.Pos); Assert.AreEqual(new Vector3(1, 1, -9), _cam.Trg); }
//add a shift to the queue public void queueShift(int index, ShiftDirection dir, DoorDirections tileDoors, bool pritority) { if (pritority) { _shiftQueue.AddFirst(new MapShift(index, dir, tileDoors)); } else { _shiftQueue.AddLast(new MapShift(index, dir, tileDoors)); } }
public object ShiftByte(byte pellet1, int shiftSize, ShiftDirection shiftDirection) { switch (shiftDirection) { case ShiftDirection.Left: return(ShiftLeft(pellet1, shiftSize)); case ShiftDirection.Right: return(ShiftRight(pellet1, shiftSize)); } throw new InvalidOperationException("Invalid shift direction provided."); }
public bool PlacePasswordRecordsInFile(string pin, ShiftDirection direction) { var pwList = GetPasswordRecordsByPin(pin); var newList = pwList.Select(x => { x.Password = _encryptor.GetHashedPassword(x.Password, direction, _encryptor.ShiftNumber); return(x); }).ToList(); var isFinished = SerializeJsonToFile(newList, pin); return(isFinished); }
public void SetShift(ShiftDirection direction) { switch (direction) { case ShiftDirection.Left: AdditionalRect.SetAsLastSibling(); break; case ShiftDirection.Right: AdditionalRect.SetAsFirstSibling(); break; } }
/// <summary> /// Returns the width or height of the board depending on the specified shift direction. /// </summary> public static int GetShiftWidthOrHeight(ShiftDirection dir) { switch (dir) { case ShiftDirection.Left: case ShiftDirection.Right: return(BOARD_WIDTH); case ShiftDirection.Up: case ShiftDirection.Down: return(BOARD_HEIGHT); default: throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } }
/// <summary> /// Modifies this Board in-place by shifting those cards that can be shifted or merged in the specified direction. /// </summary> /// <param name="newCardCells">If not null, the possible locations for a new card will be added to this list.</param> /// <returns>Whether anything was able to be shifted.</returns> public bool Shift(ShiftDirection dir, IList <IntVector2D> newCardCells) { bool ret = false; IntVector2D increment = GetShiftIncrement(dir); int widthOrHeight = GetShiftWidthOrHeight(dir); foreach (IntVector2D startCell in GetShiftStartCells(dir)) { bool shifted = ShiftRowOrColumn(startCell, increment, widthOrHeight); if (shifted && newCardCells != null) { newCardCells.Add(startCell - increment * (widthOrHeight - 1)); } ret = ret || shifted; } return(ret); }
/// <summary> /// Returns the cells along the edge toward which the board will be shifted by the specified direction. /// </summary> public static IEnumerable <IntVector2D> GetShiftStartCells(ShiftDirection dir) { switch (dir) { case ShiftDirection.Left: { for (int y = 0; y < BOARD_HEIGHT; y++) { yield return(new IntVector2D(0, y)); } break; } case ShiftDirection.Right: { for (int y = 0; y < BOARD_HEIGHT; y++) { yield return(new IntVector2D(BOARD_WIDTH - 1, y)); } break; } case ShiftDirection.Up: { for (int x = 0; x < BOARD_WIDTH; x++) { yield return(new IntVector2D(x, 0)); } break; } case ShiftDirection.Down: { for (int x = 0; x < BOARD_WIDTH; x++) { yield return(new IntVector2D(x, BOARD_HEIGHT - 1)); } break; } default: { throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } } }
public EncryptionConfig(XPathNavigator nav, IEncryptionConfig template) { _template = template; if (_template != null) { _workFactor = _template.WorkFactor; _shiftFactor = _template.ShiftFactor; _shiftOffset = _template.ShiftOffset; _shiftDirection = _template.ShiftDirection; } SetWorkFactor(nav); SetShiftFactor(nav); SetShiftOffset(nav); SetShiftDirection(nav); }
/// <summary> /// Shifts the game board in the specified direction, merging cards where possible. /// </summary> /// <returns>Whether any cards were actually shifted.</returns> public bool Shift(ShiftDirection dir) { _tempBoard.CopyFrom(_board); List <IntVector2D> newCardCells = new List <IntVector2D>(); bool shifted = _board.Shift(dir, newCardCells); if (shifted) { IntVector2D newCardCell = newCardCells[_rand.Int32(0, newCardCells.Count - 1)]; _board[newCardCell] = DrawNextCard(); _prevBoard.CopyFrom(_tempBoard); LastShiftTime = DateTime.Now; LastShiftDirection = dir; TotalTurns++; } return(shifted); }
private static float rotationForShiftDirection(ShiftDirection shiftDirection) { switch (shiftDirection) { case ShiftDirection.UP: return(0.0f); case ShiftDirection.DOWN: return((float)Math.PI); case ShiftDirection.LEFT: return(-(float)Math.PI / 2.0f); case ShiftDirection.RIGHT: return((float)Math.PI / 2.0f); default: throw new Exception("Invalid ShiftDirection passed to rotationForShiftDirection"); } }
public void TestShiftAndShiftInternalNegativeCases(ShiftDirection direction) { var bitboard = Square.FromAlgebraic("a1").Bitboard; const string ParameterName = "direction"; Assert.That( () => bitboard.Shift(direction), Throws.TypeOf <ArgumentOutOfRangeException>() .With .Property(nameof(ArgumentOutOfRangeException.ParamName)) .EqualTo(ParameterName)); Assert.That( () => Bitboard.ShiftInternal(bitboard.InternalValue, direction), Throws.TypeOf <ArgumentOutOfRangeException>() .With .Property(nameof(ArgumentOutOfRangeException.ParamName)) .EqualTo(ParameterName)); }
/// <summary> /// Returns the amount in each dimension by which each card should attempt to shift in the specified direction. /// </summary> public static IntVector2D GetShiftIncrement(ShiftDirection dir) { switch (dir) { case ShiftDirection.Left: return(new IntVector2D(-1, 0)); case ShiftDirection.Right: return(new IntVector2D(1, 0)); case ShiftDirection.Up: return(new IntVector2D(0, -1)); case ShiftDirection.Down: return(new IntVector2D(0, 1)); default: throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } }
private static void PopulatePawnCaptures( ICollection <GameMoveData2> resultMoves, Bitboard pawns, Bitboard enemies, ShiftDirection captureDirection, Bitboard rank8, Bitboard enPassantCaptureTarget) { var captureTargets = pawns.Shift(captureDirection); var enPassantCapture = captureTargets & enPassantCaptureTarget; PopulatePawnMoves( resultMoves, enPassantCapture, (int)captureDirection, GameMoveFlags.IsEnPassantCapture); var captures = captureTargets & enemies; if (captures.IsNone) { return; } var nonPromotionCaptures = captures & ~rank8; PopulatePawnMoves( resultMoves, nonPromotionCaptures, (int)captureDirection, GameMoveFlags.IsRegularCapture); var promotionCaptures = captures & rank8; PopulatePawnMoves( resultMoves, promotionCaptures, (int)captureDirection, GameMoveFlags.IsRegularCapture | GameMoveFlags.IsPawnPromotion); }
public void TestShiftAndShiftInternal( string squareNotation, ShiftDirection direction, string expectedResultSquareNotation) { var bitboard = Square.FromAlgebraic(squareNotation).Bitboard; var resultBitboard = bitboard.Shift(direction); var resultValue = Bitboard.ShiftInternal(bitboard.InternalValue, direction); if (expectedResultSquareNotation is null) { Assert.That(resultBitboard.IsNone, Is.True); Assert.That(resultValue, Is.EqualTo(0UL)); return; } var expectedResultBitboard = Square.FromAlgebraic(expectedResultSquareNotation).Bitboard; Assert.That(resultBitboard.Value, Is.EqualTo(expectedResultBitboard.Value)); Assert.That(resultValue, Is.EqualTo(expectedResultBitboard.InternalValue)); }
/// <summary> /// Moves cursor and shifts display without changing DDRAM contents. /// </summary> /// <param name="shiftOperation">Shift display or cursor move</param> /// <param name="shiftDirection">Shift display or cursor move direction</param> private void Shift(ShiftOperation shiftOperation, ShiftDirection shiftDirection) { // DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 // 0 0 0 1 SC RL - - byte shiftCmd = SHIFT_MOVE; // display shift if (shiftOperation == ShiftOperation.DisplayShift) { shiftCmd |= SHIFT_DISPLAY; } // right direction if (shiftDirection == ShiftDirection.Right) { shiftCmd |= SHIFT_RIGHT; } this.SendCommand(shiftCmd); // 37 us (datasheet) }
private uint shiftIntVal(uint value, ShiftDirection dir) { // Shift has no effect on the value 0 if (value == 0) { return(value); } if (dir == ShiftDirection.Right) { value >>= 1; } else // if (dir == ShiftDirection.Left) { value <<= 1; } numericUpDown.Value = value; return(value); }
/// <summary> /// Instead of redrawing a lot of subblocks, we will just move most of the blocks by one block to any direction /// and only mark a single column or row for redrawing. /// </summary> /// <param name="direction">The direction to shift</param> private void ShiftBlocks(ShiftDirection direction) { switch (direction) { case ShiftDirection.Right: ShiftSubBlocksRight(); shadowOffsetX -= blockW / shadowScale; break; case ShiftDirection.Left: ShiftSubBlocksLeft(); shadowOffsetX += blockW / shadowScale; break; case ShiftDirection.Up: ShiftSubBlocksUp(); shadowOffsetZ -= blockH / shadowScale; break; case ShiftDirection.Down: ShiftSubBlocksDown(); shadowOffsetZ += blockH / shadowScale; break; } // make sure the textures link to the correct render targets for (int orderIndex = 0; orderIndex < Nsubblocks; orderIndex++) { try { // I got errors: The render target must not be set on the device when calling GetTexture() // even if I just before this set graphicsDevice.SetRenderTarget(0, null); I have no idea why shadowMapsSingle[orderIndex] = shadowRenderTargetSingle[orderIndex]; } catch { } } SetNextRectangleToDraw(true); }
public void Move(ShiftDirection dir, float shift) { switch (dir) { case ShiftDirection.XAxis: Pos = new Vector3(Pos.X + shift, Pos.Y, Pos.Z); Trg = new Vector3(Trg.X + shift, Trg.Y, Trg.Z); break; case ShiftDirection.YAxis: Pos = new Vector3(Pos.X, Pos.Y + shift, Pos.Z); Trg = new Vector3(Trg.X, Trg.Y + shift, Trg.Z); break; case ShiftDirection.ZAxis: Pos = new Vector3(Pos.X, Pos.Y, Pos.Z + shift); Trg = new Vector3(Trg.X, Trg.Y, Trg.Z + shift); break; default: break; } }
/// <summary> /// Returns the shift direction as specified by the specified string, or null if none was specified. /// If the string has no length, then the defaultDir will be returned. /// </summary> private static ShiftDirection? GetShiftDirection(string str, ShiftDirection defaultDir) { if(str.Length == 0) return defaultDir; else if(str.Length > 1) return null; else { switch(str[0]) { case 'l': return ShiftDirection.Left; case 'r': return ShiftDirection.Right; case 'u': return ShiftDirection.Up; case 'd': return ShiftDirection.Down; default: return null; } } }
// Update is called once per frame void FixedUpdate() { Vector3 cameraPos = new Vector3(); cameraPos.z = transform.position.z; cameraPos.y = player.position.y + yOffset; if (tracker.GetPosition() >= shiftValue) { ; shift = ShiftDirection.RIGHT; } else if (tracker.GetPosition() <= -shiftValue) { shift = ShiftDirection.LEFT; } if (shift == ShiftDirection.RIGHT) { cameraPos.x = Mathf.Lerp(transform.position.x, player.position.x + xOffset, incrementTime); } else if (shift == ShiftDirection.LEFT) { cameraPos.x = Mathf.Lerp(transform.position.x, player.position.x - xOffset, incrementTime); } else { cameraPos.x = Mathf.Lerp(transform.position.x, player.position.x, incrementTime); } if (!followY) { cameraPos.y = yOffset; } transform.position = cameraPos; }
public string GetHashedPassword(string pw, ShiftDirection direction, int shift) { try { shift = shift == 0 ? 1 : shift; int numHashChars = (shift * pw.Length) + shift; var pwHash = RandomGenerator.GetRandomAsciiString(numHashChars); pwHash = pwHash.Replace('\\', ':'); string encryptedPassword = ""; if (pw.Length == 0) { return(null); } switch (direction) { case ShiftDirection.ShiftLeft: return(ShiftHashToTheLeft(pw, shift, pwHash)); case ShiftDirection.ShiftRight: return(ShiftHashToTheRight(pw, shift, pwHash)); default: for (int i = 0; i < pw.Length; i++) { encryptedPassword = string.Concat(encryptedPassword, pw.Substring(i, 1), pwHash.Substring(i, 1)); } break; } return(encryptedPassword); } catch (System.Exception) { return(pw); } }
/// <summary> /// Down radio button checked changed. /// </summary> private void rb_Down_CheckedChanged(object sender, EventArgs e) { // If checked, change direction. if (rb_Down.Checked) _direction = ShiftDirection.Down; }
private void ShiftZIndicies(ShiftDirection direction, int pivot, UIElement exclusion) { for(int i = m_handles.Length; i < this.Children.Count; ++i) { if (this.Children[i] != exclusion) { int z = Canvas.GetZIndex(this.Children[i]); if (direction == ShiftDirection.Backwards && z > pivot) { Canvas.SetZIndex(this.Children[i], --z); if (OnChildElementZIndexChanged != null) OnChildElementZIndexChanged(this.Children[i], z); } else if( direction == ShiftDirection.Forwards && z < pivot) { Canvas.SetZIndex(this.Children[i], ++z); if (OnChildElementZIndexChanged != null) OnChildElementZIndexChanged(this.Children[i], z); } } } }
public void ShufflePosition(ViewObject view) { if (view == null) { throw new ArgumentNullException(nameof(view)); } if ((view.Y <= this.State.Horizon) && ((view.Flags & ViewObjectFlags.IgnoreHorizon) == 0)) { view.Y = this.State.Horizon + 1; } if (this.CheckWalkingArea(view)) { // Walkable if (!this.CheckContact(view)) { // No contact with others if (this.CheckControlLines(view)) { // No control ine return; } } } ShiftDirection shiftDir = ShiftDirection.Left; int shiftCount = 1; int shiftSize = 1; while (!this.CheckWalkingArea(view) || this.CheckContact(view) || !this.CheckControlLines(view)) { switch (shiftDir) { case ShiftDirection.Left: view.X--; shiftCount--; if (shiftCount == 0) { shiftDir = ShiftDirection.Down; shiftCount = shiftSize; } break; case ShiftDirection.Down: view.Y++; shiftCount--; if (shiftCount == 0) { shiftDir = ShiftDirection.Right; shiftSize++; shiftCount = shiftSize; } break; case ShiftDirection.Right: view.X++; shiftCount--; if (shiftCount == 0) { shiftDir = ShiftDirection.Up; shiftCount = shiftSize; } break; case ShiftDirection.Up: view.Y--; shiftCount--; if (shiftCount == 0) { shiftDir = ShiftDirection.Left; shiftSize++; shiftCount = shiftSize; } break; } } }
/// <summary> /// Right radio button checked changed. /// </summary> private void rb_Right_CheckedChanged(object sender, EventArgs e) { // If checked, change direction. if (rb_Right.Checked) _direction = ShiftDirection.Right; }
/// <summary> /// Shifts the tiles up in the desired amount. /// </summary> /// <param name="amount">The amount of tiles to shift.</param> public void Shift(ShiftDirection direction, int amount) { // Create a new set of tiles. GMareTile[,] tiles = GetEmptyLayer(_tiles2.GetLength(0), _tiles2.GetLength(1)); // Iterate through columns. for (int col = 0; col < tiles.GetLength(0); col++) { // Iterate through rows. for (int row = 0; row < tiles.GetLength(1); row++) { int target = 0; // Calculate offset. switch (direction) { // Shift up. case ShiftDirection.Up: // Calculate offset. target = row + amount; // If the target is not out of bounds. if (target < _tiles2.GetLength(1)) tiles[col, row] = _tiles2[col, target].Clone(); break; // Shift right. case ShiftDirection.Right: // Calculate offset. target = col + amount; // If the target is not out of bounds. if (target < _tiles2.GetLength(0)) tiles[target, row] = _tiles2[col, row].Clone(); break; // Shift down. case ShiftDirection.Down: // Calculate offset. target = row + amount; // If the target is not out of bounds. if (target < _tiles2.GetLength(1)) tiles[col, target] = _tiles2[col, row].Clone(); break; // Shift left. case ShiftDirection.Left: // Calculate offset. target = col + amount; // If the target is not out of bounds. if (target < _tiles2.GetLength(0)) tiles[col, row] = _tiles2[target, row].Clone(); break; } } } // Set the tiles to the new shifted tiles. _tiles2 = tiles; }
/// <summary> /// Shifts room tiles in a desired direction, by a desired amount, on the desired layer. /// </summary> /// <param name="layer">The layer to shift.</param> /// <param name="direction">The direction to shift the tiles.</param> /// <param name="amount">The amount of tiles to shift.</param> public void Shift(GMareLayer layer, ShiftDirection direction, int amount) { // If the tile swap happens on all layers. if (layer == null) { // Iterate through each layer. foreach (GMareLayer temp in _layers) { // Shift layer. temp.Shift(direction, amount); } } else { // Get the index of the desired layer. int index = _layers.IndexOf(layer); // Shift layer. _layers[index].Shift(direction, amount); } }
/// <summary> /// Shift display without changing DDRAM contents. /// </summary> /// <param name="direction">Shift display direction</param> public void ShiftDisplay(ShiftDirection direction) { this.Shift(ShiftOperation.DisplayShift, direction); }
/// <summary> /// Move cursor without changing DDRAM contents. /// </summary> /// <param name="direction">Cursor move direction</param> public void MoveCursor(ShiftDirection direction) { this.Shift(ShiftOperation.CursorMove, direction); }
/// <summary> /// Returns the width or height of the board depending on the specified shift direction. /// </summary> public static int GetShiftWidthOrHeight(ShiftDirection dir) { switch(dir) { case ShiftDirection.Left: case ShiftDirection.Right: return BOARD_WIDTH; case ShiftDirection.Up: case ShiftDirection.Down: return BOARD_HEIGHT; default: throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } }
/// <summary> /// Modifies this Board in-place by shifting those cards that can be shifted or merged in the specified direction. /// </summary> /// <param name="newCardCells">If not null, the possible locations for a new card will be added to this list.</param> /// <returns>Whether anything was able to be shifted.</returns> public bool Shift(ShiftDirection dir, IList<IntVector2D> newCardCells) { bool ret = false; IntVector2D increment = GetShiftIncrement(dir); int widthOrHeight = GetShiftWidthOrHeight(dir); foreach(IntVector2D startCell in GetShiftStartCells(dir)) { bool shifted = ShiftRowOrColumn(startCell, increment, widthOrHeight); if(shifted && newCardCells != null) newCardCells.Add(startCell - increment * (widthOrHeight - 1)); ret = ret || shifted; } return ret; }
/// <summary> /// Returns the cells along the edge toward which the board will be shifted by the specified direction. /// </summary> public static IEnumerable<IntVector2D> GetShiftStartCells(ShiftDirection dir) { switch(dir) { case ShiftDirection.Left: { for(int y = 0; y < BOARD_HEIGHT; y++) yield return new IntVector2D(0, y); break; } case ShiftDirection.Right: { for(int y = 0; y < BOARD_HEIGHT; y++) yield return new IntVector2D(BOARD_WIDTH - 1, y); break; } case ShiftDirection.Up: { for(int x = 0; x < BOARD_WIDTH; x++) yield return new IntVector2D(x, 0); break; } case ShiftDirection.Down: { for(int x = 0; x < BOARD_WIDTH; x++) yield return new IntVector2D(x, BOARD_HEIGHT - 1); break; } default: { throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } } }
/// <summary> /// Returns the amount in each dimension by which each card should attempt to shift in the specified direction. /// </summary> public static IntVector2D GetShiftIncrement(ShiftDirection dir) { switch(dir) { case ShiftDirection.Left: return new IntVector2D(-1, 0); case ShiftDirection.Right: return new IntVector2D(1, 0); case ShiftDirection.Up: return new IntVector2D(0, -1); case ShiftDirection.Down: return new IntVector2D(0, 1); default: throw new NotSupportedException("Unknown ShiftDirection '" + dir + "'."); } }
/// <summary> /// Moves cursor and shifts display without changing DDRAM contents. /// </summary> /// <param name="shiftOperation">Shift display or cursor move</param> /// <param name="shiftDirection">Shift display or cursor move direction</param> private void Shift(ShiftOperation shiftOperation, ShiftDirection shiftDirection) { // DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 // 0 0 0 1 SC RL - - byte shiftCmd = SHIFT_MOVE; // display shift if (shiftOperation == ShiftOperation.DisplayShift) shiftCmd |= SHIFT_DISPLAY; // right direction if (shiftDirection == ShiftDirection.Right) shiftCmd |= SHIFT_RIGHT; this.SendCommand(shiftCmd); // 37 us (datasheet) }
/// <summary> /// Shifts the game board in the specified direction, merging cards where possible. /// </summary> /// <returns>Whether any cards were actually shifted.</returns> public bool Shift(ShiftDirection dir) { _tempBoard.CopyFrom(_board); List<IntVector2D> newCardCells = new List<IntVector2D>(); bool shifted = _board.Shift(dir, newCardCells); if(shifted) { IntVector2D newCardCell = newCardCells[_rand.Int32(0, newCardCells.Count - 1)]; _board[newCardCell] = DrawNextCard(); _prevBoard.CopyFrom(_tempBoard); LastShiftTime = DateTime.Now; LastShiftDirection = dir; TotalTurns++; } return shifted; }