summaryrefslogtreecommitdiff
path: root/src/card/card.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/card/card.rs')
-rw-r--r--src/card/card.rs62
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();
+ }
+}