diff options
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 + } + } +} |