summaryrefslogtreecommitdiff
path: root/src/ships.rs
diff options
context:
space:
mode:
authorJustin Worthe <justin.worthe@gmail.com>2017-06-18 15:15:11 +0200
committerJustin Worthe <justin.worthe@gmail.com>2017-06-18 15:15:11 +0200
commit862897ea1d183810c2783eaeeaf40f648ef3dc2d (patch)
treefb168f1122fa2839b52443c54555593045262a2a /src/ships.rs
parent29181fce4797b6e4833ab56d1fa7ff9fa865965b (diff)
Added knowledge of weapons
Next step: knowledge of weapon's effects.
Diffstat (limited to 'src/ships.rs')
-rw-r--r--src/ships.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/ships.rs b/src/ships.rs
index ef29fe9..e37fe33 100644
--- a/src/ships.rs
+++ b/src/ships.rs
@@ -2,6 +2,62 @@ use std::fmt;
use std::str;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
+pub enum Weapon {
+ SingleShot,
+ DoubleShotVertical,
+ DoubleShotHorizontal,
+ CornerShot,
+ CrossShotDiagonal,
+ CrossShotHorizontal,
+ SeekerMissle
+}
+
+impl fmt::Display for Weapon {
+ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ use Weapon::*;
+
+ f.write_str(
+ match self {
+ &SingleShot => "1",
+ &DoubleShotVertical => "2",
+ &DoubleShotHorizontal => "3",
+ &CornerShot => "4",
+ &CrossShotDiagonal => "5",
+ &CrossShotHorizontal => "6",
+ &SeekerMissle => "7"
+ }
+ )
+ }
+}
+
+impl Weapon {
+ pub fn energy_per_round(map_size: u16) -> u16 {
+ if map_size < 10 {
+ 2
+ }
+ else if map_size < 14 {
+ 3
+ }
+ else {
+ 4
+ }
+ }
+ pub fn energy_cost(&self, map_size: u16) -> u16 {
+ use Weapon::*;
+ let epr = Weapon::energy_per_round(map_size);
+ match self {
+ &SingleShot => 1,
+ &DoubleShotVertical | &DoubleShotHorizontal => 8*epr,
+ &CornerShot => 10*epr,
+ &CrossShotDiagonal => 12*epr,
+ &CrossShotHorizontal => 14*epr,
+ &SeekerMissle => 10*epr
+ }
+ }
+}
+
+
+#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub enum Ship {
Battleship,
Carrier,
@@ -55,6 +111,19 @@ impl Ship {
}
}
+ pub fn weapons(&self) -> Vec<Weapon> {
+ use Ship::*;
+ use Weapon::*;
+
+ match self {
+ &Battleship => vec!(SingleShot, CrossShotDiagonal),
+ &Carrier => vec!(SingleShot, CornerShot),
+ &Cruiser => vec!(SingleShot, CrossShotHorizontal),
+ &Destroyer => vec!(SingleShot, DoubleShotVertical, DoubleShotHorizontal),
+ &Submarine => vec!(SingleShot, SeekerMissle)
+ }
+ }
+
pub fn all_types() -> Vec<Ship> {
use Ship::*;