diff options
author | Tom Barrett <tombarrett@siu.edu> | 2017-11-02 05:51:32 -0500 |
---|---|---|
committer | Tom Barrett <tombarrett@siu.edu> | 2017-11-02 05:51:32 -0500 |
commit | 2e5f1363e6efff3daefee9fe6388be2332e6fb62 (patch) | |
tree | f0e255472120577d3b8699df9bda746b847ed730 /src/location.rs | |
parent | 5c495b75f25c324b5e468d0aa80d0699bb5f3fd2 (diff) |
-units now move respect impassable locations, syntax more uniform
Diffstat (limited to 'src/location.rs')
-rw-r--r-- | src/location.rs | 34 |
1 files changed, 21 insertions, 13 deletions
diff --git a/src/location.rs b/src/location.rs index f17965e..4a98ef6 100644 --- a/src/location.rs +++ b/src/location.rs @@ -1,6 +1,6 @@ use std::cmp; -pub struct Location{ +pub struct Location { pub x : i32, pub y : i32 } @@ -24,20 +24,28 @@ impl cmp::PartialEq for Location { } impl Location { - pub fn up(mut self) -> Location { - self.y += 1; - self + pub fn up(self) -> Location { + Location{ x : self.x, y : self.y + 1 } } - pub fn down(mut self) -> Location { - self.y -= 1; - self + pub fn upleft(self) -> Location { + Location{ x : self.x - 1, y : self.y + 1 } } - pub fn right(mut self) -> Location { - self.x += 1; - self + pub fn upright(self) -> Location { + Location{ x : self.x + 1, y : self.y + 1 } } - pub fn left(mut self) -> Location { - self.x -= 1; - self + 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 } } } |