summaryrefslogtreecommitdiff
path: root/src/location.rs
diff options
context:
space:
mode:
authorTom Barrett <tombarrett@siu.edu>2017-11-02 08:36:26 -0500
committerTom Barrett <tombarrett@siu.edu>2017-11-02 08:36:26 -0500
commit1c3ec15a9a8b7cef3c544af225d028b3de13d75e (patch)
tree33eb2512060caf7296849ce99dcb0bb920c94aee /src/location.rs
parent2e5f1363e6efff3daefee9fe6388be2332e6fb62 (diff)
- added color constants, fixed some syntax, and changed method of
getting potential locations
Diffstat (limited to 'src/location.rs')
-rw-r--r--src/location.rs35
1 files changed, 12 insertions, 23 deletions
diff --git a/src/location.rs b/src/location.rs
index 4a98ef6..eb8110c 100644
--- a/src/location.rs
+++ b/src/location.rs
@@ -24,28 +24,17 @@ impl cmp::PartialEq for Location {
}
impl Location {
- pub fn up(self) -> Location {
- Location{ x : self.x, y : self.y + 1 }
- }
- pub fn upleft(self) -> Location {
- Location{ x : self.x - 1, y : self.y + 1 }
- }
- pub fn upright(self) -> Location {
- Location{ x : self.x + 1, y : self.y + 1 }
- }
- pub fn down(self) -> Location {
- Location{ x : self.x, y : self.y - 1 }
- }
- pub fn downleft(self) -> Location {
- Location{ x : self.x - 1, y : self.y - 1 }
- }
- pub fn downright(self) -> Location {
- Location{ x : self.x + 1, y : self.y - 1 }
- }
- pub fn right(self) -> Location {
- Location{ x : self.x + 1, y : self.y }
- }
- pub fn left(self) -> Location {
- Location{ x : self.x - 1, y : self.y }
+ pub fn get_around(self) -> Vec<Location> {
+ let mut around = Vec::new();
+ around.push(Location { x : self.x, y : self.y });
+ around.push(Location { x : self.x+1, y : self.y });
+ around.push(Location { x : self.x-1, y : self.y });
+ around.push(Location { x : self.x, y : self.y+1 });
+ around.push(Location { x : self.x, y : self.y-1 });
+ around.push(Location { x : self.x+1, y : self.y+1 });
+ around.push(Location { x : self.x-1, y : self.y-1 });
+ around.push(Location { x : self.x+1, y : self.y-1 });
+ around.push(Location { x : self.x-1, y : self.y+1 });
+ around
}
}