1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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();
}
}
|