From a853a837b8cb991d8c55496401bef02275139c4e Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Fri, 24 Nov 2017 01:31:41 -0600 Subject: -added giving a grid placement order --- src/list.rs | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'src/list.rs') diff --git a/src/list.rs b/src/list.rs index 6c07c01..2340385 100644 --- a/src/list.rs +++ b/src/list.rs @@ -12,7 +12,7 @@ pub struct List{ impl List { pub fn new(impassable_locations : Vec) -> List { let mut men = Vec::new(); - for i in 0..3 { + for i in 0..10 { men.push(Character::new('@', Colors::BlueUnit as u8, Location(150,150+i))); } List { @@ -42,6 +42,42 @@ impl List { } } + pub fn give_grid(&mut self, first_location : Location, second_location : Location) { + let mut index = 0; + for i in first_location.0..second_location.0 + 1 { + for j in first_location.1..second_location.1 + 1 { + if index < self.men.len() { + self.men[index].give_destination(Location(i,j)); + index += 1; + } + } + } + for i in second_location.0..first_location.0 { + for j in second_location.1..first_location.1 { + if index < self.men.len() { + self.men[index].give_destination(Location(i,j)); + index += 1; + } + } + } + for i in first_location.0..second_location.0 + 1 { + for j in second_location.1..first_location.1 { + if index < self.men.len() { + self.men[index].give_destination(Location(i,j)); + index += 1; + } + } + } + for i in second_location.0..first_location.0 { + for j in first_location.1..second_location.1 + 1 { + if index < self.men.len() { + self.men[index].give_destination(Location(i,j)); + index += 1; + } + } + } + } + fn get_free_locations(&mut self, location : Location) -> Vec<(Location, usize)> { let mut potential_locations = location.neighbours(Vec::new()); -- cgit v1.2.3