Created
May 28, 2017 14:04
-
-
Save dan200/d77b606c9c495faa4ee76e5fbfca1555 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Dan200.Game.Level | |
{ | |
public enum Direction | |
{ | |
North = 0, | |
East, | |
South, | |
West, | |
Up, | |
Down | |
} | |
public static class DirectionExtensions | |
{ | |
private static int[] DIR_TO_X = { 0, -1, 0, 1, 0, 0 }; | |
private static int[] DIR_TO_Y = { 0, 0, 0, 0, 1, -1 }; | |
private static int[] DIR_TO_Z = { 1, 0, -1, 0, 0, 0 }; | |
private static int[] ROTATE_LEFT = { 3, 0, 1, 2, 4, 5 }; | |
private static int[] ROTATE_RIGHT = { 1, 2, 3, 0, 4, 5 }; | |
private static int[] ROTATE_180 = { 2, 3, 0, 1, 4, 5 }; | |
private static int[] OPPOSITE = { 2, 3, 0, 1, 5, 4 }; | |
public static int GetX(this Direction dir) | |
{ | |
return DIR_TO_X[(int)dir]; | |
} | |
public static int GetY(this Direction dir) | |
{ | |
return DIR_TO_Y[(int)dir]; | |
} | |
public static int GetZ(this Direction dir) | |
{ | |
return DIR_TO_Z[(int)dir]; | |
} | |
public static Direction RotateLeft(this Direction dir) | |
{ | |
return (Direction)ROTATE_LEFT[(int)dir]; | |
} | |
public static Direction RotateRight(this Direction dir) | |
{ | |
return (Direction)ROTATE_RIGHT[(int)dir]; | |
} | |
public static Direction Rotate180(this Direction dir) | |
{ | |
return (Direction)ROTATE_180[(int)dir]; | |
} | |
public static Direction Opposite(this Direction dir) | |
{ | |
return (Direction)OPPOSITE[(int)dir]; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment