diff options
| author | Christian Cunningham <cc@localhost> | 2024-02-07 19:15:07 -0800 |
|---|---|---|
| committer | Christian Cunningham <cc@localhost> | 2024-02-07 19:15:07 -0800 |
| commit | 5f3e5f473c6d7a45297c4d301eb2a2d61078586b (patch) | |
| tree | bd725a5d16dc27a1c7b5b0997732feb57aaa3192 /src/card/card.rs | |
| parent | ccc015a370b87cebec77c3f48cd72ec3039dea6d (diff) | |
Modularize
Diffstat (limited to 'src/card/card.rs')
| -rw-r--r-- | src/card/card.rs | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/card/card.rs b/src/card/card.rs new file mode 100644 index 0000000..72b992a --- /dev/null +++ b/src/card/card.rs @@ -0,0 +1,62 @@ +use crate::card::effect::*; +use crate::card::player::*; +use crate::rand_u8; + +#[allow(dead_code)] +#[derive(Copy,Clone)] +pub struct Card { + pub n: u8, + pub e: u8, + pub s: u8, + pub w: u8, + pub owner: PlayerId, + pub effect: Option<CardEffect>, +} + +#[allow(dead_code)] +impl Default for Card { + fn default() -> Self { + Card { + n: 0, + e: 0, + s: 0, + w: 0, + owner: PlayerId::default(), + effect: None, + } + } +} + +impl core::fmt::Debug for Card { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + if let Err(error) = write!(f, "Card {{\n\towner: {:?}\n\tn: {:?},\n\te: {:?},\n\ts: {:?},\n\tw: {:?}", self.owner, self.n, self.e, self.s, self.w) { + return Err(error); + } + if let Some(effect) = self.effect { + if let Err(error) = write!(f, "\n\teffect: {:?}", effect) { + return Err(error); + } + } + write!(f, "\n}}") + } +} + +impl Card { + pub fn new(owner: PlayerId) -> Self { + Self { + n: 0, + e: 0, + s: 0, + w: 0, + owner: owner, + effect: None, + } + } + + pub fn randomize(&mut self) { + self.n = rand_u8(); + self.e = rand_u8(); + self.s = rand_u8(); + self.w = rand_u8(); + } +} |
