Card Struct
Added first version of Card struct. Also added an ability for it to be printed out through rust standard functions. Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
36
src/card.rs
36
src/card.rs
@@ -0,0 +1,36 @@
|
||||
use std::fmt;
|
||||
|
||||
pub struct Card {
|
||||
pub suit: u8,
|
||||
pub value: u8,
|
||||
}
|
||||
|
||||
impl fmt::Display for Card {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let value = match self.value {
|
||||
0 => "A",
|
||||
1 => "2",
|
||||
2 => "3",
|
||||
3 => "4",
|
||||
4 => "5",
|
||||
5 => "6",
|
||||
6 => "7",
|
||||
7 => "8",
|
||||
8 => "9",
|
||||
9 => "10",
|
||||
10 => "J",
|
||||
11 => "Q",
|
||||
12 => "K",
|
||||
_ => "",
|
||||
};
|
||||
let suit = match self.suit {
|
||||
0 => "H",
|
||||
1 => "C",
|
||||
2 => "D",
|
||||
3 => "S",
|
||||
_ => "",
|
||||
};
|
||||
|
||||
write!(f, "{}{}", value, suit)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
use std::error::Error;
|
||||
|
||||
mod card;
|
||||
mod hand;
|
||||
mod deck;
|
||||
mod gamestate;
|
||||
mod hand;
|
||||
|
||||
pub fn run() -> Result<(), Box<dyn Error>> {
|
||||
println!("Hello, world!");
|
||||
|
||||
Reference in New Issue
Block a user