From 2e5f1363e6efff3daefee9fe6388be2332e6fb62 Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Thu, 2 Nov 2017 05:51:32 -0500 Subject: -units now move respect impassable locations, syntax more uniform --- src/location.rs | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) (limited to 'src/location.rs') 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 } } } -- cgit v1.2.3