int GetWrapedTable(int setSquare, int tempDir, int tableSize, int tableRows)
{
var tempSquare = (Math.Abs(tempDir) == 4) ? -1 * (int)Math.Sign(tempDir) : (Math.Abs(tempDir) % 5) * (int)Math.Sign(tempDir);
if ((setSquare % tableRows) + tempSquare == -1 || (setSquare % tableRows) + tempSquare == tableRows)
{
tempSquare = (tableRows - 1) * ((((setSquare % tableRows) + tempSquare) == tableRows) ? -1 : 1);
}
setSquare += tempSquare;
if (Math.Abs(tempDir) != 1 && Math.Abs(tempDir) != 0)
{
tempSquare = tableRows * (int)Math.Sign(tempDir);
setSquare += tempSquare;
}
if (setSquare < 0)
{
setSquare = tableSize - Math.Abs(setSquare);
}
setSquare %= tableSize;
return(setSquare);
}