Add missing card module to git

This commit is contained in:
Markus Wagner 2021-01-09 21:25:22 +01:00
parent 0f2f085efe
commit ab4ab2926b
3 changed files with 154 additions and 0 deletions

130
src/cards.rs Normal file
View File

@ -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<CardType>,
}
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<u32> {
for t in &self.types {
match t {
CardType::Treasure(coin) => return Some(*coin),
_ => (),
}
}
None
}
pub fn victory(&self) -> Option<u32> {
for t in &self.types {
match t {
CardType::Victory(points) => return Some(*points),
_ => (),
}
}
None
}
}
impl Serialize for Card {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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)
}
}

BIN
static/images/cards/duchy.jpg (Stored with Git LFS) Normal file

Binary file not shown.

21
static/join.html Normal file
View File

@ -0,0 +1,21 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>DnD</title>
</head>
<body>
<p>
<div>
<form id="login_form" method="post">
Your name: <input type="text" name="name"> <br />
<input type="hidden" name="type" value="JoinGame">
<input type="submit" value="Join game">
</form>
</div>
</p>
</body>
</html>