diff options
author | Justin Worthe <justin.worthe@gmail.com> | 2017-05-13 19:19:06 +0200 |
---|---|---|
committer | Justin Worthe <justin.worthe@gmail.com> | 2017-05-13 19:19:06 +0200 |
commit | 36b72bfef7b7b8dea94546d11704ec529091bce1 (patch) | |
tree | 4a8cdae81db3ab44aa946046bbfbb87f96c360c5 /src/ships.rs | |
parent | 27682d0ab246af8d0375853fdea44c38de2c2db4 (diff) |
Split into smaller portions
Diffstat (limited to 'src/ships.rs')
-rw-r--r-- | src/ships.rs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ships.rs b/src/ships.rs new file mode 100644 index 0000000..8058d4a --- /dev/null +++ b/src/ships.rs @@ -0,0 +1,38 @@ +use std::fmt; + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +pub enum Ship { + Battleship, + Carrier, + Cruiser, + Destroyer, + Submarine +} + +impl fmt::Display for Ship { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use Ship::*; + + f.write_str( + match self { + &Battleship => "Battleship", + &Carrier => "Carrier", + &Cruiser => "Cruiser", + &Destroyer => "Destroyer", + &Submarine => "Submarine" + } + ) + } +} + +impl Ship { + pub fn length(&self) -> u16 { + match self { + &Battleship => 4, + &Carrier => 5, + &Cruiser => 3, + &Destroyer => 2, + &Submarine => 3 + } + } +} |