996
|
1 // Dir.cpp
|
|
2
|
|
3 #include "lib.h"
|
|
4 #include "Dir.h"
|
|
5
|
|
6 using namespace std;
|
|
7
|
|
8 namespace Dir
|
|
9 {
|
|
10 t back(t current)
|
|
11 {
|
|
12 static t result[] = {south, southwest, west, northwest,
|
|
13 north, northeast, east, southeast};
|
|
14 check(current, "Dir::back()");
|
|
15 return result[current];
|
|
16 }
|
|
17
|
|
18 t left(t current)
|
|
19 {
|
|
20 static t result[] = {northwest, north, northeast, east,
|
|
21 southeast, south, southwest, west};
|
|
22 check(current, "Dir::left()");
|
|
23 return result[current];
|
|
24 }
|
|
25
|
|
26 t right(t current)
|
|
27 {
|
|
28 static t result[] = {northeast, east, southeast, south,
|
|
29 southwest, west, northwest, north};
|
|
30 check(current, "Dir::right()");
|
|
31 return result[current];
|
|
32 }
|
|
33
|
|
34 string dirToString(t current)
|
|
35 {
|
|
36 static string result[] = {"north", "northeast", "east", "southeast",
|
|
37 "south", "southwest", "west", "northwest"};
|
|
38 if (current >= min && current <= max)
|
|
39 {
|
|
40 return result[current];
|
|
41 }
|
|
42 else
|
|
43 {
|
|
44 return intToString(current);
|
|
45 }
|
|
46 }
|
|
47
|
|
48 Vec dirToVec(t current)
|
|
49 {
|
|
50 static Vec result[] = {Vec(0, -1), Vec(1, -1), Vec(1, 0), Vec(1, 1),
|
|
51 Vec(0, 1), Vec(-1, 1), Vec(-1, 0), Vec(-1, -1)};
|
|
52 check(current, "Dir::dirToVec()");
|
|
53 return result[current];
|
|
54 }
|
|
55
|
|
56 void check(t current, string const & name)
|
|
57 {
|
|
58 if (current < min || current > max)
|
|
59 {
|
|
60 throw InternalException(name + ": Invalid Direction: "
|
|
61 + dirToString(current));
|
|
62 }
|
|
63 }
|
|
64 }
|