summaryrefslogtreecommitdiff
path: root/src/storage.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/storage.rs')
-rw-r--r--src/storage.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/storage.rs b/src/storage.rs
index 6aa8417..3c6e684 100644
--- a/src/storage.rs
+++ b/src/storage.rs
@@ -3,19 +3,25 @@ use item::Item;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct Storage {
items : Vec<Item>,
+ carrying : usize,
capacity : usize,
}
impl Storage {
pub fn new(items : Vec<Item>) -> Storage {
+ let mut carrying = 0;
+ for item in items.iter() {
+ carrying += item.size;
+ }
Storage {
items : items,
- capacity : 100,
+ capacity : 10,
+ carrying : carrying,
}
}
pub fn has_minerals(&self) -> bool {
- match self.items.iter().position(|item| item.name == "Iron") {
+ match self.items.iter().position(|item| item.is_mineral()) {
Some(_) => true,
None => false,
}
@@ -28,7 +34,14 @@ impl Storage {
}
}
- pub fn give(&mut self, item : Item) {
- self.items.push(item);
+ pub fn give(&mut self, item : Item) -> bool {
+ match self.capacity >= self.carrying + item.size {
+ true => {
+ self.carrying += item.size;
+ self.items.push(item);
+ true
+ },
+ false => false,
+ }
}
}