From ab4ab2926b647cbbd568d43bd5e482a7719eab88 Mon Sep 17 00:00:00 2001 From: Markus Wagner Date: Sat, 9 Jan 2021 21:25:22 +0100 Subject: [PATCH] Add missing card module to git --- src/cards.rs | 130 ++++++++++++++++++++++++++++++++++ static/images/cards/duchy.jpg | 3 + static/join.html | 21 ++++++ 3 files changed, 154 insertions(+) create mode 100644 src/cards.rs create mode 100644 static/images/cards/duchy.jpg create mode 100644 static/join.html diff --git a/src/cards.rs b/src/cards.rs new file mode 100644 index 0000000..c347df7 --- /dev/null +++ b/src/cards.rs @@ -0,0 +1,130 @@ +use serde::{Serialize, Serializer}; +use std::fmt; + +pub fn copper() -> Card { + Card { + name: "Copper".into(), + cost: 0, + types: vec![CardType::Treasure(1)], + } +} + +pub fn silver() -> Card { + Card { + name: "Silver".into(), + cost: 3, + types: vec![CardType::Treasure(2)], + } +} + +pub fn gold() -> Card { + Card { + name: "Gold".into(), + cost: 6, + types: vec![CardType::Treasure(3)], + } +} + +pub fn estate() -> Card { + Card { + name: "Estate".into(), + cost: 2, + types: vec![CardType::Victory(1)], + } +} + +pub fn duchy() -> Card { + Card { + name: "Duchy".into(), + cost: 5, + types: vec![CardType::Victory(3)], + } +} + +pub fn province() -> Card { + Card { + name: "Province".into(), + cost: 8, + types: vec![CardType::Victory(6)], + } +} + +pub fn curse() -> Card { + Card { + name: "Curse".into(), + cost: 0, + types: vec![CardType::Curse], + } +} + +#[derive(Clone)] +pub enum CardType { + Action(fn()), + Curse, + Treasure(u32), + Victory(u32), +} + +#[derive(Clone)] +pub struct Card { + pub name: String, + pub cost: u32, + pub types: Vec, +} + +impl Card { + pub fn action(&self) -> Option<()> { + for t in &self.types { + match t { + CardType::Action(_) => return Some(()), + _ => (), + } + } + None + } + + pub fn curse(&self) -> Option<()> { + for t in &self.types { + match t { + CardType::Action(_) => return Some(()), + _ => (), + } + } + None + } + + pub fn treasure(&self) -> Option { + for t in &self.types { + match t { + CardType::Treasure(coin) => return Some(*coin), + _ => (), + } + } + None + } + + pub fn victory(&self) -> Option { + for t in &self.types { + match t { + CardType::Victory(points) => return Some(*points), + _ => (), + } + } + None + } +} + +impl Serialize for Card { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + serializer.serialize_str(&self.name) + } +} + +impl fmt::Display for Card { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", self.name) + } +} diff --git a/static/images/cards/duchy.jpg b/static/images/cards/duchy.jpg new file mode 100644 index 0000000..7bd64f3 --- /dev/null +++ b/static/images/cards/duchy.jpg @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ffad0228064cce44a159cf0dea7c0affca157d0ec9fc3d2216ace2c72328205c +size 155282 diff --git a/static/join.html b/static/join.html new file mode 100644 index 0000000..8207ae9 --- /dev/null +++ b/static/join.html @@ -0,0 +1,21 @@ + + + + + + DnD + + + +

+

+
+ Your name:
+ + +
+
+

+ + +