public bool CanMove(Coords currentPos, Direction dir)
{
switch (dir)
{
case Direction.Left:
if ((currentPos.x > 0) && (this[currentPos.x - 1, currentPos.y].canEnter))
return true;
break;
case Direction.Right:
if ((currentPos.x < this.width - 1) && (this[currentPos.x + 1, currentPos.y].canEnter))
return true;
break;
case Direction.Down:
if ((currentPos.y < this.height - 1) && (this[currentPos.x, currentPos.y + 1].canEnter))
return true;
break;
case Direction.Up:
if ((currentPos.y > 0) && (this[currentPos.x, currentPos.y - 1].canEnter))
return true;
break;
// Diagonal movement
case Direction.DownLeft:
if ((currentPos.x > 0) && (currentPos.y < this.height - 1)
&& (this[currentPos.x - 1, currentPos.y + 1].canEnter)
&& ((this[currentPos.x, currentPos.y + 1].canEnter)
|| (this[currentPos.x - 1, currentPos.y].canEnter)
)
)
return true;
break;
case Direction.UpRight:
if ((currentPos.x < this.width - 1) && (currentPos.y > 0)
&& ((this[currentPos.x, currentPos.y - 1].canEnter)
|| (this[currentPos.x + 1, currentPos.y].canEnter))
&& (this[currentPos.x + 1, currentPos.y - 1].canEnter)
)
return true;
break;
case Direction.DownRight:
if ((currentPos.y < this.height - 1) && (currentPos.x < this.width - 1)
&& ((this[currentPos.x, currentPos.y + 1].canEnter)
|| (this[currentPos.x + 1, currentPos.y].canEnter))
&& (this[currentPos.x + 1, currentPos.y + 1].canEnter))
return true; break;
case Direction.UpLeft:
if ((currentPos.y > 0)
&& (currentPos.x > 0)
&& (this[currentPos.x - 1, currentPos.y - 1].canEnter)
&& ((this[currentPos.x - 1, currentPos.y].canEnter)
|| (this[currentPos.x, currentPos.y - 1].canEnter)))
return true;
break;
}
return false;
}