summaryrefslogtreecommitdiff
path: root/src/ship.rs
blob: 49da84dd66b3b48656c568f9662a612bb311987d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use mass::Mass;
extern crate serde_json;

#[derive(Serialize, Deserialize, Debug)]
pub struct Ship {
    name        : String,
    location    : (isize, isize, isize),
    r           : f64,
}

impl Ship {
    pub fn range(&self) -> f64 {
        self.r
    }
}

impl Mass for Ship {
    fn new(name : &str, location : (isize, isize, isize)) -> Ship {
        Ship {
            name        : String::from(name),
            location    : location,
            r           : 100.0,
        }
    }

    fn name(&self) -> &String {
        &self.name
    }

    fn location(&self) -> (isize, isize, isize) {
        self.location
    }

    fn set_location(&mut self, location : (isize, isize, isize)) {
        self.location = location;
    }

    fn serialize(&self) ->String {
        serde_json::to_string(self).unwrap()
    }

    fn deserialize(&mut self, data : &str) {
        //self = serde_json::from_str(data).unwrap();
    }
}