public static bool Copy(ref CGameBlock DstGameBlock, ref CGameBlock SrcGameBlock) { DstGameBlock.iContent = SrcGameBlock.iContent; DstGameBlock.Position = SrcGameBlock.Position; return(true); }
}//end of AreNumbersSequenced //Only modify CurrentNumberSequence for moving pieces about public bool TryMovePiece(int iContent) { int iBlockIdx = -1; int iZeroIdx = -1; //Get current position for (int iBlock = 0; iBlock < GameSettings.iBlocks; iBlock++) { if (GameSettings.aGameBlocks[iBlock].iContent == iContent) { iBlockIdx = iBlock; } if (GameSettings.aGameBlocks[iBlock].iContent == 0) { iZeroIdx = iBlock; } } /*check to see if '0' block can be swapped with*/ //Check to see if the piece that is attempting to move is in the same column as the empty spot if (GameSettings.aGameBlocks[iBlockIdx].Position.EqualsX(GameSettings.aGameBlocks[iZeroIdx].Position) && ( GameSettings.aGameBlocks[iZeroIdx].Position.EqualsY(GameSettings.aGameBlocks[iBlockIdx].Position.Y - GameSettings.GameBlockSize.Y) || GameSettings.aGameBlocks[iZeroIdx].Position.EqualsY(GameSettings.aGameBlocks[iBlockIdx].Position.Y + GameSettings.GameBlockSize.Y))) { CGameBlock TempBlock = new CGameBlock(); TempBlock.CopyFrom(GameSettings.aGameBlocks[iBlockIdx]); GameSettings.aGameBlocks[iBlockIdx].CopyFrom(GameSettings.aGameBlocks[iZeroIdx]); GameSettings.aGameBlocks[iZeroIdx].CopyFrom(TempBlock); AdjustGameBlock(iBlockIdx); AdjustGameBlock(iZeroIdx); TempBlock = null; //can GC TempBlock immediately } //Check to see if the piece that is attempting to move is in the same row as the empty spot if (GameSettings.aGameBlocks[iBlockIdx].Position.EqualsY(GameSettings.aGameBlocks[iZeroIdx].Position) && ( GameSettings.aGameBlocks[iZeroIdx].Position.EqualsX(GameSettings.aGameBlocks[iBlockIdx].Position.X - GameSettings.GameBlockSize.X) || GameSettings.aGameBlocks[iZeroIdx].Position.EqualsX(GameSettings.aGameBlocks[iBlockIdx].Position.X + GameSettings.GameBlockSize.X))) { CGameBlock TempBlock = new CGameBlock(); TempBlock.CopyFrom(GameSettings.aGameBlocks[iBlockIdx]); GameSettings.aGameBlocks[iBlockIdx].CopyFrom(GameSettings.aGameBlocks[iZeroIdx]); GameSettings.aGameBlocks[iZeroIdx].CopyFrom(TempBlock); AdjustGameBlock(iBlockIdx); AdjustGameBlock(iZeroIdx); TempBlock = null; //can GC TempBlock immediately } return(true); }//end of TryMovePiece
public void CopyFrom(CGameBlock GameBlock) { if (GameBlock == null) { //GameBlock doesn't exist, do not copy return; } iContent = GameBlock.iContent; Position = GameBlock.Position; }